From patchwork Thu Apr 9 08:47:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zefan Li X-Patchwork-Id: 46920 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 5FDD8218D6 for ; Thu, 9 Apr 2015 08:59:13 +0000 (UTC) Received: by wiaa2 with SMTP id a2sf15834457wia.1 for ; Thu, 09 Apr 2015 01:59:12 -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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=GUvUldskHBFghi0R3bYTJw9BIBUCunvdgVxkfZz7Pd4=; b=m5XOwMlQJBJN2Mk2q4bj6UwDfpU4Zx1VideuB4LDhqfyTDkWR7m84xrZ/YBvFE81ec 3cL4zwxM7AH6BWEqe0PJFySFffobrzPBIV2DdFOuINRZgxdnw5M+pVllmdI/aOC0E91F Mq74E8RoP83HwgfPG0eJSIMEJJAnr2wb01wasFEQFl6aFtNTHyWs8l8khdjlYTSxY37X GXO6n5w8838X1PYqMLsN3RRhqntN9b/YPoD0kamjkl2HmSyFwh9upuUX6GzZvICtnICT XWXyl5OcvZl+QcKIawnoLP5nSU/LTYcMR6W/hV/ZyA1rmH/e/9k1PV2dbZKZKBcQlamr 3APg== X-Gm-Message-State: ALoCoQkh+EkYFiSp+8MFZutwDCwKv2rfxBN/6QfJgNSH0rAZ2qn18pBqW/5bRJeGt//QAYdAFzE7 X-Received: by 10.112.151.146 with SMTP id uq18mr3103228lbb.20.1428569952672; Thu, 09 Apr 2015 01:59:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.129 with SMTP id m1ls256588laf.76.gmail; Thu, 09 Apr 2015 01:59:12 -0700 (PDT) X-Received: by 10.152.6.34 with SMTP id x2mr3606780lax.47.1428569952537; Thu, 09 Apr 2015 01:59:12 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id i2si10934062lbz.68.2015.04.09.01.59.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 01:59:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbbqq2 with SMTP id qq2so77338814lbb.3 for ; Thu, 09 Apr 2015 01:59:12 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr12411296lbc.86.1428569952425; Thu, 09 Apr 2015 01:59:12 -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.67.65 with SMTP id l1csp342799lbt; Thu, 9 Apr 2015 01:59:11 -0700 (PDT) X-Received: by 10.68.227.41 with SMTP id rx9mr53254259pbc.76.1428569950480; Thu, 09 Apr 2015 01:59:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oj13si20546006pdb.149.2015.04.09.01.59.08; Thu, 09 Apr 2015 01:59:10 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-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 S933785AbbDII6y (ORCPT + 27 others); Thu, 9 Apr 2015 04:58:54 -0400 Received: from mail.kernel.org ([198.145.29.136]:44024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755018AbbDII6r (ORCPT ); Thu, 9 Apr 2015 04:58:47 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A14A2042C; Thu, 9 Apr 2015 08:58:46 +0000 (UTC) Received: from localhost.localdomain (unknown [183.247.163.231]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 26D0120450; Thu, 9 Apr 2015 08:58:39 +0000 (UTC) From: lizf@kernel.org To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, John Stultz , "Peter Zijlstra (Intel)" , Linus Torvalds , Sasha Levin , Ingo Molnar , Zefan Li Subject: [PATCH 3.4 172/176] ntp: Fixup adjtimex freq validation on 32-bit systems Date: Thu, 9 Apr 2015 16:47:00 +0800 Message-Id: <1428569224-23820-172-git-send-email-lizf@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428569028-23762-1-git-send-email-lizf@kernel.org> References: <1428569028-23762-1-git-send-email-lizf@kernel.org> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linux-kernel-owner@vger.kernel.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.176 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 3.4.107-rc1 review patch. If anyone has any objections, please let me 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 Signed-off-by: Zefan Li --- 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 7666b24..e32587e 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -660,10 +660,14 @@ int do_adjtimex(struct timex *txc) return result; } - 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; }