Skip to content

Commit b87121d

Browse files
Al Viroborkmann
authored andcommitted
bpf: don't bother with getname/kern_path - use user_path_at
kernel/bpf/inode.c misuses kern_path...() - it's much simpler (and more efficient, on top of that) to use user_path...() counterparts rather than bothering with doing getname() manually. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20200120232858.GF8904@ZenIV.linux.org.uk
1 parent d49d066 commit b87121d

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

‎kernel/bpf/inode.c‎

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static const struct inode_operations bpf_dir_iops = {
380380
.unlink = simple_unlink,
381381
};
382382

383-
static int bpf_obj_do_pin(const struct filename *pathname, void *raw,
383+
static int bpf_obj_do_pin(const char __user *pathname, void *raw,
384384
enum bpf_type type)
385385
{
386386
struct dentry *dentry;
@@ -389,7 +389,7 @@ static int bpf_obj_do_pin(const struct filename *pathname, void *raw,
389389
umode_t mode;
390390
int ret;
391391

392-
dentry = kern_path_create(AT_FDCWD, pathname->name, &path, 0);
392+
dentry = user_path_create(AT_FDCWD, pathname, &path, 0);
393393
if (IS_ERR(dentry))
394394
return PTR_ERR(dentry);
395395

@@ -422,38 +422,30 @@ static int bpf_obj_do_pin(const struct filename *pathname, void *raw,
422422

423423
int bpf_obj_pin_user(u32 ufd, const char __user *pathname)
424424
{
425-
struct filename *pname;
426425
enum bpf_type type;
427426
void *raw;
428427
int ret;
429428

430-
pname = getname(pathname);
431-
if (IS_ERR(pname))
432-
return PTR_ERR(pname);
433-
434429
raw = bpf_fd_probe_obj(ufd, &type);
435-
if (IS_ERR(raw)) {
436-
ret = PTR_ERR(raw);
437-
goto out;
438-
}
430+
if (IS_ERR(raw))
431+
return PTR_ERR(raw);
439432

440-
ret = bpf_obj_do_pin(pname, raw, type);
433+
ret = bpf_obj_do_pin(pathname, raw, type);
441434
if (ret != 0)
442435
bpf_any_put(raw, type);
443-
out:
444-
putname(pname);
436+
445437
return ret;
446438
}
447439

448-
static void *bpf_obj_do_get(const struct filename *pathname,
440+
static void *bpf_obj_do_get(const char __user *pathname,
449441
enum bpf_type *type, int flags)
450442
{
451443
struct inode *inode;
452444
struct path path;
453445
void *raw;
454446
int ret;
455447

456-
ret = kern_path(pathname->name, LOOKUP_FOLLOW, &path);
448+
ret = user_path_at(AT_FDCWD, pathname, LOOKUP_FOLLOW, &path);
457449
if (ret)
458450
return ERR_PTR(ret);
459451

@@ -480,36 +472,27 @@ static void *bpf_obj_do_get(const struct filename *pathname,
480472
int bpf_obj_get_user(const char __user *pathname, int flags)
481473
{
482474
enum bpf_type type = BPF_TYPE_UNSPEC;
483-
struct filename *pname;
484-
int ret = -ENOENT;
485475
int f_flags;
486476
void *raw;
477+
int ret;
487478

488479
f_flags = bpf_get_file_flag(flags);
489480
if (f_flags < 0)
490481
return f_flags;
491482

492-
pname = getname(pathname);
493-
if (IS_ERR(pname))
494-
return PTR_ERR(pname);
495-
496-
raw = bpf_obj_do_get(pname, &type, f_flags);
497-
if (IS_ERR(raw)) {
498-
ret = PTR_ERR(raw);
499-
goto out;
500-
}
483+
raw = bpf_obj_do_get(pathname, &type, f_flags);
484+
if (IS_ERR(raw))
485+
return PTR_ERR(raw);
501486

502487
if (type == BPF_TYPE_PROG)
503488
ret = bpf_prog_new_fd(raw);
504489
else if (type == BPF_TYPE_MAP)
505490
ret = bpf_map_new_fd(raw, f_flags);
506491
else
507-
goto out;
492+
return -ENOENT;
508493

509494
if (ret < 0)
510495
bpf_any_put(raw, type);
511-
out:
512-
putname(pname);
513496
return ret;
514497
}
515498

0 commit comments

Comments
 (0)