From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C885F2C21E8 for ; Fri, 3 Apr 2026 17:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775236248; cv=none; b=Ek/hf9O8Ir2ZK6Ub2l1j0RyxkJvkXAz9MEyozZYi83aA8yjXI8SFj04xUee8iCZYqUSXpV5I5ZzqojfUwyu5DEFcJtq2BU25iR0ikVNQmxzdSX7RMAnUqumPpDPqXI2XJFcxlQE0WeK4/1btW+jDFQBIpHylxKfvaaOBT3dLJwQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775236248; c=relaxed/simple; bh=Y85FxLxT+VrBijHT+VnsXzVQVV48jInGpXIXX1yr2Qs=; h=Date:To:From:Subject:Message-Id; b=A5WEalSr9gwEOVZo2ZskRxV2jRfrLT+jMVJHyWX4b4yMLg4TRtU7Y/QhF1T+tHR+pCsMStDZqFc1oPAsKUGCO42qIaWQlFajULMoSz6Q/CoXl21+RbuDwdTAz9U2QK7QK/KO7jQEOa+toyJFNWrHzqvmRQStG5GthUb3GwqsHHs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=GxWgNZXb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="GxWgNZXb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DF19C4CEF7; Fri, 3 Apr 2026 17:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1775236248; bh=Y85FxLxT+VrBijHT+VnsXzVQVV48jInGpXIXX1yr2Qs=; h=Date:To:From:Subject:From; b=GxWgNZXb5XVIZysi/K/2fWqVmsTMGY5hc6AtM9gCJuCH7ZiIuEx71uoPPuHo89esi Mk1F7pBJuTEbiPJWwNZ5mpH0Ej4nGTg0w2ZlWauex6qqKUO0TOpNMdFEa9z4/gwnjZ dq6ENrOFRvjuG7JuoQJNPavTF/WyuphaZ32HLtaI= Date: Fri, 03 Apr 2026 10:10:47 -0700 To: mm-commits@vger.kernel.org,dmantipov@yandex.ru,akpm@linux-foundation.org From: Andrew Morton Subject: + lib-fix-memparse-to-handle-overflow.patch added to mm-nonmm-unstable branch Message-Id: <20260403171048.4DF19C4CEF7@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: lib: fix memparse() to handle overflow has been added to the -mm mm-nonmm-unstable branch. Its filename is lib-fix-memparse-to-handle-overflow.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-fix-memparse-to-handle-overflow.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Dmitry Antipov Subject: lib: fix memparse() to handle overflow Date: Fri, 3 Apr 2026 13:33:34 +0300 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. Link: https://lkml.kernel.org/r/20260403103338.1122415-3-dmantipov@yandex.ru Signed-off-by: Dmitry Antipov Reviewed-by: Andy Shevchenko Cc: Albert Ou Cc: Alexandre Ghiti Cc: Ard Biesheuvel Cc: "Darrick J. Wong" Cc: Kees Cook Cc: Nathan Chancellor Cc: Palmer Dabbelt Cc: Paul Walmsley Signed-off-by: Andrew Morton --- lib/cmdline.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) --- a/lib/cmdline.c~lib-fix-memparse-to-handle-overflow +++ a/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 = simple_strtoull(ptr, &endptr, 0); + unsigned int shl = 0; + /* Consume valid suffix even in case of overflow. */ switch (*endptr) { case 'E': case 'e': - ret <<= 10; + shl += 10; fallthrough; case 'P': case 'p': - ret <<= 10; + shl += 10; fallthrough; case 'T': case 't': - ret <<= 10; + shl += 10; fallthrough; case 'G': case 'g': - ret <<= 10; + shl += 10; fallthrough; case 'M': case 'm': - ret <<= 10; + shl += 10; fallthrough; case 'K': case 'k': - ret <<= 10; - endptr++; + shl += 10; fallthrough; default: break; } + if (shl && likely(ptr != endptr)) { + /* Have valid suffix with preceding number. */ + if (unlikely(check_shl_overflow(ret, shl, &ret))) + ret = ULLONG_MAX; + endptr++; + } + if (retptr) *retptr = endptr; _ Patches currently in -mm which might be from dmantipov@yandex.ru are lib-fix-_parse_integer_limit-to-handle-overflow.patch lib-fix-memparse-to-handle-overflow.patch lib-add-more-string-to-64-bit-integer-conversion-overflow-tests.patch lib-cmdline_kunit-add-test-case-for-memparse.patch lib-cmdline-adjust-a-few-comments-to-fix-kernel-doc-wreturn-warnings.patch riscv-export-symbols-needed-for-riscv32-efi-stub.patch