Article View: linux.kernel.netdev
Article #25226Re: [PATCH net] selftests: nettest: reject out-of-range integer values
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 12:23
Date: Tue, 01 Dec 2026 12:23
126 lines
12573 bytes
12573 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The rewritten str_to_uint() in
tools/testing/selftests/net/nettest.c still accepts some out-of-range…
- [Low] selftests: nettest: str_to_uint() accepts wrapped negative values
via strtoul()
--
selftests: nettest: reject out-of-range integer values
This patch changes str_to_uint() in nettest.c so the strtoul() result
stays an unsigned long. The errno, trailing-character and range checks
now run before the value is narrowed to unsigned int. The goal is to
reject out-of-range arguments such as 4294967296, which used to wrap to
an in-range value.
> diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c
> index 1f5227f3d64d6..4421beb76a130 100644
> --- a/tools/testing/selftests/net/nettest.c
> +++ b/tools/testing/selftests/net/nettest.c
> @@ -625,24 +625,27 @@ static int set_dontroute(int sd)
[ ... ]
> errno = 0;
> - number = (unsigned int) strtoul(str, &end, 0);
> + number = strtoul(str, &end, 0);
>
> /* entire string should be consumed by conversion
> * and value should be between min and max
> */
> - if (((*end == '\0') || (*end == '\n')) && (end != str) &&
> - (errno != ERANGE) && (min <= number) && (number <= max)) {
> - *value = number;
> - return 0;
> - }
> + if (end == str || errno)
> + return -1;
> + if (*end != '\0' && (*end != '\n' || end[1]))
> + return -1;
> + if (number < min || number > max)
> + return -1;
[Severity: Low]
Does this still let negative arguments wrap into the accepted range?
strtoul() accepts an optional leading '-' and negates the parsed
magnitude in unsigned long arithmetic. As long as the magnitude itself
fits in an unsigned long, errno is left at 0 and end advances past
every digit. None of the new checks catch that case.
On 64-bit, strtoul("-18446744073709551615", &end, 0) returns 1 and
strtoul("-18446744073709551361", &end, 0) returns 255, both with
errno == 0 and *end == '\0'. Both values pass the min/max check, so
nettest -Q -18446744073709551361 runs with a DS field of 255 instead
of reporting "Invalid DS Field".
On 32-bit, any value in [-4294967295, -2147483649] passed where max is
INT_MAX wraps into [1, INT_MAX] and is accepted. That covers the -t
timeout and expected_dev in resolve_devices().
The port, protocol and MD5 prefix length options go through the same
helper. A small negative such as -1 is rejected only because it wraps
to a value far above max. That is presumably what the negative -Q case
in the testing notes exercised.
The commit message says a malformed argument should fail rather than
make nettest run with a different DSCP field, protocol, port or
timeout. Should str_to_uint() also reject a leading '-' before calling
strtoul()? It would need to skip the leading whitespace that strtoul()
itself accepts. Parsing with strtoll() and rejecting negative results
would be another option.
[Severity: High]
Can negative arguments still wrap into range here?
strtoul() accepts a leading minus sign and negates the parsed magnitude in
unsigned long arithmetic. If the magnitude fits in an unsigned long,
errno stays 0 and end moves past every digit.
On 64-bit, strtoul("-18446744073709551361", &end, 0) returns 255 with
errno == 0 and *end == '\0'. That value passes every new check above.
The callers in main() pass optarg straight through:
case 'Q':
if (str_to_uint(optarg, 0, 255, &tmp) != 0) {
fprintf(stderr, "Invalid DS Field\n");
So nettest -Q -18446744073709551361 runs with dsfield 255, and
nettest -p -18446744073709551615 runs with port 1.
The -t and -P options go through the same path. So do the MD5 prefix
length and expected_dev in resolve_devices(). On 32-bit, -4294967295
becomes 1.
A small negative such as -1 is rejected only because it wraps to a value
far above max.
The commit message says a malformed argument should no longer make nettest
"run with a different DSCP field, protocol, port, or timeout instead of
failing".
Could str_to_uint() also reject a leading '-' (after any whitespace)
before it calls strtoul()? Another option is to parse with strtoll() and
reject negative results.
>
> - return -1;
> + *value = (unsigned int)number;
> + return 0;
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130115512.57185-1-zhangminghui01%40kylinos.cn
Technical Details
Message-ID:
<179612783154.3146.2116613211232217894@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375014-linux-kernel-netdev=dewy.ruReferences:
<20261130115512.57185-1-zhangminghui01@kylinos.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375014-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] selftests: nettest: reject out-of-range integer values Date: Tue, 01 Dec 2026 12:23:51 +0000 Organization: Usenet Network Message-ID: <179612783154.3146.2116613211232217894@kernel.org> References: <20261130115512.57185-1-zhangminghui01@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1707866"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:OSmSl/5mbJMvYY6ABbp7vCaRK4s= sha256:erF6HTatUQmvnVARGtdJaMUzupYC91hC+fyAvMKJaT4= sha1:7m4iN5uCj8wI6yOC2cNY2tHkunM= sha256:EDI0lPEBRnvJIGbxoKoQhO43Akxl7Ob4HrLU8Ratt4I= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id C717F117370; Tue, 1 Dec 2026 15:24:09 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MXebr3FADe54; Tue, 1 Dec 2026 15:24:06 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-375014-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 00C1511736E; Tue, 1 Dec 2026 15:23:57 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 8F4FD600FED; Tue, 1 Dec 2026 12:23:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796127834; b=hrIypMOBV59z/aZSnJihshke+6buLiE/su3m725NnGNKulIRFylYBx8KGsvL/TX5AgW6 lDk0JA31uByn5h3lA8yCnfwYLq1zHUuO9ZtILXbKmCb+3qUtUVUyeDX0R1wzOU2IzQywS 4WvIL/1eH+Y/SwbsUH/4CFWE7GZfvBaejw37KORK6h2HGQO3H1mT3fFmk7ZN19PLDHcx5 sIWnonNtgSuEnYDQyaFmGhcF/E72mPtunF4r03J2P6m3SQsQs6hoQ8ha6hRitDYewWXMo VaoXR1rHDZ8tRhhp8plB5LgfTYpROoQNZc6h0MBcWhe/Ndh5egH4Z4ZpSGCpKLEWlKQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127834; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=C/tW6d+90e+CHFmvfwjUKweRhqN5BOJPZ4yyxbyeO5w=; b=F18Azxb85cvNnhFmC+5MV4vHDPPbx01W7rjidr34SMnWtxUGc9Y8gJrIrAmqwD3E34YY KNCNbitaQyCgmhGMUaeBFpD3puKUfLqWRFe3h/YgxIJFk5CSWKvaAX70ecsYvUhFys0nY qmDXfx44u4gffWchn5CDj3hOsSKSttPjPwWB9uN2Ej0Z/Hz2ej1PC6qESKHP0IcVo0VdK W6/tSVdu8Z8fc5mPaZTtAfQfOKBpUZ1RRDfKOveiLhypiSZKqULFjMGs2I3GuS+hg6NMq I4dervbUs8eS7eFjWlIgzIMtutK5Kmdr5gdTq9qdQ0z/EE2serO7uG9w6jOjThf8l3w== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NjJI85Er; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB172606A329; Tue, 1 Dec 2026 12:23:54 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NjJI85Er X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127833; b=sGc11dwrPuUwBBPcpU4q4O2iTVeGWuKBh18b1+b3TgS37OyGWf7U1KSjcHw2Q1j0KeJF PlyViSIxDDS3DM5btW3iR1xFF73dsVN2ag2F//2cp4VpQrXPtlwvnOTV80WaKFmgzV5+i PxJ+oUr1ODJgH0Bo3uM8/DATH4gPF+6YfM8luF4rzAyByaWiI0DzGxjKvZx2dBuQKpORr suCw7uNJIJGA+d5pjTb2dfMYZJ0hqCflvnqwMd484Bi93JZTCeUTmsMtzDId6hY+Kk4UV DPXzM+Kl/n3q8ECQgzwa6uDiPwJg9+gjUMdYveAJu5n0XOXXoSsMabBM5XdYQrp6tqw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127833; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=C/tW6d+90e+CHFmvfwjUKweRhqN5BOJPZ4yyxbyeO5w=; b=J76xlaIhxKCHLGlwKiPhzVc0XdOQR5MNvaSbuRPIDsI9MqxZzdruusL+BKCKd6TluB4m c925j7rbWP0uMxlom6EKmB+xE1Vqe6XHZaAnUZIrImt8QYX4LMOeh0I1ncHEipCZ5Tt3D sVO/YjTKDJ2IEtPcXSHb4sARYRpm59LrV7m4N3Im1IT1OdJLOOrCATYukRv8ehk15QmuP IaRbq11w6K3V2sZxvAY7E2+lrs+ggYpBoAWmy2F9bqOjmpAjpHgwVWiMRY5OWl+QWlP8H NtObdVm/i7lqqVHqcBvz9An7EdLCNY4q1wntVqB8nqTY78q/AOyRJB1CpEKuVCfT5NA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NjJI85Er; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D606C606A31A; Tue, 1 Dec 2026 12:23:53 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 174981F00893; Tue, 1 Dec 2026 12:23:52 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796127832; bh=C/tW6d+90e+CHFmvfwjUKweRhqN5BOJPZ4yyxbyeO5w=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=NjJI85Er0bAYrAx2F/rAuJRUyj+qWyHcT8OxIzxiM5il+jfQT1Oqdy1nfASSCzP4E 61fy1jTNwASCUWvHNXZZ9QXn2r1LBrMpCF4uf2vcc9KPOvYGVfuR4vf1yOKr/dBY0j 0pfqsk41FYHU+bm3C3UcTbTWlEHfGU05yxWdSY5EVXfnTS9n3jZ+eCznhdJAKlzQQF UrJz1GlGPa3FFSRH7/hrnuOm53oUPtLYLK2SE5UA48yEwLzu7E5A3+j5EfMm/Aj+VK O8ADfMCWbbNM4yO/kaGoCRyMKdzbhdZHqSlhrErnpu8m1J0mSLkSAOxz/f4ZzTsQfV FVctJ19pOUKXw== X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, shuah@kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, horms@kernel.org, dsahern@kernel.org X-In-Reply-To: <20261130115512.57185-1-zhangminghui01@kylinos.cn> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list