Skip to content

Commit 17e3ac8

Browse files
yonghong-songborkmann
authored andcommittedJan 11, 2019
bpf: fix bpffs bitfield pretty print
Commit 9d5f9f7 ("bpf: btf: fix struct/union/fwd types with kind_flag") introduced kind_flag and used bitfield_size in the btf_member to directly pretty print member values. The commit contained a bug where the incorrect parameters could be passed to function btf_bitfield_seq_show(). The bits_offset parameter in the function expects a value less than 8. Instead, the member offset in the structure is passed. The below is btf_bitfield_seq_show() func signature: void btf_bitfield_seq_show(void *data, u8 bits_offset, u8 nr_bits, struct seq_file *m) both bits_offset and nr_bits are u8 type. If the bitfield member offset is greater than 256, incorrect value will be printed. This patch fixed the issue by calculating correct proper data offset and bits_offset similar to non kind_flag case. Fixes: 9d5f9f7 ("bpf: btf: fix struct/union/fwd types with kind_flag") Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed
 

‎kernel/bpf/btf.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,6 @@ static void btf_bitfield_seq_show(void *data, u8 bits_offset,
12191219
u8 nr_copy_bits;
12201220
u64 print_num;
12211221

1222-
data += BITS_ROUNDDOWN_BYTES(bits_offset);
1223-
bits_offset = BITS_PER_BYTE_MASKED(bits_offset);
12241222
nr_copy_bits = nr_bits + bits_offset;
12251223
nr_copy_bytes = BITS_ROUNDUP_BYTES(nr_copy_bits);
12261224

@@ -1255,7 +1253,9 @@ static void btf_int_bits_seq_show(const struct btf *btf,
12551253
* BTF_INT_OFFSET() cannot exceed 64 bits.
12561254
*/
12571255
total_bits_offset = bits_offset + BTF_INT_OFFSET(int_data);
1258-
btf_bitfield_seq_show(data, total_bits_offset, nr_bits, m);
1256+
data += BITS_ROUNDDOWN_BYTES(total_bits_offset);
1257+
bits_offset = BITS_PER_BYTE_MASKED(total_bits_offset);
1258+
btf_bitfield_seq_show(data, bits_offset, nr_bits, m);
12591259
}
12601260

12611261
static void btf_int_seq_show(const struct btf *btf, const struct btf_type *t,
@@ -2001,12 +2001,12 @@ static void btf_struct_seq_show(const struct btf *btf, const struct btf_type *t,
20012001

20022002
member_offset = btf_member_bit_offset(t, member);
20032003
bitfield_size = btf_member_bitfield_size(t, member);
2004+
bytes_offset = BITS_ROUNDDOWN_BYTES(member_offset);
2005+
bits8_offset = BITS_PER_BYTE_MASKED(member_offset);
20042006
if (bitfield_size) {
2005-
btf_bitfield_seq_show(data, member_offset,
2007+
btf_bitfield_seq_show(data + bytes_offset, bits8_offset,
20062008
bitfield_size, m);
20072009
} else {
2008-
bytes_offset = BITS_ROUNDDOWN_BYTES(member_offset);
2009-
bits8_offset = BITS_PER_BYTE_MASKED(member_offset);
20102010
ops = btf_type_ops(member_type);
20112011
ops->seq_show(btf, member_type, member->type,
20122012
data + bytes_offset, bits8_offset, m);

0 commit comments

Comments
 (0)
Please sign in to comment.