From nobody Mon Feb 9 12:10:52 2026 Received: from forward202d.mail.yandex.net (forward202d.mail.yandex.net [178.154.239.219]) (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 85AF640F8CB; Wed, 4 Feb 2026 14:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213999; cv=none; b=HAnFfS2QDmjAMErCU2qSZZCYnGu9ph1Qo0z0y4ZWAoh902DpDwKXSB5d1TKrWQdnhXwkuHTz5A7dnXUInwdAlXPmV2pXe8Jj5XiM5dJgbOUEsOqEQf6mYrzTHkDllYaCTFrQRLbcHXTEgvl007Fbl1iucKFqr8x9jOX8/7Yezew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213999; c=relaxed/simple; bh=R6zs33WQ84en5tjPbrzZIwDWnySjLcVt8dD8Qw8zUtU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j10WhmCWQUtwmyVcitvmlv7roud/yCFFuT3MyndbnYtraFRwWKTwyBM1VGXZ7udXUNlARnJPj6amUxeim3QVysmz+rtPzVGKaYEFHwqbkKXEjrk99igt4yY2TBi2gWW9IL/5cXf7R81Zmo/bpks0u5UO0GrPXPtBj8NHEZCCRzs= 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=lCKgjJkV; arc=none smtp.client-ip=178.154.239.219 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="lCKgjJkV" Received: from forward102d.mail.yandex.net (forward102d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d102]) by forward202d.mail.yandex.net (Yandex) with ESMTPS id C195D89519; Wed, 04 Feb 2026 16:59:54 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:4f41:0:640:844:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id 9959CC011C; Wed, 04 Feb 2026 16:59:47 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id ixp7xlOGqOs0-v5X2gJ0i; Wed, 04 Feb 2026 16:59:47 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770213587; bh=j6IFUnJfkIk8paM3WA6aApufvLav+nbFsQN6ZWDlQt4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=lCKgjJkV2EMzWF0saEaLaDFYzs0Xpn5uDMn5rXjQILCyzWccI9ezNzJ0ySOG4X0SH is3ce3Epc2qlQ2IeHwPLYccaVsh9d/8tnoB+S07amL1O/BPd8Izrs/KtPg92wXXFOt 5e62pX78nKTjPAhH4zg9fSePnRPYb401G3kyzY04= Authentication-Results: mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v5 1/5] lib: fix _parse_integer_limit() to handle overflow Date: Wed, 4 Feb 2026 16:57:13 +0300 Message-ID: <20260204135717.941256-2-dmantipov@yandex.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260204135717.941256-1-dmantipov@yandex.ru> References: <20260204135717.941256-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 --- 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 | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/kstrtox.c b/lib/kstrtox.c index bdde40cd69d7..8691f85cf2ce 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -39,20 +39,26 @@ 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 long long res; + unsigned long long tmp, res; unsigned int rv; =20 res =3D 0; @@ -72,14 +78,21 @@ unsigned int _parse_integer_limit(const char *s, unsign= ed int base, unsigned lon if (val >=3D base) break; /* - * Check for overflow only if we are within range of - * it in the max base we support (16) + * Accumulate result if no overflow detected. + * Otherwise just consume valid characters. */ - if (unlikely(res & (~0ull << 60))) { - if (res > div_u64(ULLONG_MAX - val, base)) - rv |=3D KSTRTOX_OVERFLOW; + if (likely(res !=3D ULLONG_MAX)) { + if (unlikely(res & (~0ull << 60))) { + /* We're close to possible overflow. */ + 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++; } --=20 2.52.0 From nobody Mon Feb 9 12:10:52 2026 Received: from forward205d.mail.yandex.net (forward205d.mail.yandex.net [178.154.239.216]) (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 C42A132571B; Wed, 4 Feb 2026 14:07:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770214035; cv=none; b=cTy/L51tZhLaVVDAjrejyBdatkTiXfkCKn9LCH/2Rh0+FbtKJjrCnkv5TS7fMcCvCbTB5P3hzcrt4BaJQyxfEwdBy8hdhX7Bv5sd6FQ8N0WyMAdO8jenGqwUgQoymH8uF+wrYZlPl8mCY86OcU7LSnkHBaFrbe8+wuN49RbjQuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770214035; c=relaxed/simple; bh=0HlBZQsfQqCnVJ+Cj9jTFVxH6hjqTnQaD1skX60UBKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jfEhjxHMNNkcsl2UOfCJ/Qc62SS0HjylhqxGiSd2reMBmfV+leFavc/hIt0GIU5/Nff4qGKERVMePR+d+fffvhQNTBwIKXJbl2VbBJrNjxP4HPTBlyMAaBR0S+42fI0TuvK+86yF967QzeocdaWsZiaZPz7uLH8F7bAUn4erWOg= 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=LE8BuIZe; arc=none smtp.client-ip=178.154.239.216 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="LE8BuIZe" Received: from forward102d.mail.yandex.net (forward102d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d102]) by forward205d.mail.yandex.net (Yandex) with ESMTPS id C222B88A9A; Wed, 04 Feb 2026 16:59:55 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:4f41:0:640:844:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id 12B12C0104; Wed, 04 Feb 2026 16:59:48 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id ixp7xlOGqOs0-fnDqrqmw; Wed, 04 Feb 2026 16:59:47 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770213587; bh=Ph9nlSIHnFc8uYBX8avqimT9s/mmxhrA1L+zGGONLyI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=LE8BuIZeqS7tyHiQ8MTXhfPRvP9e1fGkjYbge/x4i2viaxLx4heR0+vfW3SysWsIh hxrWZtJg3fBm9iBZiLsWpVvwZGv4/LOrwV8Ogj7n59t0FWHD1gOazrccfCVQre+qA9 u62u76pPut0u56NIFKKpckbTTLIiLd4KFE4pP0Dw= Authentication-Results: mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v5 2/5] lib: fix memparse() to handle overflow Date: Wed, 4 Feb 2026 16:57:14 +0300 Message-ID: <20260204135717.941256-3-dmantipov@yandex.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260204135717.941256-1-dmantipov@yandex.ru> References: <20260204135717.941256-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 --- v5: initial version to join the series --- lib/cmdline.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/cmdline.c b/lib/cmdline.c index 90ed997d9570..e18fdfb80ba5 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -151,38 +151,48 @@ unsigned long long memparse(const char *ptr, char **r= etptr) { char *endptr; /* local pointer to end of parsed string */ =20 + unsigned int shl =3D 0; unsigned long long ret =3D simple_strtoull(ptr, &endptr, 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; + shl +=3D 10; endptr++; fallthrough; default: break; } =20 + /* If no overflow, apply suffix if any. */ + if (likely(ret !=3D ULLONG_MAX) && shl) { + unsigned long long val; + + ret =3D (unlikely(check_shl_overflow(ret, shl, &val)) + ? ULLONG_MAX : val); + } + if (retptr) *retptr =3D endptr; =20 --=20 2.52.0 From nobody Mon Feb 9 12:10:52 2026 Received: from forward103d.mail.yandex.net (forward103d.mail.yandex.net [178.154.239.214]) (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 999933542D4; Wed, 4 Feb 2026 13:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.214 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213598; cv=none; b=hOs1wiQ1lL2xt4d2M/4tumA0iqFcdrL5DDwtHTuo+jXEs4kJfmQL8FpvVN0L3vMMHkhtz2WsYh2id7KuAETPMc0zCNg6L4r7PWuR8M2fhFNmvg1neeT6eFJv8sL2TSAHivMPzmRnoiFlwBTsqBUL/wNW3Km9y9eSfl5chphYn5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213598; c=relaxed/simple; bh=IoWTscMXu90WPT9YAOKC1OM9eFzsxf545fN9v0TAQSg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XQ1zEVioi55YM+axsU63I7qWrA3gXcZfizL77kxhPg4KTrjS7B3QjHMxeli0Nq6ym9Ush0FhlRAh6+t8H/m7WAidr1jgEqIXe49AABL4fDgQlIU8mbeqwrTZOoLOlMW+jJ19NJ4pJ/MZTW35xMGTypG6MKiLaB5Gg2xMBAz/pFU= 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=f62RzuI9; arc=none smtp.client-ip=178.154.239.214 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="f62RzuI9" Received: from mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:4f41:0:640:844:0]) by forward103d.mail.yandex.net (Yandex) with ESMTPS id BF0DFC0083; Wed, 04 Feb 2026 16:59:48 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id ixp7xlOGqOs0-mqAHaCfI; Wed, 04 Feb 2026 16:59:48 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770213588; bh=b4uXku/dWVzrhcn5CJ5kVruyZ0arrfLsiINpqGsUm7c=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=f62RzuI9rDAUwPvJRv22A3FB42UDhKRcnmwyGS0UE1G+d/Xpw3RITV3yO5l/T/73h r7WcywfIyHoahfwx/h9Gn0fICz23F7Suf6SHNg+ijrrjYNsmZmZAO6R1kTDTSqdUbC KDq+Yu4t/SxfiFg3sMmKodESVL/sK8LD4k5GPjLc= Authentication-Results: mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v5 3/5] lib: add more string to 64-bit integer conversion overflow tests Date: Wed, 4 Feb 2026 16:57:15 +0300 Message-ID: <20260204135717.941256-4-dmantipov@yandex.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260204135717.941256-1-dmantipov@yandex.ru> References: <20260204135717.941256-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: 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.52.0 From nobody Mon Feb 9 12:10:52 2026 Received: from forward204d.mail.yandex.net (forward204d.mail.yandex.net [178.154.239.217]) (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 8227C3EBF21; Wed, 4 Feb 2026 14:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213960; cv=none; b=fRG6e1XVgCV9vmXY3x/Jg2MIw+UcU3oZvkeVX7V5H8jbPCHqu/itedztyOI7NrTZ4uEgMlcN08RGBZwWkqKqjjKHGXX5pAUXQDmoXduWVvdThZzzLsx/Ba3vg+/DSfHIB6zhCicGV5mARwcB/ndnPrLgq9PRteMLl3VwquiQbWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213960; c=relaxed/simple; bh=xQaf4Qri0q7DR/I1UTEJRzPeJGgvbGaDi+LUdnm6IX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QUHo9/+HtWEH1xK18YWR33LfqzS45qth3S3+Sxz+9pG6t+IseOLu3etEEXzIYDYlxBWO8OIQpkPatb6GOBYci4ZhBOW/MokjOuT/7d1gQeyecl4PP/fOhiFJkAQuDEbO+0Oqei8O+m4xyOqgBeoOioBcxOMdetrKhLBtFL+IwxM= 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=LgM4467J; arc=none smtp.client-ip=178.154.239.217 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="LgM4467J" Received: from forward101d.mail.yandex.net (forward101d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d101]) by forward204d.mail.yandex.net (Yandex) with ESMTPS id AB35C88614; Wed, 04 Feb 2026 16:59:56 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:4f41:0:640:844:0]) by forward101d.mail.yandex.net (Yandex) with ESMTPS id 2D4E9C0066; Wed, 04 Feb 2026 16:59:49 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id ixp7xlOGqOs0-gUToEhGc; Wed, 04 Feb 2026 16:59:49 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770213589; bh=Dv1vjCEmMHfj9beaaBM2B1Eb+EUAtmcm0V59HDOdKlE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=LgM4467JJhHmbDihf9bhhJCVMdkGdCKkKq/eJR4vFPFmdBlVIYHgsRJb52CMQD59D 7UHW9unPvwDf0cgxc2EDrj7iHB/uygoSTK4wwR5VJLMmD+D1BIdgHYZXKttB2PLd5V b5p0z8vCfxXQwq+To1JoCYVk/GJhcGnaxukaQoqo= Authentication-Results: mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v5 4/5] lib/cmdline_kunit: add test case for memparse() Date: Wed, 4 Feb 2026 16:57:16 +0300 Message-ID: <20260204135717.941256-5-dmantipov@yandex.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260204135717.941256-1-dmantipov@yandex.ru> References: <20260204135717.941256-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 --- 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 | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lib/tests/cmdline_kunit.c b/lib/tests/cmdline_kunit.c index c1602f797637..41bf4fecd97e 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,63 @@ 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 }, + { "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 }, + { "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.52.0 From nobody Mon Feb 9 12:10:52 2026 Received: from forward100d.mail.yandex.net (forward100d.mail.yandex.net [178.154.239.211]) (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 A12D940F8C2; Wed, 4 Feb 2026 13:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.211 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213598; cv=none; b=KlrCZNeCngU958TmXaA+ZXscceWGuGPdowZdOOVaqjJ5l8r6/y5eVHRMIJ/woDhMpWrSO3DoX6tVZM4zCMRxZ6aoqmnrId4Q5BElxWzoEC4aZVOEf2f/JpfVSbk6Q6N77VY1ObUV3iJuHGcS0duOI3i4E0yUQ4NssScqdVQ3YQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770213598; c=relaxed/simple; bh=qeYCwCyPFsOM3FUtsZBFHWHlf9wMKyvS2v+X7GWuWJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I/LucQRn2iYK7UZZL3PYvJD3MWYIHXOEGFyILncZbYYtFeWEy5zWRfhbTq2Lx9felOmrtKaSqbg9JlHnyUGCcQv7Og3itwlRC2Bl9kQ+btuVkG1msdnVFQKbt6uZ0lNB8UPixJJKkUfIOBe32Xt+zlQdVJh7+N8tcln0ErSv8DU= 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=lsQtjLD2; arc=none smtp.client-ip=178.154.239.211 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="lsQtjLD2" Received: from mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:4f41:0:640:844:0]) by forward100d.mail.yandex.net (Yandex) with ESMTPS id C64B3C0086; Wed, 04 Feb 2026 16:59:49 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id ixp7xlOGqOs0-gnLf22ma; Wed, 04 Feb 2026 16:59:49 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1770213589; bh=BbpoEEQEsYGNHUUR7D/TJUYhcvpQHUq5n7L8TA6k0Ck=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=lsQtjLD27eqiQMboPaRlvZQWs6bzbfk8d3O/83opFDh/KnZzd9Bz7jAMt4yPCfd9J yi01sGXhmMc7H8KCK+/jLTHTSxPc0r2ugd5DlOzJssShiYJLO/ibLrmaKXHTVLs1qJ cMZ0j2FGaTQoDvEKkUQeZtcGOu9euAcc5pQl9J7k= Authentication-Results: mail-nwsmtp-smtp-production-main-63.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andy Shevchenko , Andrew Morton Cc: Kees Cook , "Darrick J . Wong" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v5 5/5] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Date: Wed, 4 Feb 2026 16:57:17 +0300 Message-ID: <20260204135717.941256-6-dmantipov@yandex.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260204135717.941256-1-dmantipov@yandex.ru> References: <20260204135717.941256-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 --- v5: likewise v4: likewise v3: likewise v2: 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 e18fdfb80ba5..c6f7aa5abe77 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) @@ -208,7 +211,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.52.0