From nobody Sat Sep 26 01:04:54 2026 Received: from out-2z4y-a134.jellyfish.systems (out-2z4y-a134.jellyfish.systems [198.54.127.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76AF933CEA7 for ; Sun, 6 Sep 2026 14:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788705595; cv=none; b=D3p13GE01es4o5TDG3wRythnyLYRAfUjzQndeN94T70wY/2MxcRSTTIH2VPlIiPlY2kEOzE42lPiz+EgzbJDB7SO2fu0gG08dp+BblU1iPZC1Uv0Sg2h0Gu9L1kUtk+8XdJ4qZQc42xyqFxsqGpfqfB2amLIigOSuRvSvNhNixc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788705595; c=relaxed/simple; bh=HjX43IXUVj0c1iU7YYoc2MlHHzj53Q0lGrYgc3kbfwM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jtJI/uDZqmA5IyFqsYlwQWhLbmqFt4DdvNk3b3n8JbjPhfIyzzT0mKq5j+otPOUP4nDcDf6chhp6691ShKjht1+daoQRbfEwhRZngTfvpw3AlM6V2TMl5KsgPkVwecCPCGMBhMX19oFmbdjwS1ZdCLV5x+LR9ViEIwpU6EW0a54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tychen.cc; spf=pass smtp.mailfrom=tychen.cc; dkim=pass (2048-bit key) header.d=tychen.cc header.i=@tychen.cc header.b=NJQ6bb1n; arc=none smtp.client-ip=198.54.127.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tychen.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tychen.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tychen.cc header.i=@tychen.cc header.b="NJQ6bb1n" Received: from fedora (unknown [69.5.53.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.spacemail.com (Postfix) with ESMTPSA id 4hdCX13skmz2x9X; Sun, 06 Sep 2026 14:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tychen.cc; s=spacemail; t=1788705573; bh=6ySDbc6oyC0qahabQIu62xCvVoIVq3NcjYGnbezvhBY=; h=From:To:Cc:Subject:Date:From; b=NJQ6bb1nnQLbupaenLLkab6hsY7dJKt2xSHDBjcC/tLtqADesOKMiMz6gXXhI87yB DH//mdmjX9HDRQyDzIaZ+vvhl59VYC5V+6R0SAONXZoueIBCvbTTJwEwSzgAiFBAXh V1fmgRM1iXYV+vDeIqXNnQlHSZLQJNLckuEJmoF5y39Lh1XtlyS+BCdZAwqQRnLsuk 91BYYyPJdEq1owE2LuA6rKN/bBZerOGWm0fSizE/nbY30RGzjaGiZT7kkYkBDeUs8t 9lWvnyWYCm0kxHv0mY+/ZfsJs/8eBZm+q3NKTiTNrWXYwoXTHvFiHijz05udLuIwb9 yeBU+LODqV95A== From: Tianyi Chen To: andrii@kernel.org, Eduard Zingerman Cc: Tianyi Chen , Alexei Starovoitov , Daniel Borkmann , Kumar Kartikeya Dwivedi , Shuah Khan , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Yonghong Song , Brian Vazquez Subject: [PATCH bpf] selftests/bpf: Check returned keys in map batch validators Date: Sun, 6 Sep 2026 22:39:18 +0800 Message-ID: <20260906143918.848536-1-hi@tychen.cc> X-Mailer: git-send-email 2.55.0 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 X-Envelope-From: hi@tychen.cc Content-Type: text/plain; charset="utf-8" The hash and array batch validators mark visited entries by output position, making the subsequent completeness checks always succeed. Duplicate keys with matching values can therefore hide missing entries. Check that returned keys fall within the populated range and index the visited array by key. This detects missing entries while preserving unordered results and existing per-CPU value validation. Controlled inputs confirm that the old validators accept duplicates and out-of-range keys with matching values, while the updated checks reject them. Ordered, reversed and shuffled valid keys still pass, and scalar and per-CPU value corruption is still rejected. The full test_maps suite passes with no skips on the matching kernel. Fixes: 30ff3c59137d ("selftests/bpf: Add batch ops testing for htab and hta= b_percpu map") Fixes: f0fac2cec286 ("selftests/bpf: Add batch ops testing to array bpf map= ") Assisted-by: LLM Signed-off-by: Tianyi Chen --- tools/testing/selftests/bpf/map_tests/array_map_batch_ops.c | 5 ++++- tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/map_tests/array_map_batch_ops.c b/= tools/testing/selftests/bpf/map_tests/array_map_batch_ops.c index b595556315b..76d3800a82a 100644 --- a/tools/testing/selftests/bpf/map_tests/array_map_batch_ops.c +++ b/tools/testing/selftests/bpf/map_tests/array_map_batch_ops.c @@ -45,6 +45,9 @@ static void map_batch_verify(int *visited, __u32 max_entr= ies, int *keys, =20 memset(visited, 0, max_entries * sizeof(*visited)); for (i =3D 0; i < max_entries; i++) { + CHECK(keys[i] < 0 || keys[i] >=3D max_entries, "key checking", + "error: i %d key %d out of range\n", i, keys[i]); + if (is_pcpu) { cpu_offset =3D i * nr_cpus; for (j =3D 0; j < nr_cpus; j++) { @@ -59,7 +62,7 @@ static void map_batch_verify(int *visited, __u32 max_entr= ies, int *keys, "error: i %d key %d value %lld\n", i, keys[i], values[i]); } - visited[i] =3D 1; + visited[keys[i]] =3D 1; } for (i =3D 0; i < max_entries; i++) { CHECK(visited[i] !=3D 1, "visited checking", diff --git a/tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c b/t= ools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c index 5da493b94ae..430949f9691 100644 --- a/tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c +++ b/tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c @@ -50,6 +50,8 @@ static void map_batch_verify(int *visited, __u32 max_entr= ies, =20 memset(visited, 0, max_entries * sizeof(*visited)); for (i =3D 0; i < max_entries; i++) { + CHECK(keys[i] < 1 || keys[i] > max_entries, "key checking", + "error: i %d key %d out of range\n", i, keys[i]); =20 if (is_pcpu) { for (j =3D 0; j < bpf_num_possible_cpus(); j++) { @@ -65,7 +67,7 @@ static void map_batch_verify(int *visited, __u32 max_entr= ies, ((int *)values)[i]); } =20 - visited[i] =3D 1; + visited[keys[i] - 1] =3D 1; =20 } for (i =3D 0; i < max_entries; i++) { --=20 2.55.0