Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795047453; b=ZIpBYTqKiq9r0VxIjTTUj9USCEFxugP5iyVqw7wseHA0nzoMqXLWmiB0YAcPJYdBi8A0 57+cMq/plC80p3/z0DN5wsidKTu7Emdfp+Lnu+1m4XT4HHBCAtRNe8O+lUcEyirXI7SnN tINQA2tMPyQd9QDU5pSPCrFD0eSwKvLvyUO9pGbYM40AvWhoEZgsRUNlLp28BlP08N2dA tY5JlH13bfYCzqM/GOZYJMRBeL2kgvQh1prjQ6pUXHYwh5h3DWmmb4E/poNjQJOnBzkk/ Pgj4HbdlB5uirDeB/I0ioGGXKOidvenk2tSUUMXI3+gTTa+wbe/tT/KfBSaBeL4nM2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795047453; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=jt4BxDmGSiWjB5h0lHq1a5hEe4lKV7gPuwvl+konzl0=; b=lmfjM/67tytMvwV290sjgSzZoBJ9XUbZwnGgeScWhmJ/ZfI7DdgzppgHOuiPtArhSMs5 2vrYpjExxAbFJ63rzL/g3Gih4/px8Sy9hQTlUISX7vyCaThnDKVcL0RMAJfKEsCjcn7xJ 3189fDEQY5OTVJZzHhDZ/NA7Ra+4zcQG0cLAzrf5URjGVO07ITJxtB7DS2Eev3W3NO9iP QQc3XQraKo0iHnaIMCXr6IAMyApxr4YROBnjDl/QG5Z1YJmtBKJ/agqIFmrcNdFGkfoRN UW7THeGPHpVqvR/j6OBWemEtbg7sutyhcxVsEYgeZyVfDW/4HNKzxmfS15qH7HKeIqQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="SHhtt1/1"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 899AE606A320; Thu, 19 Nov 2026 00:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=SHhtt1/1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E425B1F000C4; Thu, 19 Nov 2026 00:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795047453; bh=jt4BxDmGSiWjB5h0lHq1a5hEe4lKV7gPuwvl+konzl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SHhtt1/1WewkKuerP4Wo9fwI/ZdPADlue6A3PSLGRljfXsJHfMS/iNa9nai1kvLyh Cx5RQReAW+08NVi5tFiMfQLFvqYjNIQhMPLx0AONiIld0OGp2OBDZi02NsytdP+wMm AL2Kmin4k2DR+02o/uKK6P6zqrE4OCZCEGsVWpc0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shuvam Pandey , Andy Shevchenko , Neel Natu , Dmitry Antipov , "Darrick J. Wong" , Kees Cook , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 1593/2857] lib/tests: extend cmdline KUnit with next_arg() tests Date: Wed, 18 Nov 2026 15:43:47 +0100 Message-ID: <20261118150258.730341461@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shuvam Pandey [ Upstream commit dcc8a57815534e3844f342b28ecfb6e626a816a0 ] The cmdline KUnit suite covers get_option() and get_options(), but it does not exercise next_arg(). Extend the suite with one test for a quoted value containing spaces and one regression test for a bare quote token after a normal parameter. The regression test covers the bare quote token path fixed by commit 9847f21225c4 ("lib/cmdline: avoid page fault in next_arg"). [shuvampandey1@gmail.com: extend cmdline next_arg() coverage with mixed tokens] Link: https://lore.kernel.org/20260316211249.88601-1-shuvampandey1@gmail.com Link: https://lore.kernel.org/20260316101227.15807-1-shuvampandey1@gmail.com Signed-off-by: Shuvam Pandey Reviewed-by: Andy Shevchenko Cc: Neel Natu Cc: Dmitry Antipov Cc: "Darrick J. Wong" Cc: Kees Cook Signed-off-by: Andrew Morton Stable-dep-of: 5d72266218b1 ("lib/cmdline: fix get_options() count and overflow with large ranges") Signed-off-by: Sasha Levin --- lib/cmdline_kunit.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/lib/cmdline_kunit.c b/lib/cmdline_kunit.c index 705b82736be08..20d525aa23eda 100644 --- a/lib/cmdline_kunit.c +++ b/lib/cmdline_kunit.c @@ -139,11 +139,73 @@ static void cmdline_test_range(struct kunit *test) } while (++i < ARRAY_SIZE(cmdline_test_range_strings)); } +static void cmdline_test_next_arg_quoted_value(struct kunit *test) +{ + char in[] = "foo=\"bar baz\" qux=1"; + char *next, *param, *val; + + next = next_arg(in, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "foo"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "bar baz"); + KUNIT_EXPECT_STREQ(test, next, "qux=1"); + + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "qux"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "1"); + KUNIT_EXPECT_STREQ(test, next, ""); +} + +static void cmdline_test_next_arg_bare_quote_regression(struct kunit *test) +{ + char in[] = "foo=bar \""; + char *next, *param, *val; + + next = next_arg(in, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "foo"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "bar"); + KUNIT_EXPECT_STREQ(test, next, "\""); + + /* This hits the i == 0 quoted-token case fixed by 9847f21225c4. */ + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, ""); + KUNIT_EXPECT_PTR_EQ(test, val, NULL); + KUNIT_EXPECT_STREQ(test, next, ""); +} + +static void cmdline_test_next_arg_mixed_tokens(struct kunit *test) +{ + char in[] = "bbb= jjj kkk=\"a=b\""; + char *next, *param, *val; + + next = next_arg(in, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "bbb"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, ""); + KUNIT_EXPECT_STREQ(test, next, "jjj kkk=\"a=b\""); + + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "jjj"); + KUNIT_EXPECT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, next, "kkk=\"a=b\""); + + next = next_arg(next, ¶m, &val); + KUNIT_EXPECT_STREQ(test, param, "kkk"); + KUNIT_ASSERT_NOT_NULL(test, val); + KUNIT_EXPECT_STREQ(test, val, "a=b"); + KUNIT_EXPECT_STREQ(test, next, ""); +} + static struct kunit_case cmdline_test_cases[] = { 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_next_arg_quoted_value), + KUNIT_CASE(cmdline_test_next_arg_bare_quote_regression), + KUNIT_CASE(cmdline_test_next_arg_mixed_tokens), {} }; -- 2.53.0