Skip to content

Commit

Permalink
fs/mount_setattr: always cleanup mount_kattr
Browse files Browse the repository at this point in the history
Make sure that finish_mount_kattr() is called after mount_kattr was
succesfully built in both the success and failure case to prevent
leaking any references we took when we built it.  We returned early if
path lookup failed thereby risking to leak an additional reference we
took when building mount_kattr when an idmapped mount was requested.

Cc: [email protected]
Cc: [email protected]
Fixes: 9caccd4 ("fs: introduce MOUNT_ATTR_IDMAP")
Signed-off-by: Christian Brauner <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Christian Brauner authored and torvalds committed Dec 30, 2021
1 parent 74c78b4 commit 012e332
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4263,12 +4263,11 @@ SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,
return err;

err = user_path_at(dfd, path, kattr.lookup_flags, &target);
if (err)
return err;

err = do_mount_setattr(&target, &kattr);
if (!err) {
err = do_mount_setattr(&target, &kattr);
path_put(&target);
}
finish_mount_kattr(&kattr);
path_put(&target);
return err;
}

Expand Down

0 comments on commit 012e332

Please sign in to comment.