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=1795038720; b=RLSZAU/prS9u0XHkVoK0A6QUztFtd1PKhVu3QHDCxBAb5BOIKOhefVAYIdiBzX4oTT82 Sn8StIpapjRgk3WfZHuhdeTU94HYimzv3K6dpBFV1nq4DF2Bd80MYIUuNz+1RRmy9DiXO 0dAME5g/lWJWvCrg17PvExoApAxfaFhXjFH578lXZl6NgljKTSGk2eGkOcUaiPnQ9C+lz n5RQAXIjOza55SNBe7zC6/hssr8mdrYmzu7C6tJ0vXxhpUZaGfEO8QTtwk0Wo2EeXIIe3 eIDzTL2NglfedBwBHyjG3p7SWrV5IitzV/y2WXrcE0RJwwKudF77oG8fJlpBMCd9DUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795038720; 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=5lCUO8syeHahvc2QTTmQWSKsNjN/uiy1+6y25ZOJ7Xs=; b=2BfQ5xf9hvQuSchRRhsy5lOo1e8hsELL2OICpCb/bB8t2Xvdtun+tfDj/qqHWYygs/n/ v1TeFGLc86qS/kLwsMecdZelQgINxWl0X04OW42WhFUViIGtNH5et1KFhhfHH6Y98yvVE Nw9ttY7ok+UHpMZg3B1Hc0KvgBSjSCPGI0+6tIT44Hxprc9SHEuzH64ixK61ykOhsfN2K bfxaFX9wLZa8a2SGKs/eG9qZgnZYKYlpeZ3DuMrZ4ER+yL8vZZ9chNTMjcdTckx0t+1s1 4PfO78h0DuEhmSVBSyZ0Kw0ocD/xCyE66lrUNH9cr/M3/jYdosKxdQg16grmQOSHhrQ== 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=CJV4byZK; 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 3C089606A334; Wed, 18 Nov 2026 21:52:00 +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=CJV4byZK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A54F1F000CD; Wed, 18 Nov 2026 21:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795038720; bh=5lCUO8syeHahvc2QTTmQWSKsNjN/uiy1+6y25ZOJ7Xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CJV4byZKDdVzWcB1mD/MNr9EkdQm34Y8YdQnATjUjy86JZiQ3bn56+3kPU2oOmx+S j4czOQ9mwIWBU8cwwwChFrAg2rGTdXKdOX2/BWbyaeQMPCNNqmCBgQpEmbiuc7S6b/ 5ANAReDoA0twBcqjECzUdJibAW5eYg4QULj7IJ+c= 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.6 1844/3318] lib/tests: extend cmdline KUnit with next_arg() tests Date: Wed, 18 Nov 2026 15:41:06 +0100 Message-ID: <20261118150417.175831475@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@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.6-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