From patchwork Mon Mar 25 20:08:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 15626 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5BAC023E66 for ; Mon, 25 Mar 2013 20:08:28 +0000 (UTC) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by fiordland.canonical.com (Postfix) with ESMTP id 00BD7A1954C for ; Mon, 25 Mar 2013 20:08:27 +0000 (UTC) Received: by mail-vc0-f173.google.com with SMTP id gd11so5015908vcb.18 for ; Mon, 25 Mar 2013 13:08:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=wfsi0hWT5U6DAfjhWm+Jn5Y3qZjI2Esnag06070EDY8=; b=XQUFRkXaL3M1g4bMUZiGvi0yXAaJImEhCSJ3XryYSUuazAWTa/NnwWroBq0mi/itGv cIAWP2SDjYr9ao0fJPwkf9H6Vazr7jAIR7tUKUHGAklyA0V/TsrU5uN56j0JovZRNoPq e47S1cApPwLJ3vk9CStNlX0CXJH+2grVxqUxX9Z0iI7sZKjFX825yggr8tT264vFMvjb NcnVAAZR1u24aLJukNLAMGKhPnorQAkgTfKHAr/6isjnWdpvlzue3quySep+nrilfxpR jwwpI7SzUmUn0ahoM/4s1iGy7bNkJqOwM6SyCxYq/wo9laUy0PL7SDdiPFDqND3nzbqX YMcQ== X-Received: by 10.52.233.225 with SMTP id tz1mr15131441vdc.54.1364242107479; Mon, 25 Mar 2013 13:08:27 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp41750ved; Mon, 25 Mar 2013 13:08:26 -0700 (PDT) X-Received: by 10.68.190.99 with SMTP id gp3mr19580762pbc.117.1364242106508; Mon, 25 Mar 2013 13:08:26 -0700 (PDT) Received: from mail-pd0-f177.google.com (mail-pd0-f177.google.com [209.85.192.177]) by mx.google.com with ESMTPS id tm7si14599149pbc.90.2013.03.25.13.08.26 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Mar 2013 13:08:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.177 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.177; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.192.177 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: by mail-pd0-f177.google.com with SMTP id y14so2657488pdi.22 for ; Mon, 25 Mar 2013 13:08:26 -0700 (PDT) X-Received: by 10.66.67.50 with SMTP id k18mr19507637pat.81.1364242106082; Mon, 25 Mar 2013 13:08:26 -0700 (PDT) Received: from localhost.localdomain (c-24-21-54-107.hsd1.or.comcast.net. [24.21.54.107]) by mx.google.com with ESMTPS id gn2sm14529074pbb.22.2013.03.25.13.08.24 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Mar 2013 13:08:25 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Thomas Gleixner , Richard Cochran , Prarit Bhargava Subject: [PATCH 1/8] ntp: Split out timex validation from do_adjtimex Date: Mon, 25 Mar 2013 13:08:11 -0700 Message-Id: <1364242098-5977-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1364242098-5977-1-git-send-email-john.stultz@linaro.org> References: <1364242098-5977-1-git-send-email-john.stultz@linaro.org> X-Gm-Message-State: ALoCoQmimDzr2c0PaMzeUgyFUmGfkAHq1MktvNcIGcdWP3AHci1AWnRDkTgwfizluY1of7KKaCnP Split out the timex validation done in do_adjtimex into a separate function. This will help simplify logic in following patches. Cc: Thomas Gleixner Cc: Richard Cochran Cc: Prarit Bhargava Signed-off-by: John Stultz --- kernel/time/ntp.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 59e2749..457d2ba 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -622,17 +622,13 @@ static inline void process_adjtimex_modes(struct timex *txc, ntp_update_frequency(); } -/* - * adjtimex mainly allows reading (and writing, if superuser) of - * kernel time-keeping variables. used by xntpd. + + +/** + * ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex */ -int do_adjtimex(struct timex *txc) +int ntp_validate_timex(struct timex *txc) { - struct timespec ts; - u32 time_tai, orig_tai; - int result; - - /* Validate the data before disabling interrupts */ if (txc->modes & ADJ_ADJTIME) { /* singleshot must not be used with any other mode bits */ if (!(txc->modes & ADJ_OFFSET_SINGLESHOT)) @@ -644,7 +640,6 @@ int do_adjtimex(struct timex *txc) /* In order to modify anything, you gotta be super-user! */ if (txc->modes && !capable(CAP_SYS_TIME)) return -EPERM; - /* * if the quartz is off by more than 10% then * something is VERY wrong! @@ -655,12 +650,32 @@ int do_adjtimex(struct timex *txc) return -EINVAL; } + if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME))) + return -EPERM; + + return 0; +} + + +/* + * adjtimex mainly allows reading (and writing, if superuser) of + * kernel time-keeping variables. used by xntpd. + */ +int do_adjtimex(struct timex *txc) +{ + struct timespec ts; + u32 time_tai, orig_tai; + int result; + + /* Validate the data before disabling interrupts */ + result = ntp_validate_timex(txc); + if (result) + return result; + if (txc->modes & ADJ_SETOFFSET) { struct timespec delta; delta.tv_sec = txc->time.tv_sec; delta.tv_nsec = txc->time.tv_usec; - if (!capable(CAP_SYS_TIME)) - return -EPERM; if (!(txc->modes & ADJ_NANO)) delta.tv_nsec *= 1000; result = timekeeping_inject_offset(&delta);