Skip to content

Commit

Permalink
userns and mnt_idmap leak in open_tree_attr(2)
Browse files Browse the repository at this point in the history
[ Upstream commit 0748e55 ]

Once want_mount_setattr() has returned a positive, it does require
finish_mount_kattr() to release ->mnt_userns.  Failing do_mount_setattr()
does not change that.

As the result, we can end up leaking userns and possibly mnt_idmap as
well.

Fixes: c4a1682 ("fs: add open_tree_attr()")
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Al Viro authored and Greg Kroah-Hartman committed Jul 6, 2025
1 parent d01042e commit 142db4e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -5307,16 +5307,12 @@ SYSCALL_DEFINE5(open_tree_attr, int, dfd, const char __user *, filename,
kattr.kflags |= MOUNT_KATTR_RECURSE;

ret = wants_mount_setattr(uattr, usize, &kattr);
if (ret < 0)
return ret;

if (ret) {
if (ret > 0) {
ret = do_mount_setattr(&file->f_path, &kattr);
if (ret)
return ret;

finish_mount_kattr(&kattr);
}
if (ret)
return ret;
}

fd = get_unused_fd_flags(flags & O_CLOEXEC);
Expand Down

0 comments on commit 142db4e

Please sign in to comment.