From patchwork Fri Jan 2 19:51:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 42704 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2A4F926CD1 for ; Fri, 2 Jan 2015 19:51:20 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id r20sf36870wiv.1 for ; Fri, 02 Jan 2015 11:51:19 -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=oAtA0GARfH9lcGlcd7pG6wuG2l3wcfS1z5aFmq2IxPU=; b=kzJy7DnRrskJSSS4O6cDuAQpaHPI1HRdvkGPtfU1nuN6Co1KDJvJjT3N2XsJBfQuUr syRsPc7W23IkCrhaaUlNe0xqf6COGqzD5Ej15JneLJe2grfadMSY7cFkBQCg8JQ2Stfb hgLLZdaPdM+X1Cg4IEgBQjkx9YXFDAmjE/wq7/yWZ9iaP0HDe+TljglLnw9GHAdaEB1p lbuhOBzHjgFV3m7xJKsxIhjxEXC9/32v5hjXvBZ6l4faSWRcJ6be+hfjHL3NhV9IlvWg 9qMyyHwG5IHI8OESiX5GMsx5AW/0jkY8BASJxesr6WXpy+moZ0oX8D/zGKVGbDKrPM8Z me6Q== X-Gm-Message-State: ALoCoQm4Fa+SqJ3r44Z9CJz6gwwoeW/01lW6GI2nl9FJM7iUVAI4qdcXFGYy0zdOVjJ2/x0nyzOG X-Received: by 10.180.189.116 with SMTP id gh20mr37622wic.2.1420228279370; Fri, 02 Jan 2015 11:51:19 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.131 with SMTP id t3ls1712596lag.44.gmail; Fri, 02 Jan 2015 11:51:19 -0800 (PST) X-Received: by 10.152.238.1 with SMTP id vg1mr78979231lac.83.1420228279213; Fri, 02 Jan 2015 11:51:19 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id uj9si52553470lbb.97.2015.01.02.11.51.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 Jan 2015 11:51:19 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id gf13so16100330lab.35 for ; Fri, 02 Jan 2015 11:51:18 -0800 (PST) X-Received: by 10.112.159.136 with SMTP id xc8mr7431668lbb.98.1420228278891; Fri, 02 Jan 2015 11:51:18 -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 c8csp277533lbb; Fri, 2 Jan 2015 11:51:18 -0800 (PST) X-Received: by 10.68.136.34 with SMTP id px2mr61015348pbb.90.1420228276608; Fri, 02 Jan 2015 11:51:16 -0800 (PST) Received: from mail-pd0-f182.google.com (mail-pd0-f182.google.com. [209.85.192.182]) by mx.google.com with ESMTPS id yh8si57599662pab.33.2015.01.02.11.51.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 Jan 2015 11:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.182 as permitted sender) client-ip=209.85.192.182; Received: by mail-pd0-f182.google.com with SMTP id p10so24188511pdj.27 for ; Fri, 02 Jan 2015 11:51:15 -0800 (PST) X-Received: by 10.70.91.67 with SMTP id cc3mr124857350pdb.76.1420228275205; Fri, 02 Jan 2015 11:51:15 -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 jt8sm33913718pbc.6.2015.01.02.11.51.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Jan 2015 11:51:14 -0800 (PST) From: John Stultz To: lkml Cc: Sasha Levin , Thomas Gleixner , Ingo Molnar , stable , John Stultz Subject: [PATCH 1/2] time: settimeofday: Validate the values of tv from user Date: Fri, 2 Jan 2015 11:51:07 -0800 Message-Id: <1420228268-2161-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420228268-2161-1-git-send-email-john.stultz@linaro.org> References: <1420228268-2161-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.215.48 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 Signed-off-by: Sasha Levin 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..7a10ec1 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 miliseconds 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; }