Skip to content

Commit 9f44653

Browse files
ArnaudLcmKernel Patches Daemon
authored andcommitted
syztest
#syz test Reported-by: [email protected] Tested-by: [email protected]
1 parent 9879802 commit 9f44653

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

kernel/bpf/stackmap.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static long __bpf_get_stackid(struct bpf_map *map,
230230
struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
231231
struct stack_map_bucket *bucket, *new_bucket, *old_bucket;
232232
u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
233-
u32 hash, id, trace_nr, trace_len, i;
233+
u32 hash, id, trace_nr, trace_len, i, max_depth;
234234
bool user = flags & BPF_F_USER_STACK;
235235
u64 *ips;
236236
bool hash_matches;
@@ -241,6 +241,19 @@ static long __bpf_get_stackid(struct bpf_map *map,
241241

242242
trace_nr = trace->nr - skip;
243243
trace_len = trace_nr * sizeof(u64);
244+
245+
/* Clamp the trace to max allowed depth */
246+
if (stack_map_use_build_id(map))
247+
max_depth = smap->map.value_size / sizeof(struct bpf_stack_build_id);
248+
else
249+
max_depth = smap->map.value_size / sizeof(u64);
250+
251+
if (trace_nr > max_depth)
252+
trace_nr = max_depth;
253+
254+
ips = trace->ip + skip;
255+
256+
244257
ips = trace->ip + skip;
245258
hash = jhash2((u32 *)ips, trace_len / sizeof(u32), 0);
246259
id = hash & (smap->n_buckets - 1);

0 commit comments

Comments
 (0)