Message ID | 20230522232917.2454595-2-andrii@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | Add O_PATH-based BPF_OBJ_PIN and BPF_OBJ_GET support | expand |
On Mon, May 22, 2023 at 04:29:14PM -0700, Andrii Nakryiko wrote: > Do a sanity check whether provided file-to-be-pinned is actually a BPF > object (prog, map, btf) before calling security_path_mknod LSM hook. If > it's not, LSM hook doesn't have to be triggered, as the operation has no > chance of succeeding anyways. > > Suggested-by: Christian Brauner <brauner@kernel.org> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org> > --- Reviewed-by: Christian Brauner <brauner@kernel.org>
On 5/23/23 1:29 AM, Andrii Nakryiko wrote: > Do a sanity check whether provided file-to-be-pinned is actually a BPF > object (prog, map, btf) before calling security_path_mknod LSM hook. If > it's not, LSM hook doesn't have to be triggered, as the operation has no > chance of succeeding anyways. > > Suggested-by: Christian Brauner <brauner@kernel.org> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org> (I took this one already in, thanks!)
diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c index 9948b542a470..329f27d5cacf 100644 --- a/kernel/bpf/inode.c +++ b/kernel/bpf/inode.c @@ -448,18 +448,17 @@ static int bpf_obj_do_pin(const char __user *pathname, void *raw, if (IS_ERR(dentry)) return PTR_ERR(dentry); - mode = S_IFREG | ((S_IRUSR | S_IWUSR) & ~current_umask()); - - ret = security_path_mknod(&path, dentry, mode, 0); - if (ret) - goto out; - dir = d_inode(path.dentry); if (dir->i_op != &bpf_dir_iops) { ret = -EPERM; goto out; } + mode = S_IFREG | ((S_IRUSR | S_IWUSR) & ~current_umask()); + ret = security_path_mknod(&path, dentry, mode, 0); + if (ret) + goto out; + switch (type) { case BPF_TYPE_PROG: ret = vfs_mkobj(dentry, mode, bpf_mkprog, raw);
Do a sanity check whether provided file-to-be-pinned is actually a BPF object (prog, map, btf) before calling security_path_mknod LSM hook. If it's not, LSM hook doesn't have to be triggered, as the operation has no chance of succeeding anyways. Suggested-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> --- kernel/bpf/inode.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)