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 DAB6133A01E; Sat, 28 Feb 2026 17:33:00 +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=1772299980; cv=none; b=gzdh6lL1Tvc1wgfs6vV4GlwmphNnu6hJYKPUPvhL3ehGKFN9by14iJsPcmtE1O/CibZTblcBknTgBPHlDLM3HshoXnRyZ2RXk5Kj9qomVQs3DrYUkVXkfggBBhicdzQhnx0jpMHE7B/0LnIL+xrOMfDBRXCMdrXCMdyqd3zMiOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772299980; c=relaxed/simple; bh=RIczDaL9PYQP5+M+OkprKa3ruNJrkZtJ83omwcciUhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HxO5kejmk+CPfAKl6JYOH2r6aOU5JBGjm50ljYErhl7xoLhwddnJx7lOQ0CILAtdfsb44UAROWyRwU8AqVmYdZ5qofN8kqiIB+5Bc/cCaRGi1MzSJriSA1SLKoNR2hu5Xx3xD/G0HtCpR4Qg3muntztbWnYa8xEOSx1ztOqSr14= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jg1woAdy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Jg1woAdy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7915FC19425; Sat, 28 Feb 2026 17:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772299980; bh=RIczDaL9PYQP5+M+OkprKa3ruNJrkZtJ83omwcciUhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jg1woAdylgoVJCyZbzHNxHb4F7AoYeXfr6ESgJaXA9P+3S9vBkKlXDuF2ZwvD+rST +n7GG9zthLTMBW4l7G+hR2ilcTkNHZnHtc4fsPC+BRVWPo0dejAkYufVcerkNdOV2i ev98GnyhsohZx1IGWzOR6SUZC2AqGwHGFfPWPPI0Cql6OyLcP3K1Z16qtoIad9cfKe ZrHqtK+AA4eQOO2dSAcEUNzl0BRTnI7Qn3QKz+cFbs7Bt28to0RqHX5KJ52hrnIa0Z KoA5CD/QXBpp9JPgYgXisy8u0GLMVjuY47jliVv5ImxiJIIqBp7ExgidWEF3Rel8tR l11+MdExfu/KA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sri Jayaramappa , Guilherme Amadio , Ian Rogers , Joshua Hunt , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.19 009/844] libsubcmd: Fix null intersection case in exclude_cmds() Date: Sat, 28 Feb 2026 12:18:42 -0500 Message-ID: <20260228173244.1509663-10-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260228173244.1509663-1-sashal@kernel.org> References: <20260228173244.1509663-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Sri Jayaramappa [ Upstream commit b6ee9b6e206b288921c14c906eebf4b32fe0c0d8 ] When there is no exclusion occurring from the cmds list - for example - cmds contains ["read-vdso32"] and excludes contains ["archive"] - the main loop completes with ci == cj == 0. In the original code the loop processing the remaining elements in the list was conditional: if (ci != cj) { ...} So we end up in the assertion loop since ci < cmds->cnt and we incorrectly try to assert the list elements to be NULL and fail with the following error help.c:104: exclude_cmds: Assertion `cmds->names[ci] == NULL' failed. Fix this by moving the if (ci != cj) check inside of a broader loop. If ci != cj, left shift the list elements, as before, and then unconditionally advance the ci and cj indicies which also covers the ci == cj case. Fixes: 1fdf938168c4d26f ("perf tools: Fix use-after-free in help_unknown_cmd()") Reviewed-by: Guilherme Amadio Signed-off-by: Sri Jayaramappa Tested-by: Guilherme Amadio Tested-by: Ian Rogers Cc: Joshua Hunt Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20251202213632.2873731-1-sjayaram@akamai.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/lib/subcmd/help.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c index ddaeb4eb3e249..db94aa685b73b 100644 --- a/tools/lib/subcmd/help.c +++ b/tools/lib/subcmd/help.c @@ -97,11 +97,13 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) ei++; } } - if (ci != cj) { - while (ci < cmds->cnt) { - cmds->names[cj++] = cmds->names[ci]; - cmds->names[ci++] = NULL; + while (ci < cmds->cnt) { + if (ci != cj) { + cmds->names[cj] = cmds->names[ci]; + cmds->names[ci] = NULL; } + ci++; + cj++; } for (ci = cj; ci < cmds->cnt; ci++) assert(cmds->names[ci] == NULL); -- 2.51.0