File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
tools/testing/selftests/bpf/progs Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 10
10
#include <linux/types.h>
11
11
#include <bpf/bpf_helpers.h>
12
12
13
+ #define bpf_clamp_umax (VAR , UMAX ) \
14
+ asm volatile ( \
15
+ "if %0 <= %[max] goto +1\n" \
16
+ "%0 = %[max]\n" \
17
+ : "+r"(VAR) \
18
+ : [max]"i"(UMAX) \
19
+ )
20
+
13
21
typedef uint32_t pid_t ;
14
22
struct task_struct {};
15
23
@@ -413,6 +421,7 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
413
421
414
422
len = bpf_probe_read_user_str (payload , STROBE_MAX_STR_LEN , map .tag );
415
423
if (len <= STROBE_MAX_STR_LEN ) {
424
+ bpf_clamp_umax (len , STROBE_MAX_STR_LEN );
416
425
descr -> tag_len = len ;
417
426
payload += len ;
418
427
}
@@ -430,13 +439,15 @@ static __always_inline void *read_map_var(struct strobemeta_cfg *cfg,
430
439
len = bpf_probe_read_user_str (payload , STROBE_MAX_STR_LEN ,
431
440
map .entries [i ].key );
432
441
if (len <= STROBE_MAX_STR_LEN ) {
442
+ bpf_clamp_umax (len , STROBE_MAX_STR_LEN );
433
443
descr -> key_lens [i ] = len ;
434
444
payload += len ;
435
445
}
436
446
descr -> val_lens [i ] = 0 ;
437
447
len = bpf_probe_read_user_str (payload , STROBE_MAX_STR_LEN ,
438
448
map .entries [i ].val );
439
449
if (len <= STROBE_MAX_STR_LEN ) {
450
+ bpf_clamp_umax (len , STROBE_MAX_STR_LEN );
440
451
descr -> val_lens [i ] = len ;
441
452
payload += len ;
442
453
}
You can’t perform that action at this time.
0 commit comments