From patchwork Tue Feb 10 07:30:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 44516 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AF20621512 for ; Tue, 10 Feb 2015 07:30:49 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf5389789wib.2 for ; Mon, 09 Feb 2015 23:30:49 -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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=MzNfIkg3SM9rmFUBn2hqe30GNW/CImKxEK9HjS079Jg=; b=eJRdzzhR4+9LRSjA0NoC6NJdA3ivGmaximgzJAZBlxRllKfUseNpL7DuAeONw3M+DN KuIcV5bNYVhsWFXrm2p2LNmE9z446F+mvrMrNzGsVk9101/5znr+qQq+PbMftBhkcQlb USzr8V8KVJuFREpHYoQs4AatNDmsj5kNJbnpIkYAf43HjjnB3NXJTzE1n5S2kBxXHQ84 L+vHvbV2K7iPrzduO8itJkOOLieGNn/xgmt1Nae9EOO2u8On+6QHMYnoc7/jPtRIl2xc oEUXQA3lmw26jomfKmU2hH63VybGcSCU3haacz+vDSGxRTQq0Py7E1Yuo1RXagH2kTdV wZ6w== X-Gm-Message-State: ALoCoQmW0tPsK6BQHBCGaTd8yliYB+3GUnl0h6mdlGNbNqD2BvFcCdF+f8iVPojka0cE8j8sXhnw X-Received: by 10.180.87.72 with SMTP id v8mr2298027wiz.3.1423553449029; Mon, 09 Feb 2015 23:30:49 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.9 with SMTP id r9ls661395lae.31.gmail; Mon, 09 Feb 2015 23:30:48 -0800 (PST) X-Received: by 10.152.181.129 with SMTP id dw1mr21709303lac.101.1423553448711; Mon, 09 Feb 2015 23:30:48 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id r3si11388363lbo.9.2015.02.09.23.30.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Feb 2015 23:30:48 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by labge10 with SMTP id ge10so18379972lab.12 for ; Mon, 09 Feb 2015 23:30:48 -0800 (PST) X-Received: by 10.112.54.167 with SMTP id k7mr21260196lbp.72.1423553448439; Mon, 09 Feb 2015 23:30:48 -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.35.133 with SMTP id h5csp439875lbj; Mon, 9 Feb 2015 23:30:47 -0800 (PST) X-Received: by 10.68.131.194 with SMTP id oo2mr35530514pbb.29.1423553446613; Mon, 09 Feb 2015 23:30:46 -0800 (PST) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com. [209.85.192.170]) by mx.google.com with ESMTPS id bf5si21746824pbd.252.2015.02.09.23.30.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Feb 2015 23:30:46 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.170 as permitted sender) client-ip=209.85.192.170; Received: by pdbft15 with SMTP id ft15so37280845pdb.11 for ; Mon, 09 Feb 2015 23:30:45 -0800 (PST) X-Received: by 10.68.194.194 with SMTP id hy2mr35197335pbc.83.1423553445607; Mon, 09 Feb 2015 23:30:45 -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 bx13sm18416548pdb.19.2015.02.09.23.30.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Feb 2015 23:30:44 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Thomas Gleixner , Ingo Molnar , Sasha Levin , stable@vger.kernel.org Subject: [RESEND][PATCH v2] ntp: Fixup adjtimex freq validation on 32bit systems Date: Mon, 9 Feb 2015 23:30:36 -0800 Message-Id: <1423553436-29747-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 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.47 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: , For tip/timers/urgent Additional validation of adjtimex freq values to avoid potential multiplication overflows were added in commit 5e5aeb4367b (time: adjtimex: Validate the ADJ_FREQUENCY values) Unfortunately the patch used LONG_MAX/MIN instead of LLONG_MAX/MIN, which was fine on 64bit systems, but being much smaller on 32bit systems caused false positives resulting in most direct frequency adjustments to fail w/ EINVAL. ntpd only does direct frequency adjustments at startup, so the issue was not as easily observed there, but other time sync applications like ptpd and chrony were more effected by the bug. See bugs: https://bugzilla.kernel.org/show_bug.cgi?id=92481 https://bugzilla.redhat.com/show_bug.cgi?id=1188074 This patch changes the checks to use LLONG_MAX for clarity, and additionally the checks are disabled on 32bit systems since LLONG_MAX/PPM_SCALE is always larger then the 32bit long freq value, so mult overflows aren't possible there. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Sasha Levin Cc: stable@vger.kernel.org Reported-by: Josh Boyer Reported-by: George Joseph Tested-by: George Joseph Signed-off-by: John Stultz --- v2: Included the BITS_PER_LONG check to disable the check on 32bit systems, since it generates build warnings in some settings. kernel/time/ntp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 4b585e0..35b25d0 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -633,10 +633,14 @@ int ntp_validate_timex(struct timex *txc) if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME))) return -EPERM; - if (txc->modes & ADJ_FREQUENCY) { - if (LONG_MIN / PPM_SCALE > txc->freq) + /* + * Check for potential mult overflows that can + * only happen on 64bit systems. + */ + if ((txc->modes & ADJ_FREQUENCY) && (BITS_PER_LONG == 64)) { + if (LLONG_MIN / PPM_SCALE > txc->freq) return -EINVAL; - if (LONG_MAX / PPM_SCALE < txc->freq) + if (LLONG_MAX / PPM_SCALE < txc->freq) return -EINVAL; }