From nobody Thu Apr 2 01:49:46 2026 Received: from forward103b.mail.yandex.net (forward103b.mail.yandex.net [178.154.239.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F15D2E8DE5; Thu, 12 Feb 2026 16:44:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; cv=none; b=SJ67gGY2mpJsSotbFkMRzDMw4l0NDpR7VgAHl4gQyJmMs/6ubfiQwNtFkedfcPLDhZ4oc2V9ucgrKD7kVK8ljjPWES71wHwCB366OFzn+6tkNDWPXCAczVJGyGAaNBiTrMyt7KnwAEBUqdsX96hYMciNwjNn7oS/pU8FkS8jfPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; c=relaxed/simple; bh=pxhCE1IopNkcK9Ec3eMFvUr5dcrXFpjQJaInJqtRiLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FBZsV6/Bl4hE6riLmiwe1dLI5OA8yJfdR2cPBmnvBvFTHudhtBhZGHFlwXKKTHZyDPzrfCQ9ZlDs+Uh29YehzNCjfFM2murZ7vKJyTAiUVws2CLeUgD/ktVTuC/HzsDyPCU5qZ7R7Y5xvb4xcVxuqd7hWe+xYMTLPvzbwowHZeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=nJPwIkPp; arc=none smtp.client-ip=178.154.239.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="nJPwIkPp" Received: from mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net [IPv6:2a02:6b8:c1e:3990:0:640:454b:0]) by forward103b.mail.yandex.net (Yandex) with ESMTPS id F4024C0063; Thu, 12 Feb 2026 19:44:16 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id EiXcAWCGxeA0-sXx3qsF6; Thu, 12 Feb 2026 19:44:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770914656; bh=qOxwQMQR/hRQV0CpfELaF6n/K7loZVqmdu8PH7RWFS4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=nJPwIkPpVtYDmPbhFR4T5OjJYOA9AAL2IzmSmBedABc7k/oBlQTUAn8eV8U/BJCgQ ad7cu8W005GUMnGet2JskF9AzmU8TB1giH4uGPhgWltz7TEqieJ4bsqd2HsIlLBv2D NPfRzGEaqoRTIm0E3GL7A6j5PMbHJ452+6lZ9tQY= Authentication-Results: mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: David Laight , Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v8 1/5] lib: fix _parse_integer_limit() to handle overflow Date: Thu, 12 Feb 2026 19:44:09 +0300 Message-ID: <20260212164413.889625-2-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212164413.889625-1-dmantipov@yandex.ru> References: <20260212164413.889625-1-dmantipov@yandex.ru> 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" In '_parse_integer_limit()', adjust native integer arithmetic with near-to-overflow branch where 'check_mul_overflow()' and 'check_add_overflow()' are used to check whether an intermediate result goes out of range, and denote such a case with ULLONG_MAX, thus making the function more similar to standard C library's 'strtoull()'. Adjust comment to kernel-doc style as well. Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- v8: do not use explicit temporary in check_xxx_overflow() calls and handle overflow flag using separate variable v7: drop redundant check against ULLONG_MAX and restore original comment v6: more compact for-loop and minor style adjustments again v5: minor brace style adjustment v4: restore plain integer arithmetic and use check_xxx_overflow() on near-to-overflow branch only v3: adjust commit message and comments as suggested by Andy v2: initial version to join the series --- lib/kstrtox.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/kstrtox.c b/lib/kstrtox.c index bdde40cd69d7..cd67f494c3bd 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -39,25 +39,30 @@ const char *_parse_integer_fixup_radix(const char *s, u= nsigned int *base) return s; } =20 -/* - * Convert non-negative integer string representation in explicitly given = radix - * to an integer. A maximum of max_chars characters will be converted. +/** + * _parse_integer_limit - Convert integer string representation to an inte= ger + * @s: Integer string representation + * @base: Radix + * @p: Where to store result + * @max_chars: Maximum amount of characters to convert + * + * Convert non-negative integer string representation in explicitly given + * radix to an integer. If overflow occurs, value at @p is set to ULLONG_M= AX. * - * Return number of characters consumed maybe or-ed with overflow bit. - * If overflow occurs, result integer (incorrect) is still returned. + * This function is the workhorse of other string conversion functions and= it + * is discouraged to use it explicitly. Consider kstrto*() family instead. * - * Don't you dare use this function. + * Return: Number of characters consumed, maybe ORed with overflow bit */ noinline unsigned int _parse_integer_limit(const char *s, unsigned int base, unsign= ed long long *p, size_t max_chars) { + unsigned int rv, overflow =3D 0; unsigned long long res; - unsigned int rv; =20 res =3D 0; - rv =3D 0; - while (max_chars--) { + for (rv =3D 0; rv < max_chars; rv++, s++) { unsigned int c =3D *s; unsigned int lc =3D _tolower(c); unsigned int val; @@ -76,15 +81,17 @@ unsigned int _parse_integer_limit(const char *s, unsign= ed int base, unsigned lon * it in the max base we support (16) */ if (unlikely(res & (~0ull << 60))) { - if (res > div_u64(ULLONG_MAX - val, base)) - rv |=3D KSTRTOX_OVERFLOW; + if (check_mul_overflow(res, base, &res) || + check_add_overflow(res, val, &res)) { + res =3D ULLONG_MAX; + overflow =3D KSTRTOX_OVERFLOW; + } + } else { + res =3D res * base + val; } - res =3D res * base + val; - rv++; - s++; } *p =3D res; - return rv; + return rv | overflow; } =20 noinline --=20 2.53.0 From nobody Thu Apr 2 01:49:46 2026 Received: from forward100b.mail.yandex.net (forward100b.mail.yandex.net [178.154.239.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BBBC35D5E9; Thu, 12 Feb 2026 16:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; cv=none; b=uQCs9Xn3XkY9rcmwa6s+D7ceXSvyjZ5VNnfBwdUghV2IZTFSWhpd3/VWu+so+ijK98uiDcAqGmtcW20ICCKDd31FRhMR/60h4agZfN9dXDpKvuV88ErLkTos73wPEOfauso20VtZvRs1pbM48jEX+70u1apr77O1fbxSFuF5sZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; c=relaxed/simple; bh=S+pOB972MT+mMKCqNOQm1kjpd0h9eXT09IaTLj01XBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OTWcfVoTwb5uMGK7VoiZ7pOKXSyhkAksxJ/xOhFWX9JUvCcsRN80YXkKnRxvm97oRLuuAO8CbJ3rkhFTuSsCe19eT8J3oJH8NUZwYsthTjrD41um5fBWPJFc3EiRruttEnCX6+K5/aNO75/tnZoe5agYAchZTp/xwwjtatSzotM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=fflf5iFm; arc=none smtp.client-ip=178.154.239.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="fflf5iFm" Received: from mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net [IPv6:2a02:6b8:c1e:3990:0:640:454b:0]) by forward100b.mail.yandex.net (Yandex) with ESMTPS id AFBB180898; Thu, 12 Feb 2026 19:44:17 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id EiXcAWCGxeA0-OjK3dee0; Thu, 12 Feb 2026 19:44:17 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770914657; bh=/uiI4r2yK9BJQMApU7dPAG4Xjf0TSjmYqI1MlncSPgI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=fflf5iFmOe0y8i6nN2qHPKu3qB+ojutnRL8Gio6CjNHJAibcMeAfHdQX4PmwBL82D o3zcE6wayun3s8j7jPaSVgCNAM5m0D0gS76Oz2OAKkBDYNBDvnFDhqBvmUL5qeooWr nILwOFMw9Tv6lG8y/R20Kn/sjsTJzuPyVS8/nJcw= Authentication-Results: mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: David Laight , Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v8 2/5] lib: fix memparse() to handle overflow Date: Thu, 12 Feb 2026 19:44:10 +0300 Message-ID: <20260212164413.889625-3-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212164413.889625-1-dmantipov@yandex.ru> References: <20260212164413.889625-1-dmantipov@yandex.ru> 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" Since '_parse_integer_limit()' (and so 'simple_strtoull()') is now capable to handle overflow, adjust 'memparse()' to handle overflow (denoted by ULLONG_MAX) returned from 'simple_strtoull()'. Also use 'check_shl_overflow()' to catch an overflow possibly caused by processing size suffix and denote it with ULLONG_MAX as well. Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- v8: do not use temporary in check_shl_overflow() v7: do not double-adjust endptr and drop redundant check against ULLONG_MAX v6: handle valid-suffix-only string like "k" as unrecognized, minor style adjustments v5: initial version to join the series --- lib/cmdline.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/cmdline.c b/lib/cmdline.c index 90ed997d9570..f6e4b113ca9f 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -150,39 +150,46 @@ EXPORT_SYMBOL(get_options); unsigned long long memparse(const char *ptr, char **retptr) { char *endptr; /* local pointer to end of parsed string */ - unsigned long long ret =3D simple_strtoull(ptr, &endptr, 0); + unsigned int shl =3D 0; =20 + /* Consume valid suffix even in case of overflow. */ switch (*endptr) { case 'E': case 'e': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'P': case 'p': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'T': case 't': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'G': case 'g': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'M': case 'm': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'K': case 'k': - ret <<=3D 10; - endptr++; + shl +=3D 10; fallthrough; default: break; } =20 + if (shl && likely(ptr !=3D endptr)) { + /* Have valid suffix with preceding number. */ + if (unlikely(check_shl_overflow(ret, shl, &ret))) + ret =3D ULLONG_MAX; + endptr++; + } + if (retptr) *retptr =3D endptr; =20 --=20 2.53.0 From nobody Thu Apr 2 01:49:46 2026 Received: from forward102b.mail.yandex.net (forward102b.mail.yandex.net [178.154.239.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D48A35D5F2; Thu, 12 Feb 2026 16:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; cv=none; b=i/QCYqlXOtvvmgsXLD18sxHFrV1idReR2Kp7jLxDTn644h0+d0tPsjccjiRwRY5CumUPpVjYwKWHFg+XHMEa42vLfd7ea3fdNGZMjLO3D054kSr9CMntBpO057IjiJqlVDnKTMArjK8WyBeKBAt5UFcPTEEmoOeRtFqcg+buY2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; c=relaxed/simple; bh=b25GLa6Nxa0JkVVRcxgvW+qahIyegLcJ0z46wPRIPQ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tzuk6s5vmHTR/otesSsRM6MO1kLcdbQ0S57ICZDQa5XEuApcn84kmr393ejzS6f8NGxCJCPi6kaXJ8l0Eq99gX0oNdg4g9G6lEG3ky5AYquSM0V5Asshi230fvY+EqVeAS/l1HmHLEPIxCWg4YBnwAO1YhKPUtQylMrs/TKCnp0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=X/474Hx3; arc=none smtp.client-ip=178.154.239.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="X/474Hx3" Received: from mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net [IPv6:2a02:6b8:c1e:3990:0:640:454b:0]) by forward102b.mail.yandex.net (Yandex) with ESMTPS id 2F59EC0080; Thu, 12 Feb 2026 19:44:18 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id EiXcAWCGxeA0-2EWwl2fW; Thu, 12 Feb 2026 19:44:17 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770914657; bh=xpMpHVbNQyEu3bVeX/qstTUz7i5myZeY5ImYtYMRO48=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=X/474Hx3OHnAEVMwY17g2QOQ83VAoMZLKIZKWwmH6sl/+KNmOiYuCjwOFEhlshcWB pd0EXRnZK+q6mUQGiR66tm2Cmb3WkTZj9txPjGsIvu/H33OjDZ2Z/tjo1EXKJFQQuj gTSEN+IIQTSTLgIF+c4pZvimlE4AFJ5wjDL3ikoI= Authentication-Results: mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: David Laight , Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v8 3/5] lib: add more string to 64-bit integer conversion overflow tests Date: Thu, 12 Feb 2026 19:44:11 +0300 Message-ID: <20260212164413.889625-4-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212164413.889625-1-dmantipov@yandex.ru> References: <20260212164413.889625-1-dmantipov@yandex.ru> 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" Add a few more string to 64-bit integer conversion tests to check whether 'kstrtoull()', 'kstrtoll()', 'kstrtou64()' and 'kstrtos64()' can handle overflows reported by '_parse_integer_limit()'. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- v5 and upwards: bump version to match the series v4: initial version to join the series --- lib/test-kstrtox.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c index ee87fef66cb5..811128d0df16 100644 --- a/lib/test-kstrtox.c +++ b/lib/test-kstrtox.c @@ -198,6 +198,7 @@ static void __init test_kstrtoull_fail(void) {"10000000000000000000000000000000000000000000000000000000000000000", 2}, {"2000000000000000000000", 8}, {"18446744073709551616", 10}, + {"569202370375329612767", 10}, {"10000000000000000", 16}, /* negative */ {"-0", 0}, @@ -275,9 +276,11 @@ static void __init test_kstrtoll_fail(void) {"9223372036854775809", 10}, {"18446744073709551614", 10}, {"18446744073709551615", 10}, + {"569202370375329612767", 10}, {"-9223372036854775809", 10}, {"-18446744073709551614", 10}, {"-18446744073709551615", 10}, + {"-569202370375329612767", 10}, /* sign is first character if any */ {"-+1", 0}, {"-+1", 8}, @@ -334,6 +337,7 @@ static void __init test_kstrtou64_fail(void) {"-1", 10}, {"18446744073709551616", 10}, {"18446744073709551617", 10}, + {"569202370375329612767", 10}, }; TEST_FAIL(kstrtou64, u64, "%llu", test_u64_fail); } @@ -386,6 +390,8 @@ static void __init test_kstrtos64_fail(void) {"18446744073709551615", 10}, {"18446744073709551616", 10}, {"18446744073709551617", 10}, + {"569202370375329612767", 10}, + {"-569202370375329612767", 10}, }; TEST_FAIL(kstrtos64, s64, "%lld", test_s64_fail); } --=20 2.53.0 From nobody Thu Apr 2 01:49:46 2026 Received: from forward102b.mail.yandex.net (forward102b.mail.yandex.net [178.154.239.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D51135D5F6; Thu, 12 Feb 2026 16:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; cv=none; b=riGIr3tQQcs8aNbjA8hD5LgAfhAWyhxr0NHa65pGkHEBODkE63rCFSZ7k/WECQe4Wahw6QECg4sAoQl7nx2tuVd60XHUqS6kNgLXi4yvtUav5pg1qUedGuhVlVLLTvi57T0zcD5faoW39dGZv6DFC3t9aSXu0fzeyFDfiqGZfms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914662; c=relaxed/simple; bh=dC5IQjg7bcOQhlmLMknzcy3NvAHdhJtqPR4YtAD/p8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YzGX4J4/XO6U4X48p0qN/smrBcwLJN+OYpdIWYvNVD/X9x4VQC0xuHZH54GYpzLAOwaPiiYGLvxeb/zwp7Lj6cFCc33RwNLQwX22cT7Pkc0aT0kYZVZGP801AykbDsqgiIo7sy6LmJdFRSSMq28BalEU1zOa7d/U3s2IFjJVNug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=i0YZgv3d; arc=none smtp.client-ip=178.154.239.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="i0YZgv3d" Received: from mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net [IPv6:2a02:6b8:c1e:3990:0:640:454b:0]) by forward102b.mail.yandex.net (Yandex) with ESMTPS id C36D0C007E; Thu, 12 Feb 2026 19:44:18 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id EiXcAWCGxeA0-nj3Xj5Zf; Thu, 12 Feb 2026 19:44:18 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770914658; bh=7ca1fZMmWTMdlSKBrBQjmsvVq/wZ571jbt66Zhf0g7M=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=i0YZgv3dA9D5IIJUO4gkuJJly4E3lBej+6m+tBhOd1a5i3fj5Wu7eHArwtshwjvIt rxOmPeP5VqO4hu+fA1TD3giFiQIFt61iHNOFG+RnfKXr/Q8MxRSy3cXwJUuOzcy3xS dLiIa1CglizXrLmiB99Hd4aEt/Y/aVYlrbs4NcxE= Authentication-Results: mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: David Laight , Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v8 4/5] lib/cmdline_kunit: add test case for memparse() Date: Thu, 12 Feb 2026 19:44:12 +0300 Message-ID: <20260212164413.889625-5-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212164413.889625-1-dmantipov@yandex.ru> References: <20260212164413.889625-1-dmantipov@yandex.ru> 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" Better late than never, now there is a long-awaited basic test for 'memparse()' which is provided by cmdline.c. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- v7 and upwards: bump version to match the series v6: tests to check whether valid-suffix-only string is handled as unrecogni= zed v5: even more tests to trigger overflow with size suffix v4: move actual overflow tests to test-kstrtox.c v3: adjust style as suggested by Andy v2: few more test cases to trigger overflows --- lib/tests/cmdline_kunit.c | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lib/tests/cmdline_kunit.c b/lib/tests/cmdline_kunit.c index c1602f797637..18b19c85baef 100644 --- a/lib/tests/cmdline_kunit.c +++ b/lib/tests/cmdline_kunit.c @@ -6,6 +6,7 @@ #include #include #include +#include #include =20 static const char *cmdline_test_strings[] =3D { @@ -139,11 +140,66 @@ static void cmdline_test_range(struct kunit *test) } while (++i < ARRAY_SIZE(cmdline_test_range_strings)); } =20 +struct cmdline_test_memparse_entry { + const char *input; + const char *unrecognized; + unsigned long long result; +}; + +static const struct cmdline_test_memparse_entry testdata[] =3D { + { "0", "", 0ULL }, + { "1", "", 1ULL }, + { "a", "a", 0ULL }, + { "k", "k", 0ULL }, + { "E", "E", 0ULL }, + { "0xb", "", 11ULL }, + { "0xz", "x", 0ULL }, + { "1234", "", 1234ULL }, + { "04567", "", 2423ULL }, + { "0x9876", "", 39030LL }, + { "05678", "8", 375ULL }, + { "0xabcdefz", "z", 11259375ULL }, + { "0cdba", "c", 0ULL }, + { "4K", "", SZ_4K }, + { "0x10k@0xaaaabbbb", "@", SZ_16K }, + { "32M", "", SZ_32M }, + { "067m:foo", ":", 55 * SZ_1M }, + { "2G;bar=3Dbaz", ";", SZ_2G }, + { "07gz", "z", 7ULL * SZ_1G }, + { "3T+data", "+", 3 * SZ_1T }, + { "04t,ro", ",", SZ_4T }, + { "012p", "", 11258999068426240ULL }, + { "7P,sync", ",", 7881299347898368ULL }, + { "0x2e", "", 46ULL }, + { "2E and more", " ", 2305843009213693952ULL }, + { "18446744073709551615", "", ULLONG_MAX }, + { "0xffffffffffffffff0", "", ULLONG_MAX }, + { "1111111111111111111T", "", ULLONG_MAX }, + { "222222222222222222222G", "", ULLONG_MAX }, + { "3333333333333333333333M", "", ULLONG_MAX }, +}; + +static void cmdline_test_memparse(struct kunit *test) +{ + const struct cmdline_test_memparse_entry *e; + unsigned long long ret; + char *retptr; + + for (e =3D testdata; e < testdata + ARRAY_SIZE(testdata); e++) { + ret =3D memparse(e->input, &retptr); + KUNIT_EXPECT_EQ_MSG(test, ret, e->result, + " when parsing '%s'", e->input); + KUNIT_EXPECT_EQ_MSG(test, *retptr, *e->unrecognized, + " when parsing '%s'", e->input); + } +} + static struct kunit_case cmdline_test_cases[] =3D { KUNIT_CASE(cmdline_test_noint), KUNIT_CASE(cmdline_test_lead_int), KUNIT_CASE(cmdline_test_tail_int), KUNIT_CASE(cmdline_test_range), + KUNIT_CASE(cmdline_test_memparse), {} }; =20 --=20 2.53.0 From nobody Thu Apr 2 01:49:46 2026 Received: from forward101b.mail.yandex.net (forward101b.mail.yandex.net [178.154.239.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0C0235D5FC; Thu, 12 Feb 2026 16:44:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914663; cv=none; b=utVbJ9QPpv/nZjfeOwu5Ky1/EyJwVhb7JKFY73zDw05o2/q40ggZwdym/oS+0uWeQ7dw7jUaGtXQkD/5M+PNutRIiwjAUffZrToeLDR4C4M38Sq5u0EaGLA5Ja3UgaSS41nF8nzLjs3LEuU0XeY1NgVqBn5aOZVnDvveBDYfASo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770914663; c=relaxed/simple; bh=x7zQCTK9E9zvarWdz56OYkmXuR+sj+nJBAl9IBPWsk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k4pD4UAkLr4/uEDob5br+K9B/XjxK7fbV+Tnk2umpTRjqkbgi6RGIqJYsaLDkHm/XOyqEtCBxggit4KO8CL2qN++FlSi+SCox5BAYMQLgiVbV74pTCLaV4aPHxWCj5cKiq/hHXSMMLRhSVh1+y8jaUQ65knx23BR4sm6Gv6UfFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=DN95QyO9; arc=none smtp.client-ip=178.154.239.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="DN95QyO9" Received: from mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net [IPv6:2a02:6b8:c1e:3990:0:640:454b:0]) by forward101b.mail.yandex.net (Yandex) with ESMTPS id 80786C0081; Thu, 12 Feb 2026 19:44:19 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id EiXcAWCGxeA0-n2xGa5QO; Thu, 12 Feb 2026 19:44:19 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770914659; bh=gA72Ls5eRaGrKkWfOZiySyHNm4v/PKnrrPEn/q+BU34=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=DN95QyO9YHAQTuBg4/0+TCm+fJiJPLwvQE93B2WchC7cLqk+jCl3g8tmq1bOeR/AP 2pEBYMPKMF7/IXQsgeLLKk3oN9cH3/7mhtDd2Voq8l+qpsCi8xB4J6dnaTnuP2tVAC tj3Qr/b+kXnE7KdqAQ4aqhIkJNLaG13RYicWzQUA= Authentication-Results: mail-nwsmtp-smtp-production-main-91.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: David Laight , Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v8 5/5] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Date: Thu, 12 Feb 2026 19:44:13 +0300 Message-ID: <20260212164413.889625-6-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212164413.889625-1-dmantipov@yandex.ru> References: <20260212164413.889625-1-dmantipov@yandex.ru> 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" Fix 'get_option()', 'memparse()' and 'parse_option_str()' comments to match the commonly used style as suggested by kernel-doc -Wreturn. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- v2 and upwards: bump version to match the series --- lib/cmdline.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/cmdline.c b/lib/cmdline.c index f6e4b113ca9f..16cce6621cec 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -43,7 +43,7 @@ static int get_range(char **str, int *pint, int n) * When @pint is NULL the function can be used as a validator of * the current option in the string. * - * Return values: + * Return: * 0 - no int in string * 1 - int found, no subsequent comma * 2 - int found including a subsequent comma @@ -145,6 +145,9 @@ EXPORT_SYMBOL(get_options); * * Parses a string into a number. The number stored at @ptr is * potentially suffixed with K, M, G, T, P, E. + * + * Return: The value as recognized by simple_strtoull() multiplied + * by the value as specified by suffix, if any. */ =20 unsigned long long memparse(const char *ptr, char **retptr) @@ -205,7 +208,7 @@ EXPORT_SYMBOL(memparse); * This function parses a string containing a comma-separated list of * strings like a=3Db,c. * - * Return true if there's such option in the string, or return false. + * Return: True if there's such option in the string or false otherwise. */ bool parse_option_str(const char *str, const char *option) { --=20 2.53.0