From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 174981F00893; Tue, 1 Dec 2026 12:23:52 +0000 (UTC) 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== Subject: Re: [PATCH net] selftests: nettest: reject out-of-range integer values From: netdev-bot+sashiko@kernel.org To: zhangminghui01@kylinos.cn 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 Date: Tue, 01 Dec 2026 12:23:51 +0000 Message-ID: <179612783154.3146.2116613211232217894@kernel.org> In-Reply-To: <20261130115512.57185-1-zhangminghui01@kylinos.cn> References: <20261130115512.57185-1-zhangminghui01@kylinos.cn> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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