Blob Blame History Raw
From 755e4a0da3035c128d18c9a8f7d2f61f29715323 Mon Sep 17 00:00:00 2001
From: Martin Lau <kafai@fb.com>
Date: Thu, 3 Jan 2019 23:36:22 +0000
Subject: [PATCH 16/27] tests: fix prog_info initialization in
 bpf-obj_get_info_by_fd-prog*

The sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_prog_get_info_attr, ...) is
called in a loop.  The bpf_prog_get_info_attr.info object is in size 104
but bpf_prog_get_info_attr.info_len is in size 168.  Hence, if the prog
is jited, the second iteration onwards will have nr_jited_ksyms == 1
which is asking the kernel to fill the
bpf_prog_get_info_attr.info.jited_ksyms and it is NULL.

* tests/bpf-obj_get_info_by_fd.c (main): Clear memory beyond prog_info
at the start of every iteration.

Additional changes:
	tests-m32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)
	tests-mx32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
---
 tests/bpf-obj_get_info_by_fd.c | 1 +
 1 file changed, 1 insertion(+)

Index: strace-4.24/tests/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests/bpf-obj_get_info_by_fd.c	2019-03-10 05:38:07.889179571 +0100
+++ strace-4.24/tests/bpf-obj_get_info_by_fd.c	2019-03-10 05:38:16.038097970 +0100
@@ -345,6 +345,7 @@
 	memset(prog_info, 0, PROG_INFO_SZ);
 	for (unsigned int i = 0; i < 4; i++) {
 		prog_info->jited_prog_len = 0;
+		memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
 		switch (i) {
 		case 1:
 			prog_info->xlated_prog_insns =
Index: strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-m32/bpf-obj_get_info_by_fd.c	2019-03-10 05:35:43.934621086 +0100
+++ strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c	2019-03-10 05:38:32.161936511 +0100
@@ -345,6 +345,7 @@
 	memset(prog_info, 0, PROG_INFO_SZ);
 	for (unsigned int i = 0; i < 4; i++) {
 		prog_info->jited_prog_len = 0;
+		memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
 		switch (i) {
 		case 1:
 			prog_info->xlated_prog_insns =
Index: strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c
===================================================================
--- strace-4.24.orig/tests-mx32/bpf-obj_get_info_by_fd.c	2019-03-10 05:38:12.854129853 +0100
+++ strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c	2019-03-10 05:38:29.561962546 +0100
@@ -345,6 +345,7 @@
 	memset(prog_info, 0, PROG_INFO_SZ);
 	for (unsigned int i = 0; i < 4; i++) {
 		prog_info->jited_prog_len = 0;
+		memset(prog_info + 1, 0, PROG_INFO_SZ - sizeof(*prog_info));
 		switch (i) {
 		case 1:
 			prog_info->xlated_prog_insns =