Skip to content

Commit 478412b

Browse files
tetragon: handle resolving null pointer
Instead of following a null pointer, note that one was found so that the selector does not determine a match against unrelated data in memory. Signed-off-by: Andy Strohman <[email protected]>
1 parent 36afafa commit 478412b

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

bpf/lib/generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct msg_generic_kprobe {
8080
#ifndef __V61_BPF_PROG
8181
struct generic_path path;
8282
#endif
83+
__s8 resolve_err_depth[MAX_POSSIBLE_ARGS];
8384
};
8485

8586
FUNC_INLINE size_t generic_kprobe_common_size(void)

bpf/process/generic_calls.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,22 @@ extract_arg_depth(u32 i, struct extract_arg_data *data)
391391
{
392392
if (i >= MAX_BTF_ARG_DEPTH || !data->btf_config[i].is_initialized)
393393
return 1;
394+
394395
*data->arg = *data->arg + data->btf_config[i].offset;
395-
if (data->btf_config[i].is_pointer)
396-
probe_read((void *)data->arg, sizeof(char *), (void *)*data->arg);
396+
397+
if (data->btf_config[i].is_pointer) {
398+
if (probe_read((void *)data->arg, sizeof(char *), (void *)*data->arg) < 0) {
399+
*data->resolve_err_depth = i;
400+
return 1;
401+
}
402+
}
403+
397404
return 0;
398405
}
399406

400407
#ifdef __LARGE_BPF_PROG
401-
FUNC_INLINE void extract_arg(struct event_config *config, int index, unsigned long *a)
408+
FUNC_INLINE void extract_arg(struct event_config *config, int index, unsigned long *a,
409+
__s8 *resolve_err_depth)
402410
{
403411
struct config_btf_arg *btf_config;
404412

@@ -413,6 +421,7 @@ FUNC_INLINE void extract_arg(struct event_config *config, int index, unsigned lo
413421
struct extract_arg_data extract_data = {
414422
.btf_config = btf_config,
415423
.arg = a,
424+
.resolve_err_depth = resolve_err_depth,
416425
};
417426
#ifndef __V61_BPF_PROG
418427
#pragma unroll
@@ -426,7 +435,10 @@ FUNC_INLINE void extract_arg(struct event_config *config, int index, unsigned lo
426435
}
427436
}
428437
#else
429-
FUNC_INLINE void extract_arg(struct event_config *config, int index, unsigned long *a) {}
438+
FUNC_INLINE void extract_arg(struct event_config *config, int index, unsigned long *a,
439+
__s8 *resolve_err_depth)
440+
{
441+
}
430442
#endif /* __LARGE_BPF_PROG */
431443

432444
FUNC_INLINE int arg_idx(int index)
@@ -471,9 +483,11 @@ FUNC_INLINE long generic_read_arg(void *ctx, int index, long off, struct bpf_map
471483
ty = config->arg[index];
472484
am = config->arm[index];
473485

486+
e->resolve_err_depth[index] = -1;
487+
474488
#if defined(GENERIC_TRACEPOINT) || defined(GENERIC_USDT)
475489
a = (&e->a0)[index];
476-
extract_arg(config, index, &a);
490+
extract_arg(config, index, &a, &e->resolve_err_depth[index]);
477491
#else
478492
arg_index = config->idx[index];
479493
asm volatile("%[arg_index] &= %1 ;\n"
@@ -491,7 +505,7 @@ FUNC_INLINE long generic_read_arg(void *ctx, int index, long off, struct bpf_map
491505
else
492506
a = (&e->a0)[arg_index];
493507

494-
extract_arg(config, index, &a);
508+
extract_arg(config, index, &a, &e->resolve_err_depth[index]);
495509

496510
if (should_offload_path(ty))
497511
return generic_path_offload(ctx, ty, a, index, off, tailcals);

bpf/process/types/basic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct config_usdt_arg {
184184
struct extract_arg_data {
185185
struct config_btf_arg *btf_config;
186186
unsigned long *arg;
187+
__s8 *resolve_err_depth;
187188
};
188189

189190
#define MAX_BTF_ARG_DEPTH 10
@@ -2024,6 +2025,9 @@ selector_arg_offset(__u8 *f, struct msg_generic_kprobe *e, __u32 selidx,
20242025
if (index > 5)
20252026
return 0;
20262027

2028+
if (e->resolve_err_depth[index] != -1)
2029+
return 0;
2030+
20272031
args = get_arg(e, index);
20282032
switch (filter->type) {
20292033
case fd_ty:

0 commit comments

Comments
 (0)