Skip to content

Commit b590cb5

Browse files
fomichevborkmann
authored andcommitted
bpf: Switch to offsetofend in BPF_PROG_TEST_RUN
Switch existing pattern of "offsetof(..., member) + FIELD_SIZEOF(..., member)' to "offsetofend(..., member)" which does exactly what we need without all the copy-paste. Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 09c4708 commit b590cb5

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

net/bpf/test_run.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,19 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
252252

253253
/* priority is allowed */
254254

255-
if (!range_is_zero(__skb, offsetof(struct __sk_buff, priority) +
256-
FIELD_SIZEOF(struct __sk_buff, priority),
255+
if (!range_is_zero(__skb, offsetofend(struct __sk_buff, priority),
257256
offsetof(struct __sk_buff, cb)))
258257
return -EINVAL;
259258

260259
/* cb is allowed */
261260

262-
if (!range_is_zero(__skb, offsetof(struct __sk_buff, cb) +
263-
FIELD_SIZEOF(struct __sk_buff, cb),
261+
if (!range_is_zero(__skb, offsetofend(struct __sk_buff, cb),
264262
offsetof(struct __sk_buff, tstamp)))
265263
return -EINVAL;
266264

267265
/* tstamp is allowed */
268266

269-
if (!range_is_zero(__skb, offsetof(struct __sk_buff, tstamp) +
270-
FIELD_SIZEOF(struct __sk_buff, tstamp),
267+
if (!range_is_zero(__skb, offsetofend(struct __sk_buff, tstamp),
271268
sizeof(struct __sk_buff)))
272269
return -EINVAL;
273270

@@ -437,8 +434,7 @@ static int verify_user_bpf_flow_keys(struct bpf_flow_keys *ctx)
437434

438435
/* flags is allowed */
439436

440-
if (!range_is_zero(ctx, offsetof(struct bpf_flow_keys, flags) +
441-
FIELD_SIZEOF(struct bpf_flow_keys, flags),
437+
if (!range_is_zero(ctx, offsetofend(struct bpf_flow_keys, flags),
442438
sizeof(struct bpf_flow_keys)))
443439
return -EINVAL;
444440

0 commit comments

Comments
 (0)