From: Dmitry V. Levin Date: Thu, 12 Apr 2018 23:00:29 +0000 (+0000) Subject: bpf: harmonize length checks X-Git-Tag: v4.23~317 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee2c065dd4c98d0888fe1ccbbec348357f1c302b;p=strace bpf: harmonize length checks The rest of the decoder uses offsetof to check the length. * bpf.c (BEGIN_BPF_CMD_DECODER(BPF_OBJ_PIN), BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID), BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID), BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Use offsetof instead of offsetofend. --- diff --git a/bpf.c b/bpf.c index dc5df345..6b602b72 100644 --- a/bpf.c +++ b/bpf.c @@ -275,10 +275,10 @@ BEGIN_BPF_CMD_DECODER(BPF_OBJ_PIN) printpath(tcp, attr.pathname); PRINT_FIELD_FD(", ", attr, bpf_fd, tcp); - if (len <= offsetofend(struct BPF_OBJ_PIN_struct, bpf_fd)) - break; /* file_flags field was added in Linux v4.15-rc1~84^2~384^2~4 */ + if (len <= offsetof(struct BPF_OBJ_PIN_struct, file_flags)) + break; PRINT_FIELD_FLAGS(", ", attr, file_flags, bpf_file_mode_flags, "BPF_F_???"); } @@ -321,10 +321,10 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID) { PRINT_FIELD_U("{", attr, start_id); PRINT_FIELD_U(", ", attr, next_id); - if (len <= offsetofend(struct BPF_PROG_GET_NEXT_ID_struct, next_id)) - break; /* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */ + if (len <= offsetof(struct BPF_PROG_GET_NEXT_ID_struct, open_flags)) + break; PRINT_FIELD_FLAGS(", ", attr, open_flags, bpf_file_mode_flags, "BPF_F_???"); } @@ -336,10 +336,10 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID) { PRINT_FIELD_U("{", attr, prog_id); PRINT_FIELD_U(", ", attr, next_id); - if (len <= offsetofend(struct BPF_PROG_GET_FD_BY_ID_struct, next_id)) - break; /* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */ + if (len <= offsetof(struct BPF_PROG_GET_FD_BY_ID_struct, open_flags)) + break; PRINT_FIELD_FLAGS(", ", attr, open_flags, bpf_file_mode_flags, "BPF_F_???"); } @@ -349,10 +349,10 @@ BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID) { PRINT_FIELD_U("{", attr, map_id); PRINT_FIELD_U(", ", attr, next_id); - if (len <= offsetofend(struct BPF_MAP_GET_FD_BY_ID_struct, next_id)) - break; /* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */ + if (len <= offsetof(struct BPF_MAP_GET_FD_BY_ID_struct, open_flags)) + break; PRINT_FIELD_FLAGS(", ", attr, open_flags, bpf_file_mode_flags, "BPF_F_???"); }