Skip to content

Commit b165585

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: implement dummy fops for bpf objects
syzkaller was able to trigger the following warning in do_dentry_open(): WARNING: CPU: 1 PID: 4508 at fs/open.c:778 do_dentry_open+0x4ad/0xe40 fs/open.c:778 Kernel panic - not syncing: panic_on_warn set ... CPU: 1 PID: 4508 Comm: syz-executor867 Not tainted 4.17.0+ #90 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: [...] vfs_open+0x139/0x230 fs/open.c:908 do_last fs/namei.c:3370 [inline] path_openat+0x1717/0x4dc0 fs/namei.c:3511 do_filp_open+0x249/0x350 fs/namei.c:3545 do_sys_open+0x56f/0x740 fs/open.c:1101 __do_sys_openat fs/open.c:1128 [inline] __se_sys_openat fs/open.c:1122 [inline] __x64_sys_openat+0x9d/0x100 fs/open.c:1122 do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x49/0xbe Problem was that prog and map inodes in bpf fs did not implement a dummy file open operation that would return an error. The patch in do_dentry_open() checks whether f_ops are present and if not bails out with an error. While this may be fine, we really shouldn't be throwing a warning though. Thus follow the model similar to bad_file_ops and reject the request unconditionally with -EIO. Fixes: b219775 ("bpf: add support for persistent maps/progs") Reported-by: [email protected] Signed-off-by: Daniel Borkmann <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 66e58e0 commit b165585

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kernel/bpf/inode.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ static const struct file_operations bpffs_map_fops = {
295295
.release = bpffs_map_release,
296296
};
297297

298+
static int bpffs_obj_open(struct inode *inode, struct file *file)
299+
{
300+
return -EIO;
301+
}
302+
303+
static const struct file_operations bpffs_obj_fops = {
304+
.open = bpffs_obj_open,
305+
};
306+
298307
static int bpf_mkobj_ops(struct dentry *dentry, umode_t mode, void *raw,
299308
const struct inode_operations *iops,
300309
const struct file_operations *fops)
@@ -314,15 +323,16 @@ static int bpf_mkobj_ops(struct dentry *dentry, umode_t mode, void *raw,
314323

315324
static int bpf_mkprog(struct dentry *dentry, umode_t mode, void *arg)
316325
{
317-
return bpf_mkobj_ops(dentry, mode, arg, &bpf_prog_iops, NULL);
326+
return bpf_mkobj_ops(dentry, mode, arg, &bpf_prog_iops,
327+
&bpffs_obj_fops);
318328
}
319329

320330
static int bpf_mkmap(struct dentry *dentry, umode_t mode, void *arg)
321331
{
322332
struct bpf_map *map = arg;
323333

324334
return bpf_mkobj_ops(dentry, mode, arg, &bpf_map_iops,
325-
map->btf ? &bpffs_map_fops : NULL);
335+
map->btf ? &bpffs_map_fops : &bpffs_obj_fops);
326336
}
327337

328338
static struct dentry *

0 commit comments

Comments
 (0)