Skip to content

Commit 36f9814

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: fix uapi hole for 32 bit compat applications
In 64 bit, we have a 4 byte hole between ifindex and netns_dev in the case of struct bpf_map_info but also struct bpf_prog_info. In net-next commit b85fab0 ("bpf: Add gpl_compatible flag to struct bpf_prog_info") added a bitfield into it to expose some flags related to programs. Thus, add an unnamed __u32 bitfield for both so that alignment keeps the same in both 32 and 64 bit cases, and can be naturally extended from there as in b85fab0. Before: # file test.o test.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped # pahole test.o struct bpf_map_info { __u32 type; /* 0 4 */ __u32 id; /* 4 4 */ __u32 key_size; /* 8 4 */ __u32 value_size; /* 12 4 */ __u32 max_entries; /* 16 4 */ __u32 map_flags; /* 20 4 */ char name[16]; /* 24 16 */ __u32 ifindex; /* 40 4 */ __u64 netns_dev; /* 44 8 */ __u64 netns_ino; /* 52 8 */ /* size: 64, cachelines: 1, members: 10 */ /* padding: 4 */ }; After (same as on 64 bit): # file test.o test.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped # pahole test.o struct bpf_map_info { __u32 type; /* 0 4 */ __u32 id; /* 4 4 */ __u32 key_size; /* 8 4 */ __u32 value_size; /* 12 4 */ __u32 max_entries; /* 16 4 */ __u32 map_flags; /* 20 4 */ char name[16]; /* 24 16 */ __u32 ifindex; /* 40 4 */ /* XXX 4 bytes hole, try to pack */ __u64 netns_dev; /* 48 8 */ __u64 netns_ino; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ /* size: 64, cachelines: 1, members: 10 */ /* sum members: 60, holes: 1, sum holes: 4 */ }; Reported-by: Dmitry V. Levin <[email protected]> Reported-by: Eugene Syromiatnikov <[email protected]> Fixes: 52775b3 ("bpf: offload: report device information about offloaded maps") Fixes: 675fc27 ("bpf: offload: report device information for offloaded programs") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 8005b09 commit 36f9814

File tree

2 files changed

+4
-0
lines changed
  • include/uapi/linux
  • tools/include/uapi/linux

2 files changed

+4
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ struct bpf_prog_info {
10171017
__aligned_u64 map_ids;
10181018
char name[BPF_OBJ_NAME_LEN];
10191019
__u32 ifindex;
1020+
__u32 :32;
10201021
__u64 netns_dev;
10211022
__u64 netns_ino;
10221023
} __attribute__((aligned(8)));
@@ -1030,6 +1031,7 @@ struct bpf_map_info {
10301031
__u32 map_flags;
10311032
char name[BPF_OBJ_NAME_LEN];
10321033
__u32 ifindex;
1034+
__u32 :32;
10331035
__u64 netns_dev;
10341036
__u64 netns_ino;
10351037
} __attribute__((aligned(8)));

tools/include/uapi/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ struct bpf_prog_info {
10171017
__aligned_u64 map_ids;
10181018
char name[BPF_OBJ_NAME_LEN];
10191019
__u32 ifindex;
1020+
__u32 :32;
10201021
__u64 netns_dev;
10211022
__u64 netns_ino;
10221023
} __attribute__((aligned(8)));
@@ -1030,6 +1031,7 @@ struct bpf_map_info {
10301031
__u32 map_flags;
10311032
char name[BPF_OBJ_NAME_LEN];
10321033
__u32 ifindex;
1034+
__u32 :32;
10331035
__u64 netns_dev;
10341036
__u64 netns_ino;
10351037
} __attribute__((aligned(8)));

0 commit comments

Comments
 (0)