History

fix "netfilter: xt_bpf: Fix XT_BPF_MODE_FD_PINNED mode of 'xt_bpf_info_v1'"

Descriptor table is a shared object; it's not a place where you can stick temporary references to files, especially when we don't need an opened file at all.

Al Viro committed 8 years ago

Commit 040ee691 parent 9ee332d4 files · +52 −14Browse files

Unified · Split

4 files
  1. include/linux/bpf.h +10 −0
  2. kernel/bpf/inode.c +39 −1
  3. kernel/bpf/syscall.c +1 −1
  4. net/netfilter/xt_bpf.c +2 −12
include/linux/bpf.h+10−0
@@ -419,6 +419,8 @@ static inline int bpf_map_attr_numa_node(const union bpf_attr *attr) · 418 unmodified lines
419 attr->numa_node : NUMA_NO_NODE;419 attr->numa_node : NUMA_NO_NODE;
420}420}
421 421
422struct bpf_prog *bpf_prog_get_type_path(const char *name, enum bpf_prog_type type);
423
422#else /* !CONFIG_BPF_SYSCALL */424#else /* !CONFIG_BPF_SYSCALL */
423static inline struct bpf_prog *bpf_prog_get(u32 ufd)425static inline struct bpf_prog *bpf_prog_get(u32 ufd)
424{426{
@@ -506,6 +508,12 @@ static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, · 81 unmodified lines
506{508{
507 return 0;509 return 0;
508}510}
511
512static inline struct bpf_prog *bpf_prog_get_type_path(const char *name,
513 enum bpf_prog_type type)
514{
515 return ERR_PTR(-EOPNOTSUPP);
516}
509#endif /* CONFIG_BPF_SYSCALL */517#endif /* CONFIG_BPF_SYSCALL */
510 518
511static inline struct bpf_prog *bpf_prog_get_type(u32 ufd,519static inline struct bpf_prog *bpf_prog_get_type(u32 ufd,
@@ -514,6 +522,8 @@ static inline struct bpf_prog *bpf_prog_get_type(u32 ufd, · 2 unmodified lines
514 return bpf_prog_get_type_dev(ufd, type, false);522 return bpf_prog_get_type_dev(ufd, type, false);
515}523}
516 524
525bool bpf_prog_get_ok(struct bpf_prog *, enum bpf_prog_type *, bool);
526
517int bpf_prog_offload_compile(struct bpf_prog *prog);527int bpf_prog_offload_compile(struct bpf_prog *prog);
518void bpf_prog_offload_destroy(struct bpf_prog *prog);528void bpf_prog_offload_destroy(struct bpf_prog *prog);
519 529
kernel/bpf/inode.c+39−1
@@ -368,7 +368,45 @@ out: · 367 unmodified lines
368 putname(pname);368 putname(pname);
369 return ret;369 return ret;
370}370}
371EXPORT_SYMBOL_GPL(bpf_obj_get_user);371
372static struct bpf_prog *__get_prog_inode(struct inode *inode, enum bpf_prog_type type)
373{
374 struct bpf_prog *prog;
375 int ret = inode_permission(inode, MAY_READ | MAY_WRITE);
376 if (ret)
377 return ERR_PTR(ret);
378
379 if (inode->i_op == &bpf_map_iops)
380 return ERR_PTR(-EINVAL);
381 if (inode->i_op != &bpf_prog_iops)
382 return ERR_PTR(-EACCES);
383
384 prog = inode->i_private;
385
386 ret = security_bpf_prog(prog);
387 if (ret < 0)
388 return ERR_PTR(ret);
389
390 if (!bpf_prog_get_ok(prog, &type, false))
391 return ERR_PTR(-EINVAL);
392
393 return bpf_prog_inc(prog);
394}
395
396struct bpf_prog *bpf_prog_get_type_path(const char *name, enum bpf_prog_type type)
397{
398 struct bpf_prog *prog;
399 struct path path;
400 int ret = kern_path(name, LOOKUP_FOLLOW, &path);
401 if (ret)
402 return ERR_PTR(ret);
403 prog = __get_prog_inode(d_backing_inode(path.dentry), type);
404 if (!IS_ERR(prog))
405 touch_atime(&path);
406 path_put(&path);
407 return prog;
408}
409EXPORT_SYMBOL(bpf_prog_get_type_path);
372 410
373static void bpf_evict_inode(struct inode *inode)411static void bpf_evict_inode(struct inode *inode)
374{412{
kernel/bpf/syscall.c+1−1
@@ -1057,7 +1057,7 @@ struct bpf_prog *bpf_prog_inc_not_zero(struct bpf_prog *prog) · 1056 unmodified lines
1057}1057}
1058EXPORT_SYMBOL_GPL(bpf_prog_inc_not_zero);1058EXPORT_SYMBOL_GPL(bpf_prog_inc_not_zero);
1059 1059
1060static bool bpf_prog_get_ok(struct bpf_prog *prog,1060bool bpf_prog_get_ok(struct bpf_prog *prog,
1061 enum bpf_prog_type *attach_type, bool attach_drv)1061 enum bpf_prog_type *attach_type, bool attach_drv)
1062{1062{
1063 /* not an attachment, just a refcount inc, always allow */1063 /* not an attachment, just a refcount inc, always allow */
net/netfilter/xt_bpf.c+2−12
@@ -52,18 +52,8 @@ static int __bpf_mt_check_fd(int fd, struct bpf_prog **ret) · 51 unmodified lines
52 52
53static int __bpf_mt_check_path(const char *path, struct bpf_prog **ret)53static int __bpf_mt_check_path(const char *path, struct bpf_prog **ret)
54{54{
55 mm_segment_t oldfs = get_fs();55 *ret = bpf_prog_get_type_path(path, BPF_PROG_TYPE_SOCKET_FILTER);
56 int retval, fd;56 return PTR_ERR_OR_ZERO(*ret);
57
58 set_fs(KERNEL_DS);
59 fd = bpf_obj_get_user(path, 0);
60 set_fs(oldfs);
61 if (fd < 0)
62 return fd;
63
64 retval = __bpf_mt_check_fd(fd, ret);
65 sys_close(fd);
66 return retval;
67}57}
68 58
69static int bpf_mt_check(const struct xt_mtchk_param *par)59static int bpf_mt_check(const struct xt_mtchk_param *par)