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