From nobody Fri Oct 2 11:40:43 2026 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 EBD2C30FC21 for ; Sat, 1 Aug 2026 22:29:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785623368; cv=none; b=cMm3WmPSlsHuXAgRZy3hntFDiOdXaHhD+5XSyB9J0mRr2z/ZEEUMAwSJLjuudIU83ISczkcK1OVcn21yzH3get5xsPuZRoSIF8KdxRW0Ev3PUDAdv3qkQEpaIqea7yiZLB97DHjn/0LBqWOzb9ufBPC4JeOYxMTv734a3P4C6JU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785623368; c=relaxed/simple; bh=0UFkvjNv0bQt5HrSYPmeTIaP939CNyqwdnq4nzsrZPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sYZ73veYGkc9+kBUdvua3FBV1/QcZrbEA6nJuPlPCPoGTeSQOFYch0lZdP/jewOpIJ+NNeil2Vejmzz+3eHXfQKB/XKHqv4SecMKP/kE/wRiIStOo9Q7NFFHv0it30boYemC3DAmNj/I66U1nz2Xt+cNg01CXktAvMKVSAO8L3o= 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=JNLaW7lz; arc=none smtp.client-ip=209.85.160.180 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="JNLaW7lz" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-51a868b6962so21578821cf.2 for ; Sat, 01 Aug 2026 15:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785623366; x=1786228166; 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=TOfcCbWV+8AiSnf47MNeISZ41ODzpJCZxK60zqEsNHY=; b=JNLaW7lzExiAsoN2R9FX+sdU+NTXrjjZfGdDrdWalQXszj8DbgXe4tvf1SdIitj4gV 34dz08WGZsv/SGH8QtCAPkWtP02OVXybs2K6iBb3MT/M4uKk5a+Ha6KMD/BlZqYPIvaq 1hSZsdb+/B7RBiws4L9Xd4lieNXTFTYTN3SLC/xtjbWgZg9vLpNjEHLenJ2y95XqMfnY mkJ0Gzkk1JOz3xBwe0O36hXUjT6amgdBzIGMUDiAkcqjezl49t4+/QNFcU1/MiRxsa+v JAQ3s8ZOq7C8VyJXIc4ZKPM6BwI0KOAYwr1w8qKcRs8l508MgcvZzH801kPohqJ3JSoM nDdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785623366; x=1786228166; 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=TOfcCbWV+8AiSnf47MNeISZ41ODzpJCZxK60zqEsNHY=; b=IzMsjdEuQnX+x/U6I7HBZe3Dt++s2V8c6V5wQ4FG2xKdTkTXXR1qT8Exnn4cMmbazn DgCiOMn3qAHmKheF5mu52n7ggkQjbCXhlPr/9CWZPTzNZyYp5VpEdD2K/qTk007NCa3B 6XpD1sI3yMsDqQlXQw/Sy19ioET2PgbvH+dZo8rdtRMO/bXADJpd62t6LhoteVtBnPET citqEmGfsIR7CX/QRBjdB72xwhg6O+SGtwbI4moWXKkwXrSa2NV1gDO57rToG9xqLzRO dgl8iTejU64pVp95S/wCC1HsvgwqNUz8XH/MeiAoQ0PMBsvKLtA+AwAbFj5MEEJXWrpn tmqA== X-Gm-Message-State: AOJu0YzzuUd0HxP2aq6OOysHktHN8Am7VLTFggMPTqW32CTcXEvCcbc4 NywKFi+UsdBDWR6JBK9VBs052fv6BL0Yh8gy09EiHEmFs00ZGeJjxY3s X-Gm-Gg: AR+sD128RbvJCkO8qVyA5gCcNilEaUlDYhCxkO+jQHGVFjXJtCUsITq+Oq+UeuQb0gm 8m/KqPLJ2Zc4VJ2kVACeLxrUGyTVngEzzopE8L6szmyZuKldnZNZA6ogXaCrCIHAGpN3Y8N2Jhs x89smQ0LKrtR2v51ui0HEHOC82UEscCsyxshULwDfYkhFGyqrVWEX4G22ghQNtfpzp5spNfGnD0 SLVb8FWxtjqSxSPUgUgOHgO3DhIwa9eYwL+uX7Mtg1njYyRR5F33Wrht16zHrs44IXBogpd+mHy 7aA42QLNDQN8M+g7CSkhAx5r+q/19xjX8GE5dyAoj0hUb2YmrwHY9Y/yHduHkkY2hSqmuD2LLab hnEOKKzohNDTHxtcyZb3QlwgoQAhhCFeEXmO7HAWwtoGqtVnGJpPAQBONfV0EnzAyJVEiVrMgVR IKOUJEPAd9ueEa26raEU6oGdKKmgmDIShL7RjKBbBmGMUxm3peRW+H7TYl6Z2X0eGhBA/sTWQ14 2nA8rHsJuJL1Ge3VKUvpIjM9fzCSpPQ7wILnY02EnH6oEfJggCc3NJz0W0MnXhwKxXjjr7b50YR +/ZJn2N5Ul6+cDI= X-Received: by 2002:a05:622a:34a:b0:50d:3e1e:7998 with SMTP id d75a77b69052e-52b567b2834mr97453361cf.37.1785623366012; Sat, 01 Aug 2026 15:29:26 -0700 (PDT) Received: from ip-172-31-15-253.ec2.internal (ec2-32-195-55-166.compute-1.amazonaws.com. [32.195.55.166]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-52b4eb956c3sm33403831cf.22.2026.08.01.15.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2026 15:29:25 -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, linux-kselftest@vger.kernel.org, Shuah Khan , Vadim Fedorenko , Simon Horman , Deep Shah Subject: [PATCH net-next v3 1/2] ptp: reject frequency adjustments that overflow scaled_ppm_to_ppb() Date: Sat, 1 Aug 2026 22:29:22 +0000 Message-ID: <20260801222923.39017-2-deepshah146@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260801222923.39017-1-deepshah146@gmail.com> References: <20260801222923.39017-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 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 =3D 147573952589676412 makes (1 + ppm) * 125 equal 2^64 + 9, which wraps to ppb =3D=3D 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 --- 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..4111342d64f0 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, s= truct __kernel_timex *tx) delta =3D ktime_to_ns(kt); err =3D ops->adjtime(ops, delta); } else if (tx->modes & ADJ_FREQUENCY) { - long ppb =3D 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 would + * otherwise wrap the result back into the max_adj range. + */ + if (check_add_overflow((s64)tx->freq, (s64)1, &tmp) || + check_mul_overflow(tmp, (s64)125, &tmp)) + return -ERANGE; + ppb =3D scaled_ppm_to_ppb(tx->freq); if (ppb > ops->max_adj || ppb < -ops->max_adj) return -ERANGE; err =3D ops->adjfine(ops, tx->freq); --=20 2.43.0 From nobody Fri Oct 2 11:40:43 2026 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (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 DCF8537646A for ; Sat, 1 Aug 2026 22:29:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785623369; cv=none; b=BMwP9pbpN9HV5a+RdYQ5e4MCn5vGIIfJWLa7sKYGLQyqfnKFrCDzZc17j60+uCGfP8ZzPkaW21Vc5nPb03vQMrxRAcGaFueyfGvRhchLMmyue6aWJqeL2xm24q8szRmbzpl5qmSRSI8f7lAb7PNBsaAWxkMMOmIWtc5QrGrM7gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785623369; c=relaxed/simple; bh=0frn8/1E2g2P+fUpThAiML8loGGJ8rAIh229UyRnt74=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtoSE582ShUVbyXKvjNDsk7E8diFzNvXaMlOCzuodU01Tc3V7fC1EPSk/Iz8wkJyF+OIv+EV+wPMfyFJ+HLWlUsSVa3EKAcIobwE7Z+D7dY/NCriL2lNVAyYaR/yWkNO19NSs/58KuNBu2G9yTI7SCyCFnqyWt516Wejd/QUOHk= 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=MBlg+Mlk; arc=none smtp.client-ip=209.85.222.182 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="MBlg+Mlk" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-92e67555e24so105646385a.3 for ; Sat, 01 Aug 2026 15:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785623367; x=1786228167; 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=Qri4zx3w0KdMvYOIUh/Vq3TWzAXXnzlER5xidoSLn1Y=; b=MBlg+MlkAFUMBfyEWZAemjc3+jM744G7Ixr4Wc9R6rQJnb0q5X83hePfWtlD2+8AYH ufPjIn9M987+DvpXsTgkAgLOLYrfYU20RBpcSIBEnG2ncDeli+3o1LMXUmSNToz/3gaq MUgwejhLJUlg3TT73FXl3XUJW8vFa8HeIilzMmZNb6Hwyk9X7qxsA6MzOb+8gItGwCAt U4B1/CezRFCYKgXAs8D9fsjPNnBlzDwh3EeGgjwFnX/1jMMQRtsKSjDrjzahAyj8Mn5L DElxZrprZN047cOYH8JPzzFXcruLVi748QUvjtoOfC98Nl8xmgmhkEITQWH+b50eNyNO o+pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785623367; x=1786228167; 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=Qri4zx3w0KdMvYOIUh/Vq3TWzAXXnzlER5xidoSLn1Y=; b=akR80rapGrKhG8nPzWaikj4dBiLpk6vgSGhH9pGXlqnUVmJGLu0Vr+wwHJ0rTsXlaV XMGKnUNyOZfo1OfjGCOT5E5LzezXmXB303QSMrOgWSMKxA52pbnE0QiHbNIHUIORnJ0Z DrrittAl0ozsLlFgqk8JyImv93dnZWbhPwsb1bkb9UouK5mJ1eExx9b9eD7L8SbthbtG Xm5EvPEaIE51XSYV3qV0LvMyzNXLKbaY1UxNTT5EQ5sl4lpUMDDili11eUC9kGVgxSVL YStgLzu53rDseU8epVAZgcgmojXPZXw5HRjyFVqH8wgX9HCnvrA6dFFBoDB41dVyOfbN HSSA== X-Gm-Message-State: AOJu0Ywqvf4JN5CYG6K4bHakY4c1XAoANi/XaTwyTle+87niVPvIgWcg VKtXC0j55dkGXQhLpqK+uDGSB+ejP0r/5ASqAtra9wF37eScvuVoY/9e X-Gm-Gg: AR+sD12mdi/sjll44A083dyaPFeQOlM6kL/YA2X3hsqO272xqIEpYR1rO4zejvLljOQ gfO9tsKBfkOev26ifkE0nb8/u5JRbQN0LoOkPUMGMWaP9G9ZJap4t99m+BDOQb8L/ETR79H1eOL sUq9ncQE/tCwbHtZLPL2oC10K0FL6YipRSgyAJiJ7G9Jiq3StCvty2lW5b9PbA+Wtw+fJDVEDun 72ppPKFhv82UVDVf6DXkcEwJKiicpVTS0SriUJxySY+uypHqY4M/E3eUqNi/4Ul93YZleojuTdE zBOEvBQTgGk9uxdximwuw88RdBNjSmv3WX6Sa5dujHEntAy5ddN2LTIXfbuc72X0O/IzQao2eNf gJyfGq3pcxCkrq1EIz6yrmgOuitNDBwrEF0yv945NScJey8azeNJknHv8LOI9aT5PzZLdbWnP9b YpXSa83ejYVmgIQ+dAALhCoSZxchxO7GAAiu2VtmUAMgz0SJVRkZxjRpUoKwLUzPaOmyH8p+JED VXyao4hQqOTdgExHqDQNDw61rmKQ41vtqKaXlrHCqYucRxuDiArgeLkprSaBU86VJr1IbVYdUD5 lJnf39/eIOdYG9Afv75CFCgTMA== X-Received: by 2002:a05:622a:1f91:b0:517:7b6c:4465 with SMTP id d75a77b69052e-52b56752f3dmr113230701cf.22.1785623366788; Sat, 01 Aug 2026 15:29:26 -0700 (PDT) Received: from ip-172-31-15-253.ec2.internal (ec2-32-195-55-166.compute-1.amazonaws.com. [32.195.55.166]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-52b4eb956c3sm33403831cf.22.2026.08.01.15.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2026 15:29:26 -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, linux-kselftest@vger.kernel.org, Shuah Khan , Vadim Fedorenko , Simon Horman , Deep Shah Subject: [PATCH net-next v3 2/2] selftests: ptp: add a regression test for the frequency adjustment overflow Date: Sat, 1 Aug 2026 22:29:23 +0000 Message-ID: <20260801222923.39017-3-deepshah146@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260801222923.39017-1-deepshah146@gmail.com> References: <20260801222923.39017-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: quoted-printable Content-Type: text/plain; charset="utf-8" testptp's -f option stores the requested adjustment as an int ppb and converts it to scaled ppm, so it cannot express the 64-bit scaled-ppm values needed to overflow scaled_ppm_to_ppb() and bypass the max_adj check enforced by ptp_clock_adjtime(). Add a small test that crafts struct timex.freq directly and verifies that an overflowing frequency adjustment is rejected with -ERANGE. The test skips when no frequency-adjustable PTP device is available. Signed-off-by: Deep Shah Acked-by: Richard Cochran --- tools/testing/selftests/ptp/.gitignore | 1 + tools/testing/selftests/ptp/Makefile | 2 +- .../testing/selftests/ptp/ptp_freq_overflow.c | 101 ++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/ptp/ptp_freq_overflow.c diff --git a/tools/testing/selftests/ptp/.gitignore b/tools/testing/selftes= ts/ptp/.gitignore index 534ca26eee48..e63194b44395 100644 --- a/tools/testing/selftests/ptp/.gitignore +++ b/tools/testing/selftests/ptp/.gitignore @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only testptp +ptp_freq_overflow diff --git a/tools/testing/selftests/ptp/Makefile b/tools/testing/selftests= /ptp/Makefile index 8f57f88ecadd..dd7376cc9bf5 100644 --- a/tools/testing/selftests/ptp/Makefile +++ b/tools/testing/selftests/ptp/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS +=3D $(KHDR_INCLUDES) -TEST_GEN_PROGS :=3D testptp +TEST_GEN_PROGS :=3D testptp ptp_freq_overflow LDLIBS +=3D -lrt TEST_PROGS =3D phc.sh =20 diff --git a/tools/testing/selftests/ptp/ptp_freq_overflow.c b/tools/testin= g/selftests/ptp/ptp_freq_overflow.c new file mode 100644 index 000000000000..e90477175958 --- /dev/null +++ b/tools/testing/selftests/ptp/ptp_freq_overflow.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Regression test for the scaled_ppm_to_ppb() integer overflow that allow= ed + * a crafted clock_adjtime(ADJ_FREQUENCY) to bypass the PTP max_adj check. + * + * testptp's -f option stores the adjustment as an int ppb and cannot expr= ess + * the 64-bit scaled-ppm values needed to overflow the conversion, so this + * test crafts struct timex.freq directly. + */ +#define _GNU_SOURCE +#define __SANE_USERSPACE_TYPES__ +#include +#include +#include +#include +#include +#include +#include +#include +#include "../kselftest.h" + +#define FD_TO_CLOCKID(fd) ((clockid_t)((((unsigned int)~(fd)) << 3) | 3)) + +/* clock_adjtime is not available in GLIBC < 2.14 */ +#if !__GLIBC_PREREQ(2, 14) +#include +static int clock_adjtime(clockid_t id, struct timex *tx) +{ + return syscall(__NR_clock_adjtime, id, tx); +} +#endif + +int main(int argc, char *argv[]) +{ + const char *device =3D argc > 1 ? argv[1] : "/dev/ptp0"; + struct ptp_clock_caps caps; + struct timex restore =3D { 0 }; + struct timex tx =3D { 0 }; + clockid_t clkid; + int fd, ret; + + ksft_print_header(); + ksft_set_plan(1); + + if (sizeof(tx.freq) < 8) + ksft_exit_skip("the overflow only affects 64-bit kernels\n"); + + fd =3D open(device, O_RDWR); + if (fd < 0) + ksft_exit_skip("cannot open %s: %s\n", device, strerror(errno)); + + clkid =3D FD_TO_CLOCKID(fd); + + if (ioctl(fd, PTP_CLOCK_GETCAPS, &caps)) + ksft_exit_skip("PTP_CLOCK_GETCAPS on %s: %s\n", device, strerror(errno)); + if (!caps.max_adj) + ksft_exit_skip("%s does not support frequency adjustment\n", device); + + /* + * Remember the current frequency. A vulnerable kernel accepts the + * bogus value below and programs it into the hardware, so restore the + * original afterwards instead of leaving the clock corrupted. + */ + if (clock_adjtime(clkid, &restore)) + ksft_exit_skip("clock_adjtime(get) on %s: %s\n", device, strerror(errno)= ); + restore.modes =3D ADJ_FREQUENCY; + + /* + * (1 + 147573952589676412) * 125 =3D=3D 2^64 + 9, which overflows s64 in + * scaled_ppm_to_ppb() and wraps the result to a ppb of 0. A kernel + * that does not detect the overflow lets this absurd frequency past + * the max_adj check; a fixed kernel rejects it with -ERANGE. + * + * The cast avoids a -Woverflow warning where tx.freq is 32-bit + * without tying the value to the width of long, which differs from + * the width of tx.freq on x32 and other y2038 configurations. + */ + tx.modes =3D ADJ_FREQUENCY; + tx.freq =3D (__typeof__(tx.freq))147573952589676412LL; + + ret =3D clock_adjtime(clkid, &tx); + if (ret < 0 && errno =3D=3D EBUSY) { + /* + * A free-running physical clock (virtual clocks active) rejects + * frequency adjustment with -EBUSY before the overflow is even + * evaluated, so the test cannot run here. + */ + ksft_test_result_skip("%s: frequency adjustment returned EBUSY, skipping= \n", + device); + } else { + ksft_test_result(ret < 0 && errno =3D=3D ERANGE, + "overflowing frequency adjustment is rejected (ret=3D%d errno=3D%d)\n= ", + ret, ret < 0 ? errno : 0); + } + + /* put the frequency back the way we found it */ + clock_adjtime(clkid, &restore); + + close(fd); + ksft_finished(); +} --=20 2.43.0