Skip to content

Commit 1f97c03

Browse files
Hou Taoanakryiko
authored andcommitted
bpf: Preserve param->string when parsing mount options
In bpf_parse_param(), keep the value of param->string intact so it can be freed later. Otherwise, the kmalloc area pointed to by param->string will be leaked as shown below: unreferenced object 0xffff888118c46d20 (size 8): comm "new_name", pid 12109, jiffies 4295580214 hex dump (first 8 bytes): 61 6e 79 00 38 c9 5c 7e any.8.\~ backtrace (crc e1b7f876): [<00000000c6848ac7>] kmemleak_alloc+0x4b/0x80 [<00000000de9f7d00>] __kmalloc_node_track_caller_noprof+0x36e/0x4a0 [<000000003e29b886>] memdup_user+0x32/0xa0 [<0000000007248326>] strndup_user+0x46/0x60 [<0000000035b3dd29>] __x64_sys_fsconfig+0x368/0x3d0 [<0000000018657927>] x64_sys_call+0xff/0x9f0 [<00000000c0cabc95>] do_syscall_64+0x3b/0xc0 [<000000002f331597>] entry_SYSCALL_64_after_hwframe+0x4b/0x53 Fixes: 6c1752e ("bpf: Support symbolic BPF FS delegation mount options") Signed-off-by: Hou Tao <houtao1@huawei.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/bpf/20241022130133.3798232-1-houtao@huaweicloud.com
1 parent a552e2e commit 1f97c03

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

kernel/bpf/inode.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
880880
const struct btf_type *enum_t;
881881
const char *enum_pfx;
882882
u64 *delegate_msk, msk = 0;
883-
char *p;
883+
char *p, *str;
884884
int val;
885885

886886
/* ignore errors, fallback to hex */
@@ -911,7 +911,8 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
911911
return -EINVAL;
912912
}
913913

914-
while ((p = strsep(&param->string, ":"))) {
914+
str = param->string;
915+
while ((p = strsep(&str, ":"))) {
915916
if (strcmp(p, "any") == 0) {
916917
msk |= ~0ULL;
917918
} else if (find_btf_enum_const(info.btf, enum_t, enum_pfx, p, &val)) {

0 commit comments

Comments
 (0)