024872
From 5338636cd9ae7f53ed73f1a7909db03189ea2ff3 Mon Sep 17 00:00:00 2001
024872
From: Eugene Syromyatnikov <evgsyr@gmail.com>
024872
Date: Mon, 4 Jul 2022 12:29:22 +0200
024872
Subject: [PATCH] tests/bpf: fix sloppy low FD number usage
024872
MIME-Version: 1.0
024872
Content-Type: text/plain; charset=UTF-8
024872
Content-Transfer-Encoding: 8bit
024872
024872
FD 42 can already be opened, so close it.  Otherwise, it may lead
024872
to the following test failure:
024872
024872
    -bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}], iter_info_len=5}}, 28) = 841540765612359407 (INJECTED)
024872
    +bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}], iter_info_len=5}}, 28) = 841540765612359407 (INJECTED)
024872
     bpf(BPF_LINK_CREATE, 0x3ff95574fe5, 28) = 841540765612359407 (INJECTED)
024872
    -bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}, ... /* 0x3ff9555d000 */], iter_info_len=6}}, 28) = 841540765612359407 (INJECTED)
024872
    +bpf(BPF_LINK_CREATE, {link_create={prog_fd=0</dev/full>, target_fd=0</dev/full>, attach_type=BPF_TRACE_ITER, flags=0, iter_info=[{map={map_fd=0</dev/full>}}, {map={map_fd=42}}, {map={map_fd=314159265}}, {map={map_fd=-1159983635}}, {map={map_fd=-1}}, ... /* 0x3ff9555d000 */], iter_info_len=6}}, 28) = 841540765612359407 (INJECTED)
024872
    [...]
024872
    FAIL bpf-success-long-y.test (exit status: 1)
024872
024872
* tests/bpf.c (init_BPF_LINK_CREATE_attr7): Close iter_info_data[1] fd.
024872
024872
Fixes: v5.18~18 "bpf: improve bpf(BPF_LINK_CREATE) decoding"
024872
Reported-by: Lenka Špačková <lkuprova@redhat.com>
024872
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2103137
024872
---
024872
 tests/bpf.c | 2 ++
024872
 1 file changed, 2 insertions(+)
024872
024872
diff --git a/tests/bpf.c b/tests/bpf.c
024872
index 82d870e..6c1ffd4 100644
024872
--- a/tests/bpf.c
024872
+++ b/tests/bpf.c
024872
@@ -1557,6 +1557,8 @@ init_BPF_LINK_CREATE_attr7(struct bpf_attr_check *check, size_t idx)
024872
 {
024872
 	struct BPF_LINK_CREATE_struct *attr = &check->data.BPF_LINK_CREATE_data;
024872
 
024872
+	close(iter_info_data[1]);
024872
+
024872
 	if (!iter_info_data_p) {
024872
 		iter_info_data_p = tail_memdup(iter_info_data,
024872
 					       sizeof(iter_info_data));
024872
diff --git a/tests-m32/bpf.c b/tests-m32/bpf.c
024872
index 82d870e..6c1ffd4 100644
024872
--- a/tests-m32/bpf.c
024872
+++ b/tests-m32/bpf.c
024872
@@ -1557,6 +1557,8 @@ init_BPF_LINK_CREATE_attr7(struct bpf_attr_check *check, size_t idx)
024872
 {
024872
 	struct BPF_LINK_CREATE_struct *attr = &check->data.BPF_LINK_CREATE_data;
024872
 
024872
+	close(iter_info_data[1]);
024872
+
024872
 	if (!iter_info_data_p) {
024872
 		iter_info_data_p = tail_memdup(iter_info_data,
024872
 					       sizeof(iter_info_data));
024872
diff --git a/tests-mx32/bpf.c b/tests-mx32/bpf.c
024872
index 82d870e..6c1ffd4 100644
024872
--- a/tests-mx32/bpf.c
024872
+++ b/tests-mx32/bpf.c
024872
@@ -1557,6 +1557,8 @@ init_BPF_LINK_CREATE_attr7(struct bpf_attr_check *check, size_t idx)
024872
 {
024872
 	struct BPF_LINK_CREATE_struct *attr = &check->data.BPF_LINK_CREATE_data;
024872
 
024872
+	close(iter_info_data[1]);
024872
+
024872
 	if (!iter_info_data_p) {
024872
 		iter_info_data_p = tail_memdup(iter_info_data,
024872
 					       sizeof(iter_info_data));
024872
-- 
024872
2.1.4
024872