[PATCH v2 3/6] bpf: implement decoding of BPF_PROG_LOAD fd_array field
Paul Chaignon
paul at isovalent.com
Thu Dec 30 10:59:37 UTC 2021
* src/bpf_attr.h (BPF_PROG_LOAD_struct): Add fd_array field introduced by
Linux kernel commit v5.6-rc1~151^2~46^2~37^2~5.
(expected_BPF_PROG_LOAD_struct_size): Update.
* src/bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Decode the new field.
* NEWS: Mention this.
* tests/bpf-obj_get_info_by_fd.c (print_prog_load): Update expected
output.
* tests/bpf.c (BPF_PROG_LOAD_checks): Likewise.
* tests/kernel_version.c (print_bpf_attr): Likewise.
Signed-off-by: Paul Chaignon <paul at isovalent.com>
---
NEWS | 2 +-
src/bpf.c | 6 ++++++
src/bpf_attr.h | 6 ++++--
tests/bpf-obj_get_info_by_fd.c | 2 ++
tests/bpf.c | 5 +++--
tests/kernel_version.c | 3 ++-
6 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index 50781548e..9b8c1ec6b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,7 @@ Noteworthy changes in release ?.?? (????-??-??)
===============================================
* Improvements
- * Enhanced decoding of BPF_MAP_CREATE bpf syscall command.
+ * Enhanced decoding of BPF_MAP_CREATE and BPF_PROG_LOAD bpf syscall commands.
* Updated lists of BPF_* constants.
* Updated lists of ioctl commands from Linux 5.16.
diff --git a/src/bpf.c b/src/bpf.c
index 5c1e7d7ba..c909d93cf 100644
--- a/src/bpf.c
+++ b/src/bpf.c
@@ -414,6 +414,12 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)
break;
tprint_struct_next();
PRINT_FIELD_FD(attr, attach_prog_fd, tcp);
+
+ /* fd_array was added in Linux commit v5.14-rc1~119^2~501^2~2^2~13. */
+ if (len <= offsetof(struct BPF_PROG_LOAD_struct, fd_array))
+ break;
+ tprint_struct_next();
+ PRINT_FIELD_ADDR64(attr, fd_array);
}
END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
diff --git a/src/bpf_attr.h b/src/bpf_attr.h
index 7b6590b60..f21dbb54d 100644
--- a/src/bpf_attr.h
+++ b/src/bpf_attr.h
@@ -128,11 +128,13 @@ struct BPF_PROG_LOAD_struct {
uint32_t line_info_cnt;
uint32_t attach_btf_id;
uint32_t attach_prog_fd;
+ uint32_t pad;
+ uint64_t ATTRIBUTE_ALIGNED(8) fd_array;
};
# define BPF_PROG_LOAD_struct_size \
- offsetofend(struct BPF_PROG_LOAD_struct, attach_prog_fd)
-# define expected_BPF_PROG_LOAD_struct_size 116
+ sizeof(struct BPF_PROG_LOAD_struct)
+# define expected_BPF_PROG_LOAD_struct_size 128
struct BPF_OBJ_PIN_struct {
uint64_t ATTRIBUTE_ALIGNED(8) pathname;
diff --git a/tests/bpf-obj_get_info_by_fd.c b/tests/bpf-obj_get_info_by_fd.c
index e2123eeee..95392cd53 100644
--- a/tests/bpf-obj_get_info_by_fd.c
+++ b/tests/bpf-obj_get_info_by_fd.c
@@ -231,6 +231,8 @@ print_prog_load(void *attr_void, size_t size, long rc)
printf(", attach_btf_id=0");
if (size > offsetof(struct BPF_PROG_LOAD_struct, attach_prog_fd))
printf(", attach_prog_fd=0</dev/null>");
+ if (size > offsetof(struct BPF_PROG_LOAD_struct, fd_array))
+ printf(", fd_array=NULL");
printf("}, %zu) = ", size);
if (rc >= 0)
printf("%ld<anon_inode:bpf-prog>\n", rc);
diff --git a/tests/bpf.c b/tests/bpf.c
index befb34cbd..eeba43821 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -786,9 +786,9 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
.line_info_cnt = 0xdad7bef8,
.attach_btf_id = 0xdad7befa,
.attach_prog_fd = 0xbadc0def,
+ .fd_array = 0xfaceb00c,
} },
- .size = offsetofend(struct BPF_PROG_LOAD_struct,
- attach_prog_fd),
+ .size = offsetofend(struct BPF_PROG_LOAD_struct, fd_array),
.str = "prog_type=BPF_PROG_TYPE_UNSPEC"
", insn_cnt=0"
", insns=NULL"
@@ -810,6 +810,7 @@ static struct bpf_attr_check BPF_PROG_LOAD_checks[] = {
", line_info_cnt=3671572216"
", attach_btf_id=3671572218"
", attach_prog_fd=-1159983633"
+ ", fd_array=0xfaceb00c"
},
};
diff --git a/tests/kernel_version.c b/tests/kernel_version.c
index fc270cd2a..228d3bccd 100644
--- a/tests/kernel_version.c
+++ b/tests/kernel_version.c
@@ -71,7 +71,8 @@ print_bpf_attr(void)
", line_info=NULL"
", line_info_cnt=0"
", attach_btf_id=0"
- ", attach_prog_fd=0}");
+ ", attach_prog_fd=0"
+ ", fd_array=NULL}");
}
int
--
2.25.1
More information about the Strace-devel
mailing list