From nobody Thu Apr 2 03:22:29 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