From patchwork Wed Jan 7 18:12:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 42849 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C01EC2055F for ; Wed, 7 Jan 2015 18:12:48 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf1043422wid.7 for ; Wed, 07 Jan 2015 10:12:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=x4c0x5umzu+QmR726MGgzcAK6l05b6JOavBt5vRRhE4=; b=IKMcJq89+z2oaaH9oeKjDGS/BHhEVyEwVp3rO+7OyQohqyZcu2US734IgY48J+/xbb Am0W8lR7+opXWeWoOxCEipE5x13XQovY4YGvnUd0x3yWZbcqT0BefUiYZwRPEyspIOEl WittD6yZr0Kmb09tJcUPCNcq39ky7NW9Ylv7aryxT+/tmhTYOyXo61vMKJ8rRrtzlOFR jJCmc7NzIQZ5bhViCAmi6OmtTuwNF3BBodPUlen3g10dIriPPrlUuNPPZRWLwCeYBvvq z+I8+2ywsG1KGso+yH2OkwS2R4PELBx3ZaFh50MKvT1qXab6tG4umqezZ8GD/j6nyEj/ mv2w== X-Gm-Message-State: ALoCoQlCqEdQPezLNSP24xE1UA36vUokHo1UEUJO+ihPRI6pqb7xWODImS1WcChJCnWxUQktnopW X-Received: by 10.180.76.40 with SMTP id h8mr3154806wiw.3.1420654368015; Wed, 07 Jan 2015 10:12:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.99 with SMTP id bf3ls213462lab.13.gmail; Wed, 07 Jan 2015 10:12:47 -0800 (PST) X-Received: by 10.152.36.1 with SMTP id m1mr6850223laj.95.1420654367844; Wed, 07 Jan 2015 10:12:47 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id m3si4244977lbc.51.2015.01.07.10.12.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 Jan 2015 10:12:46 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id u10so1531837lbd.13 for ; Wed, 07 Jan 2015 10:12:46 -0800 (PST) X-Received: by 10.112.125.41 with SMTP id mn9mr6918130lbb.80.1420654366557; Wed, 07 Jan 2015 10:12:46 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.9.200 with SMTP id c8csp20160lbb; Wed, 7 Jan 2015 10:12:45 -0800 (PST) X-Received: by 10.66.248.163 with SMTP id yn3mr7509051pac.5.1420654360125; Wed, 07 Jan 2015 10:12:40 -0800 (PST) Received: from mail-pd0-f173.google.com (mail-pd0-f173.google.com. [209.85.192.173]) by mx.google.com with ESMTPS id td4si4194655pab.227.2015.01.07.10.12.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 Jan 2015 10:12:40 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.173 as permitted sender) client-ip=209.85.192.173; Received: by mail-pd0-f173.google.com with SMTP id ft15so6085985pdb.4 for ; Wed, 07 Jan 2015 10:12:39 -0800 (PST) X-Received: by 10.70.3.2 with SMTP id 2mr7700054pdy.86.1420654359059; Wed, 07 Jan 2015 10:12:39 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id pd9sm2429545pdb.35.2015.01.07.10.12.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jan 2015 10:12:38 -0800 (PST) From: John Stultz To: lkml Cc: Sasha Levin , Thomas Gleixner , Ingo Molnar , stable , Andy Lutomirski , John Stultz Subject: [PATCH 1/2] time: settimeofday: Validate the values of tv from user Date: Wed, 7 Jan 2015 10:12:19 -0800 Message-Id: <1420654340-3009-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420654340-3009-1-git-send-email-john.stultz@linaro.org> References: <1420654340-3009-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Sasha Levin An unvalidated user input is multiplied by a constant, which can result in an undefined behaviour for large values. While this is validated later, we should avoid triggering undefined behaviour. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: stable Cc: Andy Lutomirski Signed-off-by: Sasha Levin [jstultz: include trivial milisecond->microsecond correction noticed by Andy] Signed-off-by: John Stultz --- include/linux/time.h | 13 +++++++++++++ kernel/time/time.c | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/time.h b/include/linux/time.h index 8c42cf8..5989b0e 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -99,6 +99,19 @@ static inline bool timespec_valid_strict(const struct timespec *ts) return true; } +static inline bool timeval_valid(const struct timeval *tv) +{ + /* Dates before 1970 are bogus */ + if (tv->tv_sec < 0) + return false; + + /* Can't have more microseconds then a second */ + if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) + return false; + + return true; +} + extern struct timespec timespec_trunc(struct timespec t, unsigned gran); #define CURRENT_TIME (current_kernel_time()) diff --git a/kernel/time/time.c b/kernel/time/time.c index a9ae20f..22d5d3b 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -196,6 +196,10 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv, if (tv) { if (copy_from_user(&user_tv, tv, sizeof(*tv))) return -EFAULT; + + if (!timeval_valid(&user_tv)) + return -EINVAL; + new_ts.tv_sec = user_tv.tv_sec; new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC; }