Skip to content

Commit a3a2e2a

Browse files
fomichevkernel-patches-bot
authored andcommitted
bpf: don't leak memory in bpf getsockopt when optlen == 0
optlen == 0 indicates that the kernel should ignore BPF buffer and use the original one from the user. We, however, forget to free the temporary buffer that we've allocated for BPF. Reported-by: Martin KaFai Lau <[email protected]> Fixes: d8fe449 ("bpf: Don't return EINVAL from {get,set}sockopt when optlen > PAGE_SIZE") Signed-off-by: Stanislav Fomichev <[email protected]>
1 parent 9a478b6 commit a3a2e2a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/bpf/cgroup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,12 +1391,13 @@ int __cgroup_bpf_run_filter_setsockopt(struct sock *sk, int *level,
13911391
if (ctx.optlen != 0) {
13921392
*optlen = ctx.optlen;
13931393
*kernel_optval = ctx.optval;
1394+
/* export and don't free sockopt buf */
1395+
return 0;
13941396
}
13951397
}
13961398

13971399
out:
1398-
if (ret)
1399-
sockopt_free_buf(&ctx);
1400+
sockopt_free_buf(&ctx);
14001401
return ret;
14011402
}
14021403

0 commit comments

Comments
 (0)