From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (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 02DC9318EDA for ; Sun, 2 Aug 2026 18:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696582; cv=none; b=VpCc5B620rMW05YDQMqtHlpAjru65/29w7pYXApXLSrHq3t7DY6IU4itjD4asO53UDVDOn030lTVGE3ygaMCnruFON21fkKA6RG/5fJ+8X0A0fHtavBRytC/WZJtVebThTqKH6XRzEKCYpGdUIhrEOT6w52XeAhnaBfW4W1y+OE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696582; c=relaxed/simple; bh=FItujQTaL37fnHyc36dq92juCbwZqjbsZ66OaWR5SlY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TdrXJ8VS94IJkaD7OmQPaYSg9rIv/4pLL7j48Naqxc1Ir/5iw6s0Gc73OTaVosVGmnPcwtTi7WMB3k0XBbs/bPHF9b8XKmF6Q3rtqqamw2l0UJGfA1cfBOWaPa2nwU7KsFddTWJBYoY1wg9RAgba7JnkGisZSXcvWNbGCpWuEqc= 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=JSiG9w1I; arc=none smtp.client-ip=74.125.224.48 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="JSiG9w1I" Received: by mail-yx1-f48.google.com with SMTP id 956f58d0204a3-6682259cb3dso4585654d50.1 for ; Sun, 02 Aug 2026 11:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785696580; x=1786301380; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QI6mRtOQUFw0EJeFqBwofkcyAca+4a6EqqEAU0Swdws=; b=JSiG9w1IFzYaBbSLjg98eoYHxDuBID4YfVTnQBpDbakQf1/2YEo3FRQ5mWyElteGHD TnfgIsGAOg71Mq7xFl/77B9d1AqjAu6fXx0fhsRDAHl6DjoT7CygCfUe5Mp4IOzoAKeU 6XMRQETlFqDgYzwmMaBQ8jt4JE/XoECyaah8QS23ZRTltTodBxdv7pzWb/XdmiGlGzQB U3bnzMeKLvdR6EA5eA3dyB7+OIxC1q6VHvFXOADQ96m2ONAeBNhuxPfDuu/iduQe8YO1 zlxmoU6dBBMj55azqAglnU/pSHqxQeNAaQIkxV+kqt4w9NlXXZdpQ+rHU3qtBQPrMS4U VC8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785696580; x=1786301380; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QI6mRtOQUFw0EJeFqBwofkcyAca+4a6EqqEAU0Swdws=; b=T1uy50E2FDfpr4p1KvLSR6ACGqUciTjC02/FJC6Rn/yd/6TUMOkBzI3y/VHkJzu7Dx hPWCVr0IJJi0FoOuzp3Lciq07ivu1uJkS9YBCCgDVJMCyoTSPyW2W7YXT4Azq4bPLcPO YX7q1D0MEnkba1iujoXCKXJ2F0hue3azGFcE1KJ1N7y2dG3Povq7BV8PiQiNU9tJ+Dwh UgLBHUYBua8pjOJ7G3Q2hkS+Sp3fAMiNBU8wgkFhwRDOFLZ2B88+Pp2XqyNxoUk1xG1t SMy55FX1qVRKK0WyK0j7+4OdXAgdmeyELLZiwlswFqQGJ5RYLQ0Z7/Ludnr/L7oIY3G+ 7hiA== X-Forwarded-Encrypted: i=1; AHgh+Rpq8di8lHkwACaNSH8yRTy53CqO1rX1PCr5xx1jbdGOtMrFnkmnBTsYdtRkxiaa4HA8vTX79JEPJ57gRLk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9fdNHm9chi/mLBglCLimqkNLDATxheAR7UHcYU2enAAvb6lAi KW7Hf0f3b+gR4Lt+RQeBlrGqJi3igsI/2xrOnxqt/UGrWkRoM3j49tjV X-Gm-Gg: AR+sD13KUuHOBy8u8XPTDY+aMQKg+bNUT5j4aVWN5ihS2X9sDkZZHDNxjNh+tU4VEWm ElaaHALtFpk2maD74Qw2cFZR7DL6yvHeoh/62s4yS2KXBCc6osgPlyZqQSMCVq2WJayKgrVhDR4 OnT1A1yZBH7qbh2KttJoxnf83cNwRgm0a0NeWTG3m8SYOrhXQmYpIaqM8uRtltkVtyYb6SAs70b Wq95ydM6jEzOs4Qs4TqNHqEk1tzWswgiUeos96tAHd4l60W/6m1wAG8N4krbSnMoX16ymnjdIGT FlNSTQDinCcSmoUmEqZTBivQlA9KHpi1uMcBEtY97TkxMsU4Z8O3uN+j099SnS8AYvIFAbsPArA vUunn70ICTyQJFy4ff74P3L/Ql5mnLBBJTeUlUaiWlN+M4Duz00TCgHAIQIjKbWGkz8WIoG/cpL MVsLn4tKHZIBQlSnv12UNJeUds0035AAL3tbT10CS4OI8E2X3FsM17fTnWdPMiEEHwdeCxHHf2y G+3TTg= X-Received: by 2002:a05:690e:4808:b0:664:c5f8:e342 with SMTP id 956f58d0204a3-6694f84c666mr6818553d50.3.1785696579807; Sun, 02 Aug 2026 11:49:39 -0700 (PDT) Received: from hoboy.vegasvil.org ([2600:1700:2430:6f6e:e2d5:5eff:fea5:802f]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6695ea8f0dasm2190358d50.12.2026.08.02.11.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2026 11:49:38 -0700 (PDT) Date: Sun, 2 Aug 2026 11:49:36 -0700 From: Richard Cochran To: Deep Shah Cc: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , Andrew Lunn , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan , Vadim Fedorenko , Simon Horman Subject: Re: [PATCH net-next v3 1/2] ptp: reject frequency adjustments that overflow scaled_ppm_to_ppb() Message-ID: References: <20260801222923.39017-1-deepshah146@gmail.com> <20260801222923.39017-2-deepshah146@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260801222923.39017-2-deepshah146@gmail.com> On Sat, Aug 01, 2026 at 10:29:22PM +0000, Deep Shah wrote: > ptp_clock_adjtime() validates an ADJ_FREQUENCY request by converting the > requested scaled ppm to ppb and comparing it against ops->max_adj: > > long ppb = scaled_ppm_to_ppb(tx->freq); > if (ppb > ops->max_adj || ppb < -ops->max_adj) > return -ERANGE; > > scaled_ppm_to_ppb() computes (1 + ppm) * 125 >> 13 in s64. For a > sufficiently large tx->freq the multiplication overflows s64 and wraps, > so the resulting ppb can fall back within [-max_adj, max_adj] and pass > the check. The unclamped tx->freq is then handed to ->adjfine(), where > drivers scale it again (e.g. scaled_ppm * 762939453125 in ptp_idt82p33) > and program a bogus frequency word. > > For example tx->freq = 147573952589676412 makes (1 + ppm) * 125 equal > 2^64 + 9, which wraps to ppb == 0 and is accepted. > > The caller already has write access to the PHC, so this hardens the > max_adj sanity check rather than crossing a privilege boundary, and > well-behaved user space (e.g. ptp4l) never requests such values. It is > a follow-up to commit 475b92f93216 ("ptp: improve max_adj check against > unreasonable values"), which handled the analogous s32 narrowing but not > this multiplication overflow. > > Detect the overflow with check_*_overflow() and reject the request in > ptp_clock_adjtime() instead of acting on the wrapped value. > > Signed-off-by: Deep Shah > Reviewed-by: Vadim Fedorenko Acked-by: Richard Cochran