From patchwork Fri Apr 3 07:05:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 46743 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D7A8B215B7 for ; Fri, 3 Apr 2015 07:05:30 +0000 (UTC) Received: by wiaa2 with SMTP id a2sf23013731wia.1 for ; Fri, 03 Apr 2015 00:05:30 -0700 (PDT) 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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=KMFY7TFIGPEQT+WRfvrRauIWhZWJnFHZtL33qJIgtuw=; b=PpGogOhu+5MNKfcksvnOs8rANHCrIBOzLavfz55LWkkPy0NsJEKPChs/Y7oKoXBDxB rkkGBg+kBrm2T4GklEvHaMSyKqOuvRO6+ZT/RM7qQAugYLuVIS0HzKBcj/RV/OxblNCI 3sCjS/X7MDB7uSlsaN24BGvWXLZWSCVddmpv95AvEnPjONPbruv+ri/5ikFC2MeP1+za 4AjXfwukLq5OO4gdizq3IxoCC3jCyiZlkbxS2aM4WcsaSNUZ8dIgPlYfvUu+dsugkCRu OoV/f6xPJ7v0jXLL1Gt6ATwhrcZnqJn90EyNqXXT0sJSXpNf8loMm1bl2R+aAsCQgKev 2TbA== X-Gm-Message-State: ALoCoQmXGnBmFe+rrGnUPKU2m5rOKvUO6chuQb4RVxqIvbAkRdPQUYQE3iWbK/QfDvyGnsKKUSBK X-Received: by 10.180.107.33 with SMTP id gz1mr270187wib.3.1428044730189; Fri, 03 Apr 2015 00:05:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.115.211 with SMTP id jq19ls323860lab.32.gmail; Fri, 03 Apr 2015 00:05:29 -0700 (PDT) X-Received: by 10.152.21.99 with SMTP id u3mr937010lae.105.1428044729919; Fri, 03 Apr 2015 00:05:29 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id r10si6010370lar.124.2015.04.03.00.05.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Apr 2015 00:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by lahf3 with SMTP id f3so74286035lah.2 for ; Fri, 03 Apr 2015 00:05:29 -0700 (PDT) X-Received: by 10.112.162.232 with SMTP id yd8mr931665lbb.41.1428044729254; Fri, 03 Apr 2015 00:05:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp1786388lbq; Fri, 3 Apr 2015 00:05:28 -0700 (PDT) X-Received: by 10.70.43.8 with SMTP id s8mr2010290pdl.132.1428044727036; Fri, 03 Apr 2015 00:05:27 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ff10si10769926pdb.108.2015.04.03.00.05.25; Fri, 03 Apr 2015 00:05:27 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751335AbbDCHFZ (ORCPT + 1 other); Fri, 3 Apr 2015 03:05:25 -0400 Received: from ip4-83-240-67-251.cust.nbox.cz ([83.240.67.251]:44345 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751497AbbDCHFY (ORCPT ); Fri, 3 Apr 2015 03:05:24 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.85) (envelope-from ) id 1YdvfI-0005OF-Pl; Fri, 03 Apr 2015 09:05:16 +0200 From: Jiri Slaby To: stable@vger.kernel.org Cc: John Stultz , "Peter Zijlstra (Intel)" , Linus Torvalds , Sasha Levin , Ingo Molnar , Christian Riesch , Jiri Slaby Subject: [patch added to the 3.12 stable tree] ntp: Fixup adjtimex freq validation on 32-bit systems Date: Fri, 3 Apr 2015 09:05:16 +0200 Message-Id: <1428044716-20683-1-git-send-email-jslaby@suse.cz> X-Mailer: git-send-email 2.3.4 Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@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.54 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: John Stultz This patch has been added to the 3.12 stable tree. If you have any objections, please let us know. =============== commit 29183a70b0b828500816bd794b3fe192fce89f73 upstream. 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 64-bit systems, but being much smaller on 32-bit 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 32-bit systems since LLONG_MAX/PPM_SCALE is always larger then the 32-bit long freq value, so multiplication overflows aren't possible there. Reported-by: Josh Boyer Reported-by: George Joseph Tested-by: George Joseph Signed-off-by: John Stultz Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Sasha Levin Link: http://lkml.kernel.org/r/1423553436-29747-1-git-send-email-john.stultz@linaro.org [ Prettified the changelog and the comments a bit. ] Signed-off-by: Ingo Molnar Cc: Christian Riesch Signed-off-by: Jiri Slaby --- 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 28db9bedc857..6211d5d6d465 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -631,10 +631,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 multiplication overflows that can + * only happen on 64-bit 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; }