From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4FF22D739C for ; Sun, 12 Jul 2026 04:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783829367; cv=none; b=nzcVWoXABoJTFUHCwmYaSRUSPPRnNg1O8ZuZX9AIavWgtT00DOHVolbAOlzFFsUvvy+3R4T27QPF55iDWni/7Jd+jwaWmb5cq3OU11dmuuKhvJaCS/I+3vHl6KhpyndRop6gz20ttojHojlF7Ar+ymIP4TH89GkoTQJIM4WoKUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783829367; c=relaxed/simple; bh=VAj6oUe/TU0O43DOvhQx6ZvzmDHg3qu28qW30e0TS1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsQ5bCo9eHAP3uu0dyH6ad1sRr/LPnZMHBT7ttG3GxeHv0oMaCAwvBS1cDBTogaz6cuQKw8RMMjxj6eAA//H7BeeJzdlAgycG/dZQgSImbtqEdwBXqSqL7Co0E4v9RDb+xFm5U43BRcM7i/7u0NwkQ7JWPyxe5PWus5zPoju8X8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JRn/Ekcy; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JRn/Ekcy" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-8efcef23d21so16681396d6.2 for ; Sat, 11 Jul 2026 21:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783829365; x=1784434165; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jfLzU+Ux3JyzhsCTRzc6rXQZzc52Sb+wpPjR6e6mN6s=; b=JRn/EkcyfRJ6M8Qp16TFbox85SAeTcXEsk7FV3P0Sne64W7hqL0TnrM12c3jCFXPcw 1rPgeB9PtPB5ejzU32hzIaHKPV9y3xSYFnsiqHRpfsEcgeO1y7UpQdQhrqTeOakwRWma hh6uWI6QuWD4jxuGPZwsNzTNXTqCQclzAqrLcghY3kjRgPGQ73xnEpYK0d8B5epqVmT4 Sc+RsLDNqt4S919je58iuqO8wSuMMb5VuK7nEam4+R7yO0v3OdCW7DOQpyEzVbAtlu5d fovN/25J/SALI13VtV7s9vQfsthhlHqf+bA+iR7/nyiltehKRKjiiEzrwu7s+bE5sWcw gfFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783829365; x=1784434165; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=jfLzU+Ux3JyzhsCTRzc6rXQZzc52Sb+wpPjR6e6mN6s=; b=PRM9oT0IX/sWskDz8LImkETkiRk3H3V6OruWFGhS6tvakXUXyyqWtKH41Hdm3gBlWQ JI8o+5+KyhqhZp19nTGYW7wpLVQlgQgmivn1e/nIYL7KjDL2sbHQkpTEd81ThORj5o/r P1NObfN1If3ZGBoIsHA40IJhCAqmIC/m/7dC2gH+2V96ImT7xeZ3yGjKf4WhwvQsKDb0 ZSy4ifYZw+xNdvdFxwlI9CeRWb0y0WyChbaZSP4FSbPr/mBq7UUsxeUXDx+zuNaxK42i n7WNijJy/PV+oxKfhPzKT1446lohXWkK8QjMoynOu1ey7I+0i1OkXA3uJNap3eytZ4uX o0mg== X-Gm-Message-State: AOJu0Yx7u/U7CYmFSLdkcXsb9raDwYuGXwgH8yf9muAmUC41lx6QjU/l DUjhmzCxa3rrP5lZ7tTC8e0d8M49j20SUukBaKJpuiCyxrgwGkNsvhq9 X-Gm-Gg: AfdE7cmigmTY4Ve0IdkeaeQ6iKDARa2k3mkzAg+/gv8Vlb9wY1ebZ/HNaW6OqFld/f7 LJrUv+EgfMdm8DOK9OHiYlr+4nFsDTwybbPthZz1CG5CZPi7n9JP0JdQ51gKVvrx7NiOZfironn Zjw1n5BTevRKmu9EXiSqa57k71UeE6LXvTJf1z4B/a2wtOAKc/xpIunSacFNqbyt4M+gOwRRXgC GUu0ecFx6Rt9EME2ei8R4TKfatMpatF8IaypGDnwlllGoTTIODtnJN4n91tJMeEqX2zfV8GhHPy aS9OfDjTzd7w6OlzWipGvFVbqcXiQEc9jFp6EEWthebHdio25TO98z8iXpPCam7ZxKkzisSqWm6 5aPVejhchq13kymqh7ng4p0atl0ISzxi1DjdariyIVGoTm64VstAleReo0BfqhXnRpYYbk3fHMI q+WNNsD2CaoSouNgoC0KP6TP+0ZGzd+a9IDhAdROjpQ5d52GWH0V5x/By3YpAb5MLVSVLTXqs5G fweKWkdBIXMSc1/32UErTvqhcIfFC9Lm9o/AUygQwk= X-Received: by 2002:a05:620a:6403:b0:92e:c117:5ee6 with SMTP id af79cd13be357-92ef2c63c87mr502225185a.82.1783829364696; Sat, 11 Jul 2026 21:09:24 -0700 (PDT) Received: from ip-172-31-15-253.ec2.internal (ec2-44-200-214-82.compute-1.amazonaws.com. [44.200.214.82]) by smtp.gmail.com with ESMTPSA id af79cd13be357-92ee5cf9d9bsm687147085a.28.2026.07.11.21.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 21:09:24 -0700 (PDT) From: Deep Shah To: netdev@vger.kernel.org, Richard Cochran , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , Andrew Lunn Cc: linux-kernel@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, Deep Shah Subject: [PATCH net 1/2] ptp: reject frequency adjustments that overflow scaled_ppm_to_ppb() Date: Sun, 12 Jul 2026 04:09:21 +0000 Message-ID: <20260712040922.6403-2-deepshah146@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260712040922.6403-1-deepshah146@gmail.com> References: <20260712040922.6403-1-deepshah146@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ptp_clock_adjtime() converts tx->freq to ppb with scaled_ppm_to_ppb() and rejects the request if it exceeds ops->max_adj. On 64-bit systems that conversion computes (1 + ppm) * 125 in s64, which can overflow for a large tx->freq and wrap the result back into [-max_adj, max_adj]. The check then passes and the original out-of-range value is handed to ->adjfine(). For example tx->freq = 147573952589676412 makes (1 + ppm) * 125 equal 2^64 + 9, which wraps to ppb == 0 and is accepted. Reject the request with -ERANGE if either the addition or the multiplication overflows. This hardens the max_adj sanity check and is not a security fix. It follows up commit 475b92f93216 ("ptp: improve max_adj check against unreasonable values"), which fixed the analogous s32 narrowing but not this overflow. Fixes: d39a743511cd ("ptp: validate the requested frequency adjustment.") Signed-off-by: Deep Shah --- drivers/ptp/ptp_clock.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index d6f54ccaf93b..f83aa44b0a74 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -159,7 +160,18 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx) delta = ktime_to_ns(kt); err = ops->adjtime(ops, delta); } else if (tx->modes & ADJ_FREQUENCY) { - long ppb = scaled_ppm_to_ppb(tx->freq); + long ppb; + s64 tmp; + + /* + * scaled_ppm_to_ppb() multiplies (1 + freq) by 125 in s64; + * reject a ->freq large enough to overflow that, which could + * otherwise wrap the result back into the max_adj range. + */ + if (check_add_overflow(tx->freq, 1, &tmp) || + check_mul_overflow(tmp, 125, &tmp)) + return -ERANGE; + ppb = scaled_ppm_to_ppb(tx->freq); if (ppb > ops->max_adj || ppb < -ops->max_adj) return -ERANGE; err = ops->adjfine(ops, tx->freq); -- 2.43.0