From nobody Thu Apr 2 18:49:38 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 9EAEA358D3D; Thu, 12 Feb 2026 12:56:34 +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=1770900997; cv=none; b=rkzNOfwrekhHO+lPkBhLfTZ7qtEvkGsKyB+ZUGpCjAVei4Tbrl1yWqui7MUtB+Qyfh7UOlj/JRe5yWlAWLbKL1xYcZgrVutwyoQoILuJ2not9RKK2YjPMV0J0uBkAvoGd2oND6crYg6SWycRQmElCq4OQf9GjPpnwGnaUOPuvrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770900997; c=relaxed/simple; bh=i/YL/mVWy5lRqFCtJyTP3sW4sKYd/0MXpGazdSmbaiM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cQASFb9FS1ht4uPC663Y/LLnqoreMBJbH4FX65bxMQEsftQ3EBzrKEB15dbMWTgAf3qWUM9jBwDMP3NXTL1pNQAoG21s1Reocae4S4aCSABBpPNPu/GFEK8SWLUysbJLyxPSbVeGDI3+a7GUU50A0Ps7JBbMS4D545ex9+yTEr4= 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=ECUY/HPy; 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="ECUY/HPy" Received: from mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net [IPv6:2a02:6b8:c11:e97:0:640:f294:0]) by forward101b.mail.yandex.net (Yandex) with ESMTPS id 56E5CC00EB; Thu, 12 Feb 2026 15:56:33 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id VuTjuXAGI4Y0-kvDfMToo; Thu, 12 Feb 2026 15:56:32 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770900992; bh=0fKN4Y+k4d+LxcuJxWobJuwlWBYAEFn705l1ytjnVDA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ECUY/HPyZDDz8wkqKe0K0rGac6h/3ejHX8cMbj7zFn5tnxxI+H8QMjaTIyBzeAR2I s3dCmCutdh4DXMGYzuoEsyjp0EdeA2Oc9SG+vzUHh6jckpaV2ppeq2XNWJan4sm6RI RXge1dE5InoKJep3fm6KFfhudemK8V1nACpPidnQ= Authentication-Results: mail-nwsmtp-smtp-production-main-70.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 v7 1/5] lib: fix _parse_integer_limit() to handle overflow Date: Thu, 12 Feb 2026 15:56:24 +0300 Message-ID: <20260212125628.739276-2-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212125628.739276-1-dmantipov@yandex.ru> References: <20260212125628.739276-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 --- 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 | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/kstrtox.c b/lib/kstrtox.c index bdde40cd69d7..ffcf0219b1f1 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -39,14 +39,20 @@ 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, @@ -56,8 +62,7 @@ unsigned int _parse_integer_limit(const char *s, unsigned= int base, unsigned lon unsigned int rv; =20 res =3D 0; - rv =3D 0; - while (max_chars--) { + for (rv =3D 0; max_chars--; rv++, s++) { unsigned int c =3D *s; unsigned int lc =3D _tolower(c); unsigned int val; @@ -76,12 +81,16 @@ 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)) + unsigned long long tmp; + + if (check_mul_overflow(res, base, &tmp) || + check_add_overflow(tmp, val, &res)) { + res =3D ULLONG_MAX; rv |=3D KSTRTOX_OVERFLOW; + } + } else { + res =3D res * base + val; } - res =3D res * base + val; - rv++; - s++; } *p =3D res; return rv; --=20 2.53.0 From nobody Thu Apr 2 18:49:38 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 063D035C1AD; Thu, 12 Feb 2026 12:56:41 +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=1770901004; cv=none; b=uwOBmjEl0+/STPk7Xp7lK+Ni/eEPfGj7HrLj+I+07VN6dPULSB0AAWVGCgDeRBZHrrHYefllUMO6syjD7jeg613D0f2LZ3vvZI32bXD0linUSkk7UwqSTrKUZ9NScjeWK8VJmkWFJmWBOqG6OcrS7xOu6t7iVlsBZfCakHYmbp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770901004; c=relaxed/simple; bh=mnKuLEH8BfjkEMBC9cWgyEAo0Be6SXc3cyw+vkboY2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j7UMkzr4BQ4xR6GM5CbSjJ27i1zusA/HUbQqavBds1pGyxheq+EQqXAdY4zXrf0IIA2afBe6iYrYOOuJk+c8DFdtqwE4+e070q0RalHbvqZyLrLfnG3JKwz/l5hSBtLwrn0NFxzGueQJK/QeJnmcEkaMuXmhuG8TNJtha3abAB0= 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=Nqi6viXC; 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="Nqi6viXC" Received: from mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net [IPv6:2a02:6b8:c11:e97:0:640:f294:0]) by forward102b.mail.yandex.net (Yandex) with ESMTPS id 2FFF2C0102; Thu, 12 Feb 2026 15:56:34 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id VuTjuXAGI4Y0-yXnszrB9; Thu, 12 Feb 2026 15:56:33 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770900993; bh=bUSYSYWj4dObYpG0McIjHrOKuumKhZrreSa3eiSsy1k=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Nqi6viXC11Fa2rMq15n8chAksHUfXjGoSFL0T3C2NBu+Wpn0RzHmQAiFqikWz2ojm 8KkmqPXPY/1qOedErE5KL6rR9OT6YlyJwZULQq4zjSt/AiedNTRovSOE87KjXGkjhm +XsW9wlnoFeT9NJeyOaKyjRvIwiMUlBz+fim906g= Authentication-Results: mail-nwsmtp-smtp-production-main-70.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 v7 2/5] lib: fix memparse() to handle overflow Date: Thu, 12 Feb 2026 15:56:25 +0300 Message-ID: <20260212125628.739276-3-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212125628.739276-1-dmantipov@yandex.ru> References: <20260212125628.739276-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. Signed-off-by: Dmitry Antipov Reviewed-by: Andy Shevchenko --- 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 | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/cmdline.c b/lib/cmdline.c index 90ed997d9570..32da6f5a9cdb 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -150,39 +150,50 @@ 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. */ + unsigned long long val; + + if (unlikely(check_shl_overflow(ret, shl, &val))) + ret =3D ULLONG_MAX; + else + ret =3D val; + endptr++; + } + if (retptr) *retptr =3D endptr; =20 --=20 2.53.0 From nobody Thu Apr 2 18:49:38 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 CD1A535B63A; Thu, 12 Feb 2026 12:56:36 +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=1770901002; cv=none; b=F5P0nQovWcCYkDzwu0udSL4f3TW/u3aUq/AULxON6Y/NuUOR2wOkgN4p9KUD5dNtr7MtKkTdO/bP1eVlgrrqcCcguRBUa1m89VRqkfdx1q7KW2cBgFRnO5mJeUWowsCplOJg8/TxmVUB5S/bXUbFCNMoEgof4a8mI5gTXwKg/pY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770901002; c=relaxed/simple; bh=b25GLa6Nxa0JkVVRcxgvW+qahIyegLcJ0z46wPRIPQ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PHEL1dsTTM9TrVwf3NA5uY2viDKBH7ipLUga5dqLsdDEWu2meS4sVx+cSVZvDY7T2LaBe2Au8Ms8VjxqHdMXTIDOF4fC1MRUoxFhBhpvjgyyrJUZlwQNpmFkjtfWPRI8mB/TMPCH+6AzjGfK7Q9s+5SE7xRAE4u9bDwABvXhkTQ= 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=eYIxE/+s; 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="eYIxE/+s" Received: from mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net [IPv6:2a02:6b8:c11:e97:0:640:f294:0]) by forward100b.mail.yandex.net (Yandex) with ESMTPS id DDF4B8077D; Thu, 12 Feb 2026 15:56:34 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id VuTjuXAGI4Y0-tsl2dBmf; Thu, 12 Feb 2026 15:56:34 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770900994; bh=xpMpHVbNQyEu3bVeX/qstTUz7i5myZeY5ImYtYMRO48=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=eYIxE/+sOTeagoc6/8ZKuR0TEL1FfbVuznpcy51BBtFN4zb9I1027ofIlozh30GX6 /ozi3TTjeR3lIRbVWwAm/9ulhF8oMfIUapK+FhXMGbf0kES8mymkgpLlnbk/goNbAJ dzkesSdkJyVL9B1EelWMr+lTRANZiAc1xb0FGF4g= Authentication-Results: mail-nwsmtp-smtp-production-main-70.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 v7 3/5] lib: add more string to 64-bit integer conversion overflow tests Date: Thu, 12 Feb 2026 15:56:26 +0300 Message-ID: <20260212125628.739276-4-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212125628.739276-1-dmantipov@yandex.ru> References: <20260212125628.739276-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 18:49:38 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 4F44E35B655; Thu, 12 Feb 2026 12:56:37 +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=1770901001; cv=none; b=cpFGAm7s9rqNaPWA58x+nRfqIeIiey3e6CNccnhdp3A1A/IzOQWLZQIB+lPq19GvLPRFc8Wv4z4/CPgFdcx3EQ+yD+MCVsZpGbd2oOkBZxVbXkjTRhK7OljEjv+t18A3ovYo5BsOsWtZiO991R3m7DYMIHJt0Deobc6a6bPKSSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770901001; c=relaxed/simple; bh=M1udxukAKPHkKctZfq03hH8MGDUSjM68iWyCiMjwjbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r/xmWzey2F10JPmV8pQBmf8Vo6GDLoFpkFoL4sbzaRWbeAVgiICsYtShqB7BQExMMs56KcANKS2F6ZODPU1NVop8Sz0mpYsrgkfTnoA5l1U1h0REkOZNcC1FrPKjYDE1BZITvOShjPTsVRThTdklY6r2z7XJKkZIK16xTGQDVHg= 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=LhZ/HSVD; 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="LhZ/HSVD" Received: from mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net [IPv6:2a02:6b8:c11:e97:0:640:f294:0]) by forward103b.mail.yandex.net (Yandex) with ESMTPS id 6BD0AC00A8; Thu, 12 Feb 2026 15:56:35 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id VuTjuXAGI4Y0-y5bNEuxR; Thu, 12 Feb 2026 15:56:35 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770900995; bh=lOs1dtgJo7dhBLMFMWgAMYw2e/gOBuP6UjCe58SSDTQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=LhZ/HSVDtzCwo5gI1DjUtRH14XeeLLrfFH222GcrGRDRkp9FNfRCLJQSymVGrkNzx B3rd6UwpKKCw+86b0j+okkrZaX8H9hYMtEo0V6jqk5LLGUU6kvEaaMysRvTnqNFDqo 8kKwnZ+yehzM9I1Buw4vtTXNiiJ/+23sEpvXolTo= Authentication-Results: mail-nwsmtp-smtp-production-main-70.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 v7 4/5] lib/cmdline_kunit: add test case for memparse() Date: Thu, 12 Feb 2026 15:56:27 +0300 Message-ID: <20260212125628.739276-5-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212125628.739276-1-dmantipov@yandex.ru> References: <20260212125628.739276-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: 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 18:49:38 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 B74C735BDB2; Thu, 12 Feb 2026 12:56:37 +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=1770901001; cv=none; b=M5jL5Rt/TUD8dDqZMChaNSvU1mFRHNdqf7cWgCo41mx/h28jnboZGEZ+9reHpJWuxy7y7dsKzRX9jExgxj+1s4KvkgcKsbCtdYjLf81b1KNv6d5rz12Hfjo1Lmv+0vt647fN5TPTYZlGMS3t6WD9Ub7fxtOvZDSdicNZZ+D0A8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770901001; c=relaxed/simple; bh=3yabApihiYJ68XRFacLC8Yylt3n+P7wvNETpIrfho8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NbMx42R8lO1hzovcrPWBaMYYfBH4ojXtGeHApPoRXrKLbiXS/oTvOr3oyK5mY8VB6Y572Y1PP0dS/Z9gsi8O+m3DQIqK8Lc5S8XLajZWrRLxXoJTi0DALYufqPqCYcfcoh4pmCgjjAHbr9C1ei3ndfHBg+QkhioRJIdeW0/23LQ= 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=RT2A+E/R; 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="RT2A+E/R" Received: from mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net [IPv6:2a02:6b8:c11:e97:0:640:f294:0]) by forward101b.mail.yandex.net (Yandex) with ESMTPS id 4678FC0082; Thu, 12 Feb 2026 15:56:36 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-70.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id VuTjuXAGI4Y0-wTpp4CyV; Thu, 12 Feb 2026 15:56:35 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770900995; bh=lQkD1HjdqbKWVKea36s5LLC68RWQLUMntkSSahrra38=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=RT2A+E/R0b7seaIGh3uW3lF4n6gFfNeZJPI1SDdPFiQAh7wKgvZfkUgX2MfSGDGGo jIHC+qkqkq7ZD7lRIZYkN62/6OIZQ9NSlT9WPfHIzQh1Ia9qIq6C8OvsW86Z3gVOk0 GNL5kRdlkDeEOw8mbY5jM6B82Ut9KsPsIxiYKaZg= Authentication-Results: mail-nwsmtp-smtp-production-main-70.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 v7 5/5] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Date: Thu, 12 Feb 2026 15:56:28 +0300 Message-ID: <20260212125628.739276-6-dmantipov@yandex.ru> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260212125628.739276-1-dmantipov@yandex.ru> References: <20260212125628.739276-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 32da6f5a9cdb..357798b79682 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) @@ -209,7 +212,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