Skip to content

Commit

Permalink
bpf: switch to fdget_raw()
Browse files Browse the repository at this point in the history
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Apr 21, 2023
1 parent 96e85e9 commit 1d0027d
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions kernel/bpf/bpf_inode_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,33 @@ void bpf_inode_storage_free(struct inode *inode)
static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)
{
struct bpf_local_storage_data *sdata;
struct file *f;
int fd;
struct fd f = fdget_raw(*(int *)key);

fd = *(int *)key;
f = fget_raw(fd);
if (!f)
if (!f.file)
return ERR_PTR(-EBADF);

sdata = inode_storage_lookup(f->f_inode, map, true);
fput(f);
sdata = inode_storage_lookup(file_inode(f.file), map, true);
fdput(f);
return sdata ? sdata->data : NULL;
}

static int bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key,
void *value, u64 map_flags)
{
struct bpf_local_storage_data *sdata;
struct file *f;
int fd;
struct fd f = fdget_raw(*(int *)key);

fd = *(int *)key;
f = fget_raw(fd);
if (!f)
if (!f.file)
return -EBADF;
if (!inode_storage_ptr(f->f_inode)) {
fput(f);
if (!inode_storage_ptr(file_inode(f.file))) {
fdput(f);
return -EBADF;
}

sdata = bpf_local_storage_update(f->f_inode,
sdata = bpf_local_storage_update(file_inode(f.file),
(struct bpf_local_storage_map *)map,
value, map_flags, GFP_ATOMIC);
fput(f);
fdput(f);
return PTR_ERR_OR_ZERO(sdata);
}

Expand All @@ -135,16 +129,14 @@ static int inode_storage_delete(struct inode *inode, struct bpf_map *map)

static int bpf_fd_inode_storage_delete_elem(struct bpf_map *map, void *key)
{
struct file *f;
int fd, err;
struct fd f = fdget_raw(*(int *)key);
int err;

fd = *(int *)key;
f = fget_raw(fd);
if (!f)
if (!f.file)
return -EBADF;

err = inode_storage_delete(f->f_inode, map);
fput(f);
err = inode_storage_delete(file_inode(f.file), map);
fdput(f);
return err;
}

Expand Down

0 comments on commit 1d0027d

Please sign in to comment.