Commit fa8380a0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'bpf-next-6.12-struct-fd' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Pull bpf 'struct fd' updates from Alexei Starovoitov:
 "This includes struct_fd BPF changes from Al and Andrii"

* tag 'bpf-next-6.12-struct-fd' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next:
  bpf: convert bpf_token_create() to CLASS(fd, ...)
  security,bpf: constify struct path in bpf_token_create() LSM hook
  bpf: more trivial fdget() conversions
  bpf: trivial conversions for fdget()
  bpf: switch maps to CLASS(fd, ...)
  bpf: factor out fetching bpf_map from FD and adding it to used_maps list
  bpf: switch fdget_raw() uses to CLASS(fd_raw, ...)
  bpf: convert __bpf_prog_get() to CLASS(fd, ...)
parents 68e5c7d4 37d3dd66
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -2246,7 +2246,16 @@ void __bpf_obj_drop_impl(void *p, const struct btf_record *rec, bool percpu);

struct bpf_map *bpf_map_get(u32 ufd);
struct bpf_map *bpf_map_get_with_uref(u32 ufd);
struct bpf_map *__bpf_map_get(struct fd f);

static inline struct bpf_map *__bpf_map_get(struct fd f)
{
	if (fd_empty(f))
		return ERR_PTR(-EBADF);
	if (unlikely(fd_file(f)->f_op != &bpf_map_fops))
		return ERR_PTR(-EINVAL);
	return fd_file(f)->private_data;
}

void bpf_map_inc(struct bpf_map *map);
void bpf_map_inc_with_uref(struct bpf_map *map);
struct bpf_map *__bpf_map_inc_not_zero(struct bpf_map *map, bool uref);
+1 −1
Original line number Diff line number Diff line
@@ -431,7 +431,7 @@ LSM_HOOK(int, 0, bpf_prog_load, struct bpf_prog *prog, union bpf_attr *attr,
	 struct bpf_token *token)
LSM_HOOK(void, LSM_RET_VOID, bpf_prog_free, struct bpf_prog *prog)
LSM_HOOK(int, 0, bpf_token_create, struct bpf_token *token, union bpf_attr *attr,
	 struct path *path)
	 const struct path *path)
LSM_HOOK(void, LSM_RET_VOID, bpf_token_free, struct bpf_token *token)
LSM_HOOK(int, 0, bpf_token_cmd, const struct bpf_token *token, enum bpf_cmd cmd)
LSM_HOOK(int, 0, bpf_token_capable, const struct bpf_token *token, int cap)
+2 −2
Original line number Diff line number Diff line
@@ -2182,7 +2182,7 @@ extern int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
				  struct bpf_token *token);
extern void security_bpf_prog_free(struct bpf_prog *prog);
extern int security_bpf_token_create(struct bpf_token *token, union bpf_attr *attr,
				     struct path *path);
				     const struct path *path);
extern void security_bpf_token_free(struct bpf_token *token);
extern int security_bpf_token_cmd(const struct bpf_token *token, enum bpf_cmd cmd);
extern int security_bpf_token_capable(const struct bpf_token *token, int cap);
@@ -2222,7 +2222,7 @@ static inline void security_bpf_prog_free(struct bpf_prog *prog)
{ }

static inline int security_bpf_token_create(struct bpf_token *token, union bpf_attr *attr,
				     struct path *path)
					    const struct path *path)
{
	return 0;
}
+8 −16
Original line number Diff line number Diff line
@@ -78,13 +78,12 @@ 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 fd f = fdget_raw(*(int *)key);
	CLASS(fd_raw, f)(*(int *)key);

	if (!fd_file(f))
	if (fd_empty(f))
		return ERR_PTR(-EBADF);

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

@@ -92,19 +91,16 @@ static long bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key,
					     void *value, u64 map_flags)
{
	struct bpf_local_storage_data *sdata;
	struct fd f = fdget_raw(*(int *)key);
	CLASS(fd_raw, f)(*(int *)key);

	if (!fd_file(f))
	if (fd_empty(f))
		return -EBADF;
	if (!inode_storage_ptr(file_inode(fd_file(f)))) {
		fdput(f);
	if (!inode_storage_ptr(file_inode(fd_file(f))))
		return -EBADF;
	}

	sdata = bpf_local_storage_update(file_inode(fd_file(f)),
					 (struct bpf_local_storage_map *)map,
					 value, map_flags, GFP_ATOMIC);
	fdput(f);
	return PTR_ERR_OR_ZERO(sdata);
}

@@ -123,15 +119,11 @@ static int inode_storage_delete(struct inode *inode, struct bpf_map *map)

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

	if (!fd_file(f))
	if (fd_empty(f))
		return -EBADF;

	err = inode_storage_delete(file_inode(fd_file(f)), map);
	fdput(f);
	return err;
	return inode_storage_delete(file_inode(fd_file(f)), map);
}

/* *gfp_flags* is a hidden argument provided by the verifier */
+3 −8
Original line number Diff line number Diff line
@@ -7711,21 +7711,16 @@ int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
struct btf *btf_get_by_fd(int fd)
{
	struct btf *btf;
	struct fd f;
	CLASS(fd, f)(fd);

	f = fdget(fd);

	if (!fd_file(f))
	if (fd_empty(f))
		return ERR_PTR(-EBADF);

	if (fd_file(f)->f_op != &btf_fops) {
		fdput(f);
	if (fd_file(f)->f_op != &btf_fops)
		return ERR_PTR(-EINVAL);
	}

	btf = fd_file(f)->private_data;
	refcount_inc(&btf->refcnt);
	fdput(f);

	return btf;
}
Loading