]> git.ipfire.org Git - thirdparty/kernel/linux.git/log
thirdparty/kernel/linux.git
2 weeks agoovl: mark *_cu_creds() as unused temporarily
Christian Brauner [Fri, 14 Nov 2025 22:45:24 +0000 (23:45 +0100)] 
ovl: mark *_cu_creds() as unused temporarily

They will become unused in the next patch and we'll drop them after the
conversion is finished together with the struct. This keeps the changes
small and reviewable.

Link: https://patch.msgid.link/20251114-work-ovl-cred-guard-copyup-v1-3-ea3fb15cf427@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_copy_up_workdir() to cred guard
Christian Brauner [Wed, 19 Nov 2025 19:27:21 +0000 (20:27 +0100)] 
ovl: port ovl_copy_up_workdir() to cred guard

Remove the complicated struct ovl_cu_creds dance and use our new copy up
cred guard.

Link: https://patch.msgid.link/20251114-work-ovl-cred-guard-copyup-v1-2-ea3fb15cf427@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: add copy up credential guard
Christian Brauner [Fri, 14 Nov 2025 22:45:22 +0000 (23:45 +0100)] 
ovl: add copy up credential guard

Add a credential guard for copy up. This will allows us to waste struct
struct ovl_cu_creds and simplify the code.

Link: https://patch.msgid.link/20251114-work-ovl-cred-guard-copyup-v1-1-ea3fb15cf427@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoMerge patch series "ovl: convert creation credential override to cred guard"
Christian Brauner [Mon, 17 Nov 2025 11:03:08 +0000 (12:03 +0100)] 
Merge patch series "ovl: convert creation credential override to cred guard"

Christian Brauner <brauner@kernel.org> says:

This cleans up the creation specific credential override.

The current code to override credentials for creation operations is
pretty difficult to understand as we override the credentials twice:

(1) override with the mounter's credentials
(2) copy the mounts credentials and override the fs{g,u}id with the inode {u,g}id

And then we elide the revert_creds() because it would be an idempotent
revert. That elision doesn't buy us anything anymore though because it's
all reference count less anyway.

The fact that this is done in a function and that the revert is
happening in the original override makes this a lot to grasp.

By introducing a cleanup guard for the creation case we can make this a
lot easier to understand and extremely visually prevalent:

with_ovl_creds(dentry->d_sb) {
scoped_class(prepare_creds_ovl, cred, dentry, inode, mode) {
if (IS_ERR(cred))
return PTR_ERR(cred);

ovl_path_upper(dentry->d_parent, &realparentpath);

/* more stuff you want to do */
}

I think this is a big improvement over what we have now.

* patches from https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-0-bd1c97a36d7b@kernel.org:
  ovl: drop ovl_setup_cred_for_create()
  ovl: port ovl_create_or_link() to new ovl_override_creator_creds cleanup guard
  ovl: mark ovl_setup_cred_for_create() as unused temporarily
  ovl: reflow ovl_create_or_link()
  ovl: port ovl_create_tmpfile() to new ovl_override_creator_creds cleanup guard
  ovl: add ovl_override_creator_creds cred guard

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-0-bd1c97a36d7b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: drop ovl_setup_cred_for_create()
Christian Brauner [Mon, 17 Nov 2025 09:34:43 +0000 (10:34 +0100)] 
ovl: drop ovl_setup_cred_for_create()

It is now unused and can be removed.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-6-bd1c97a36d7b@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_create_or_link() to new ovl_override_creator_creds cleanup guard
Christian Brauner [Mon, 17 Nov 2025 09:34:42 +0000 (10:34 +0100)] 
ovl: port ovl_create_or_link() to new ovl_override_creator_creds cleanup guard

This clearly indicates the double-credential override and makes the code
a lot easier to grasp with one glance.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-5-bd1c97a36d7b@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: mark ovl_setup_cred_for_create() as unused temporarily
Christian Brauner [Mon, 17 Nov 2025 09:34:41 +0000 (10:34 +0100)] 
ovl: mark ovl_setup_cred_for_create() as unused temporarily

The function will become unused in the next patch.
We'll remove it in later patches to keep the diff legible.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-4-bd1c97a36d7b@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: reflow ovl_create_or_link()
Christian Brauner [Mon, 17 Nov 2025 09:34:40 +0000 (10:34 +0100)] 
ovl: reflow ovl_create_or_link()

Reflow the creation routine in preparation of porting it to a guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-3-bd1c97a36d7b@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_create_tmpfile() to new ovl_override_creator_creds cleanup guard
Christian Brauner [Mon, 17 Nov 2025 09:34:39 +0000 (10:34 +0100)] 
ovl: port ovl_create_tmpfile() to new ovl_override_creator_creds cleanup guard

This clearly indicates the double-credential override and makes the code
a lot easier to grasp with one glance.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-2-bd1c97a36d7b@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: add ovl_override_creator_creds cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:38 +0000 (10:34 +0100)] 
ovl: add ovl_override_creator_creds cred guard

The current code to override credentials for creation operations is
pretty difficult to understand. We effectively override the credentials
twice:

(1) override with the mounter's credentials
(2) copy the mounts credentials and override the fs{g,u}id with the inode {u,g}id

And then we elide the revert because it would be an idempotent revert.
That elision doesn't buy us anything anymore though because I've made it
all work without any reference counting anyway. All it does is mix the
two credential overrides together.

We can use a cleanup guard to clarify the creation codepaths and make
them easier to understand.

This just introduces the cleanup guard keeping the patch reviewable.
We'll convert the caller in follow-up patches and then drop the
duplicated code.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-1-bd1c97a36d7b@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoMerge patch series "ovl: convert to cred guard"
Christian Brauner [Mon, 17 Nov 2025 11:01:28 +0000 (12:01 +0100)] 
Merge patch series "ovl: convert to cred guard"

Christian Brauner <brauner@kernel.org> says:

This adds an overlayfs specific extension of the cred guard
infrastructure I introduced. This allows all of overlayfs to be ported
to cred guards. I refactored a few functions to reduce the scope of the
cred guard. I think this is beneficial as it's visually very easy to
grasp the scope in one go. Lightly tested.

* patches from https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-0-b31603935724@kernel.org: (42 commits)
  ovl: remove ovl_revert_creds()
  ovl: port ovl_fill_super() to cred guard
  ovl: refactor ovl_fill_super()
  ovl: port ovl_lower_positive() to cred guard
  ovl: port ovl_lookup() to cred guard
  ovl: refactor ovl_lookup()
  ovl: port ovl_copyfile() to cred guard
  ovl: port ovl_rename() to cred guard
  ovl: refactor ovl_rename()
  ovl: introduce struct ovl_renamedata
  ovl: port ovl_listxattr() to cred guard
  ovl: port ovl_xattr_get() to cred guard
  ovl: port ovl_xattr_set() to cred guard
  ovl: port ovl_nlink_end() to cred guard
  ovl: port ovl_nlink_start() to cred guard
  ovl: port ovl_check_empty_dir() to cred guard
  ovl: port ovl_dir_llseek() to cred guard
  ovl: refactor ovl_iterate() and port to cred guard
  ovl: don't override credentials for ovl_check_whiteouts()
  ovl: port ovl_maybe_lookup_lowerdata() to cred guard
  ...

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-0-b31603935724@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: remove ovl_revert_creds()
Christian Brauner [Mon, 17 Nov 2025 09:34:13 +0000 (10:34 +0100)] 
ovl: remove ovl_revert_creds()

The wrapper isn't needed anymore. Overlayfs completely relies on its
cleanup guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-42-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_fill_super() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:12 +0000 (10:34 +0100)] 
ovl: port ovl_fill_super() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-41-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: refactor ovl_fill_super()
Christian Brauner [Mon, 17 Nov 2025 09:34:11 +0000 (10:34 +0100)] 
ovl: refactor ovl_fill_super()

Split the core into a separate helper in preparation of converting the
caller to the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-40-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_lower_positive() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:10 +0000 (10:34 +0100)] 
ovl: port ovl_lower_positive() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-39-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_lookup() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:09 +0000 (10:34 +0100)] 
ovl: port ovl_lookup() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-38-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: refactor ovl_lookup()
Christian Brauner [Mon, 17 Nov 2025 09:34:08 +0000 (10:34 +0100)] 
ovl: refactor ovl_lookup()

Split the core into a separate helper in preparation of converting the
caller to the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-37-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_copyfile() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:07 +0000 (10:34 +0100)] 
ovl: port ovl_copyfile() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-36-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_rename() to cred guard
Christian Brauner [Wed, 19 Nov 2025 19:53:17 +0000 (20:53 +0100)] 
ovl: port ovl_rename() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-35-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: refactor ovl_rename()
Christian Brauner [Wed, 19 Nov 2025 19:48:38 +0000 (20:48 +0100)] 
ovl: refactor ovl_rename()

Extract the code that runs under overridden credentials into a separate
ovl_rename_upper() helper function and the code that runs before/after to
ovl_rename_start/end(). Error handling is simplified.
The helpers returns errors directly instead of using goto labels.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-34-b31603935724@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: introduce struct ovl_renamedata
Christian Brauner [Wed, 19 Nov 2025 17:50:56 +0000 (18:50 +0100)] 
ovl: introduce struct ovl_renamedata

Add a struct ovl_renamedata to group rename-related state that was
previously stored in local variables. Embedd struct renamedata directly
aligning with the vfs.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-33-b31603935724@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_listxattr() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:03 +0000 (10:34 +0100)] 
ovl: port ovl_listxattr() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-32-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_xattr_get() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:02 +0000 (10:34 +0100)] 
ovl: port ovl_xattr_get() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-31-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_xattr_set() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:01 +0000 (10:34 +0100)] 
ovl: port ovl_xattr_set() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-30-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_nlink_end() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:34:00 +0000 (10:34 +0100)] 
ovl: port ovl_nlink_end() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-29-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_nlink_start() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:59 +0000 (10:33 +0100)] 
ovl: port ovl_nlink_start() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-28-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_check_empty_dir() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:58 +0000 (10:33 +0100)] 
ovl: port ovl_check_empty_dir() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-27-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_dir_llseek() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:57 +0000 (10:33 +0100)] 
ovl: port ovl_dir_llseek() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-26-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: refactor ovl_iterate() and port to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:56 +0000 (10:33 +0100)] 
ovl: refactor ovl_iterate() and port to cred guard

factor out ovl_iterate_merged() and move some code into
ovl_iterate_real() for easier use of the scoped ovl cred guard.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-25-b31603935724@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: don't override credentials for ovl_check_whiteouts()
Christian Brauner [Mon, 17 Nov 2025 09:33:55 +0000 (10:33 +0100)] 
ovl: don't override credentials for ovl_check_whiteouts()

The function is only called when rdd->dentry is non-NULL:

if (!err && rdd->first_maybe_whiteout && rdd->dentry)
    err = ovl_check_whiteouts(realpath, rdd);

| Caller                        | Sets rdd->dentry? | Can call ovl_check_whiteouts()? |
|-------------------------------|-------------------|---------------------------------|
| ovl_dir_read_merged()         | ✓ Yes (line 430)  | ✓ YES                           |
| ovl_dir_read_impure()         | ✗ No              | ✗ NO                            |
| ovl_check_d_type_supported()  | ✗ No              | ✗ NO                            |
| ovl_workdir_cleanup_recurse() | ✗ No              | ✗ NO                            |
| ovl_indexdir_cleanup()        | ✗ No              | ✗ NO                            |

VFS layer (.iterate_shared file operation)
  → ovl_iterate()
      [CRED OVERRIDE]
      → ovl_cache_get()
          → ovl_dir_read_merged()
              → ovl_dir_read()
                  → ovl_check_whiteouts()
      [CRED REVERT]

ovl_unlink()
  → ovl_do_remove()
      → ovl_check_empty_dir()
          [CRED OVERRIDE]
          → ovl_dir_read_merged()
              → ovl_dir_read()
                  → ovl_check_whiteouts()
          [CRED REVERT]

ovl_rename()
  → ovl_check_empty_dir()
      [CRED OVERRIDE]
      → ovl_dir_read_merged()
          → ovl_dir_read()
              → ovl_check_whiteouts()
      [CRED REVERT]

All valid callchains already override credentials so drop the override.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-24-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_maybe_lookup_lowerdata() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:54 +0000 (10:33 +0100)] 
ovl: port ovl_maybe_lookup_lowerdata() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-23-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_maybe_validate_verity() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:53 +0000 (10:33 +0100)] 
ovl: port ovl_maybe_validate_verity() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-22-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_fileattr_get() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:52 +0000 (10:33 +0100)] 
ovl: port ovl_fileattr_get() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-21-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_fileattr_set() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:51 +0000 (10:33 +0100)] 
ovl: port ovl_fileattr_set() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-20-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_fiemap() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:50 +0000 (10:33 +0100)] 
ovl: port ovl_fiemap() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-19-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_set_or_remove_acl() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:49 +0000 (10:33 +0100)] 
ovl: port ovl_set_or_remove_acl() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-18-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port do_ovl_get_acl() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:48 +0000 (10:33 +0100)] 
ovl: port do_ovl_get_acl() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-17-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_get_link() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:47 +0000 (10:33 +0100)] 
ovl: port ovl_get_link() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-16-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_permission() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:46 +0000 (10:33 +0100)] 
ovl: port ovl_permission() to cred guard

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-15-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_getattr() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:45 +0000 (10:33 +0100)] 
ovl: port ovl_getattr() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-14-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_setattr() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:44 +0000 (10:33 +0100)] 
ovl: port ovl_setattr() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-13-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_flush() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:43 +0000 (10:33 +0100)] 
ovl: port ovl_flush() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-12-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_fadvise() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:42 +0000 (10:33 +0100)] 
ovl: port ovl_fadvise() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-11-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_fallocate() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:41 +0000 (10:33 +0100)] 
ovl: port ovl_fallocate() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-10-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_fsync() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:40 +0000 (10:33 +0100)] 
ovl: port ovl_fsync() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-9-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_llseek() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:39 +0000 (10:33 +0100)] 
ovl: port ovl_llseek() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-8-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_open_realfile() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:38 +0000 (10:33 +0100)] 
ovl: port ovl_open_realfile() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-7-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_create_tmpfile() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:37 +0000 (10:33 +0100)] 
ovl: port ovl_create_tmpfile() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-6-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_do_remove() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:36 +0000 (10:33 +0100)] 
ovl: port ovl_do_remove() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-5-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_set_link_redirect() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:35 +0000 (10:33 +0100)] 
ovl: port ovl_set_link_redirect() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-4-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_create_or_link() to cred guard
Christian Brauner [Mon, 17 Nov 2025 09:33:34 +0000 (10:33 +0100)] 
ovl: port ovl_create_or_link() to cred guard

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-3-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: port ovl_copy_up_flags() to cred guards
Christian Brauner [Mon, 17 Nov 2025 09:33:33 +0000 (10:33 +0100)] 
ovl: port ovl_copy_up_flags() to cred guards

Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-2-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoovl: add override_creds cleanup guard extension for overlayfs
Christian Brauner [Mon, 17 Nov 2025 09:33:32 +0000 (10:33 +0100)] 
ovl: add override_creds cleanup guard extension for overlayfs

Overlayfs plucks the relevant creds from the superblock. Extend the
override_creds cleanup class I added to override_creds_ovl which uses
the ovl_override_creds() function as initialization helper. Add
with_ovl_creds() based on this new class.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-1-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoMerge branch 'vfs-6.19.directory.locking' into base.vfs-6.19.ovl
Christian Brauner [Wed, 19 Nov 2025 20:56:47 +0000 (21:56 +0100)] 
Merge branch 'vfs-6.19.directory.locking' into base.vfs-6.19.ovl

Bring in the directory locking changes as they touch overlayfs in a
pretty substantial way and we are about to change the credential
override semantics quite substantially as well.

Signed-off-by: Christian Brauner <brauner@kernel.org>
2 weeks agoMerge branch 'kbuild-6.19.fms.extension'
Christian Brauner [Wed, 19 Nov 2025 20:56:17 +0000 (21:56 +0100)] 
Merge branch 'kbuild-6.19.fms.extension'

Bring in the shared branch with the kbuild tree to enable
'-fms-extensions' for 6.19. The overlayfs cred guard work
depends on this.

Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoMerge patch series "Create and use APIs to centralise locking for directory ops."
Christian Brauner [Fri, 14 Nov 2025 12:16:04 +0000 (13:16 +0100)] 
Merge patch series "Create and use APIs to centralise locking for directory ops."

NeilBrown <neilb@ownmail.net> says:

This series is the next part of my effort to change directory-op
locking to allow multiple concurrent ops in a directory.  Ultimately we
will (in my plan) lock the target dentry(s) rather than the whole
parent directory.

To help with changing the locking protocol, this series centralises
locking and lookup in some helpers.  The various helpers are introduced
and then used in the same patch - roughly one patch per helper though
with various exceptions.

I haven't introduced these helpers into the various filesystems that
Al's tree-in-dcache series is changing.  That series introduces and
uses similar helpers tuned to the specific needs of that set of
filesystems.  Ultimately all the helpers will use the same backends
which can then be adjusted when it is time to change the locking
protocol.

One change that deserves highlighting is in patch 13 where vfs_mkdir()
is changed to unlock the parent on failure, as well as the current
behaviour of dput()ing the dentry on failure.  Once this change is in
place, the final step of both create and an remove sequences only
requires the target dentry, not the parent.  So e.g.  end_creating() is
only given the dentry (which may be IS_ERR() after vfs_mkdir()).  This
helps establish the pattern that it is the dentry that is being locked
and unlocked (the lock is currently held on dentry->d_parent->d_inode,
but that can change).

* patches from https://patch.msgid.link/20251113002050.676694-1-neilb@ownmail.net:
  VFS: introduce end_creating_keep()
  VFS: change vfs_mkdir() to unlock on failure.
  ecryptfs: use new start_creating/start_removing APIs
  Add start_renaming_two_dentries()
  VFS/ovl/smb: introduce start_renaming_dentry()
  VFS/nfsd/ovl: introduce start_renaming() and end_renaming()
  VFS: add start_creating_killable() and start_removing_killable()
  VFS: introduce start_removing_dentry()
  smb/server: use end_removing_noperm for for target of smb2_create_link()
  VFS: introduce start_creating_noperm() and start_removing_noperm()
  VFS/nfsd/cachefiles/ovl: introduce start_removing() and end_removing()
  VFS/nfsd/cachefiles/ovl: add start_creating() and end_creating()
  VFS: tidy up do_unlinkat()
  VFS: introduce start_dirop() and end_dirop()
  debugfs: rename end_creating() to debugfs_end_creating()

Link: https://patch.msgid.link/20251113002050.676694-1-neilb@ownmail.net
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS: introduce end_creating_keep()
NeilBrown [Thu, 13 Nov 2025 00:18:38 +0000 (11:18 +1100)] 
VFS: introduce end_creating_keep()

Occasionally the caller of end_creating() wants to keep using the dentry.
Rather then requiring them to dget() the dentry (when not an error)
before calling end_creating(), provide end_creating_keep() which does
this.

cachefiles and overlayfs make use of this.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-16-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS: change vfs_mkdir() to unlock on failure.
NeilBrown [Thu, 13 Nov 2025 00:18:37 +0000 (11:18 +1100)] 
VFS: change vfs_mkdir() to unlock on failure.

vfs_mkdir() already drops the reference to the dentry on failure but it
leaves the parent locked.
This complicates end_creating() which needs to unlock the parent even
though the dentry is no longer available.

If we change vfs_mkdir() to unlock on failure as well as releasing the
dentry, we can remove the "parent" arg from end_creating() and simplify
the rules for calling it.

Note that cachefiles_get_directory() can choose to substitute an error
instead of actually calling vfs_mkdir(), for fault injection.  In that
case it needs to call end_creating(), just as vfs_mkdir() now does on
error.

ovl_create_real() will now unlock on error.  So the conditional
end_creating() after the call is removed, and end_creating() is called
internally on error.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-15-neilb@ownmail.net
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoecryptfs: use new start_creating/start_removing APIs
NeilBrown [Thu, 13 Nov 2025 00:18:36 +0000 (11:18 +1100)] 
ecryptfs: use new start_creating/start_removing APIs

This requires the addition of start_creating_dentry() which is given the
dentry which has already been found, and asks for it to be locked and
its parent validated.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-14-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoAdd start_renaming_two_dentries()
NeilBrown [Thu, 13 Nov 2025 00:18:35 +0000 (11:18 +1100)] 
Add start_renaming_two_dentries()

A few callers want to lock for a rename and already have both dentries.
Also debugfs does want to perform a lookup but doesn't want permission
checking, so start_renaming_dentry() cannot be used.

This patch introduces start_renaming_two_dentries() which is given both
dentries.  debugfs performs one lookup itself.  As it will only continue
with a negative dentry and as those cannot be renamed or unlinked, it is
safe to do the lookup before getting the rename locks.

overlayfs uses start_renaming_two_dentries() in three places and  selinux
uses it twice in sel_make_policy_nodes().

In sel_make_policy_nodes() we now lock for rename twice instead of just
once so the combined operation is no longer atomic w.r.t the parent
directory locks.  As selinux_state.policy_mutex is held across the whole
operation this does not open up any interesting races.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-13-neilb@ownmail.net
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS/ovl/smb: introduce start_renaming_dentry()
NeilBrown [Thu, 13 Nov 2025 00:18:34 +0000 (11:18 +1100)] 
VFS/ovl/smb: introduce start_renaming_dentry()

Several callers perform a rename on a dentry they already have, and only
require lookup for the target name.  This includes smb/server and a few
different places in overlayfs.

start_renaming_dentry() performs the required lookup and takes the
required lock using lock_rename_child()

It is used in three places in overlayfs and in ksmbd_vfs_rename().

In the ksmbd case, the parent of the source is not important - the
source must be renamed from wherever it is.  So start_renaming_dentry()
allows rd->old_parent to be NULL and only checks it if it is non-NULL.
On success rd->old_parent will be the parent of old_dentry with an extra
reference taken.  Other start_renaming function also now take the extra
reference and end_renaming() now drops this reference as well.

ovl_lookup_temp(), ovl_parent_lock(), and ovl_parent_unlock() are
all removed as they are no longer needed.

OVL_TEMPNAME_SIZE and ovl_tempname() are now declared in overlayfs.h so
that ovl_check_rename_whiteout() can access them.

ovl_copy_up_workdir() now always cleans up on error.

Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-12-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS/nfsd/ovl: introduce start_renaming() and end_renaming()
NeilBrown [Thu, 13 Nov 2025 00:18:33 +0000 (11:18 +1100)] 
VFS/nfsd/ovl: introduce start_renaming() and end_renaming()

start_renaming() combines name lookup and locking to prepare for rename.
It is used when two names need to be looked up as in nfsd and overlayfs -
cases where one or both dentries are already available will be handled
separately.

__start_renaming() avoids the inode_permission check and hash
calculation and is suitable after filename_parentat() in do_renameat2().
It subsumes quite a bit of code from that function.

start_renaming() does calculate the hash and check X permission and is
suitable elsewhere:
- nfsd_rename()
- ovl_rename()

In ovl, ovl_do_rename_rd() is factored out of ovl_do_rename(), which
itself will be gone by the end of the series.

Acked-by: Chuck Lever <chuck.lever@oracle.com> (for nfsd parts)
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: NeilBrown <neil@brown.name>
--
Changes since v3:
 - added missig dput() in ovl_rename when "whiteout" is not-NULL.

Changes since v2:
 - in __start_renaming() some label have been renamed, and err
   is always set before a "goto out_foo" rather than passing the
   error in a dentry*.
 - ovl_do_rename() changed to call the new ovl_do_rename_rd() rather
   than keeping duplicate code
 - code around ovl_cleanup() call in ovl_rename() restructured.

Link: https://patch.msgid.link/20251113002050.676694-11-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Acked-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS: add start_creating_killable() and start_removing_killable()
NeilBrown [Thu, 13 Nov 2025 00:18:32 +0000 (11:18 +1100)] 
VFS: add start_creating_killable() and start_removing_killable()

These are similar to start_creating() and start_removing(), but allow a
fatal signal to abort waiting for the lock.

They are used in btrfs for subvol creation and removal.

btrfs_may_create() no longer needs IS_DEADDIR() and
start_creating_killable() includes that check.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-10-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS: introduce start_removing_dentry()
NeilBrown [Thu, 13 Nov 2025 00:18:31 +0000 (11:18 +1100)] 
VFS: introduce start_removing_dentry()

start_removing_dentry() is similar to start_removing() but instead of
providing a name for lookup, the target dentry is given.

start_removing_dentry() checks that the dentry is still hashed and in
the parent, and if so it locks and increases the refcount so that
end_removing() can be used to finish the operation.

This is used in cachefiles, overlayfs, smb/server, and apparmor.

There will be other users including ecryptfs.

As start_removing_dentry() takes an extra reference to the dentry (to be
put by end_removing()), there is no need to explicitly take an extra
reference to stop d_delete() from using dentry_unlink_inode() to negate
the dentry - as in cachefiles_delete_object(), and ksmbd_vfs_unlink().

cachefiles_bury_object() now gets an extra ref to the victim, which is
drops.  As it includes the needed end_removing() calls, the caller
doesn't need them.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-9-neilb@ownmail.net
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agosmb/server: use end_removing_noperm for for target of smb2_create_link()
NeilBrown [Thu, 13 Nov 2025 00:18:30 +0000 (11:18 +1100)] 
smb/server: use end_removing_noperm for for target of smb2_create_link()

Sometimes smb2_create_link() needs to remove the target before creating
the link.
It uses ksmbd_vfs_kern_locked(), and is the only user of that interface.

To match the new naming, that function is changed to
ksmbd_vfs_kern_start_removing(), and related functions or flags are also
renamed.

The lock actually happens in ksmbd_vfs_path_lookup() and that is changed
to use start_removing_noperm() - permission to perform lookup in the
parent was already checked in vfs_path_parent_lookup().

Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-8-neilb@ownmail.net
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS: introduce start_creating_noperm() and start_removing_noperm()
NeilBrown [Thu, 13 Nov 2025 00:18:29 +0000 (11:18 +1100)] 
VFS: introduce start_creating_noperm() and start_removing_noperm()

xfs, fuse, ipc/mqueue need variants of start_creating or start_removing
which do not check permissions.
This patch adds _noperm versions of these functions.

Note that do_mq_open() was only calling mntget() so it could call
path_put() - it didn't really need an extra reference on the mnt.
Now it doesn't call mntget() and uses end_creating() which does
the dput() half of path_put().

Also mq_unlink() previously passed
   d_inode(dentry->d_parent)
as the dir inode to vfs_unlink().  This is after locking
   d_inode(mnt->mnt_root)
These two inodes are the same, but normally calls use the textual
parent.
So I've changes the vfs_unlink() call to be given d_inode(mnt->mnt_root).

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
--
changes since v2:
 - dir arg passed to vfs_unlink() in mq_unlink() changed to match
   the dir passed to lookup_noperm()
 - restore assignment to path->mnt even though the mntget() is removed.

Link: https://patch.msgid.link/20251113002050.676694-7-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS/nfsd/cachefiles/ovl: introduce start_removing() and end_removing()
NeilBrown [Thu, 13 Nov 2025 00:18:28 +0000 (11:18 +1100)] 
VFS/nfsd/cachefiles/ovl: introduce start_removing() and end_removing()

start_removing() is similar to start_creating() but will only return a
positive dentry with the expectation that it will be removed.  This is
used by nfsd, cachefiles, and overlayfs.  They are changed to also use
end_removing() to terminate the action begun by start_removing().  This
is a simple alias for end_dirop().

Apart from changes to the error paths, as we no longer need to unlock on
a lookup error, an effect on callers is that they don't need to test if
the found dentry is positive or negative - they can be sure it is
positive.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-6-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS/nfsd/cachefiles/ovl: add start_creating() and end_creating()
NeilBrown [Thu, 13 Nov 2025 00:18:27 +0000 (11:18 +1100)] 
VFS/nfsd/cachefiles/ovl: add start_creating() and end_creating()

start_creating() is similar to simple_start_creating() but is not so
simple.
It takes a qstr for the name, includes permission checking, and does NOT
report an error if the name already exists, returning a positive dentry
instead.

This is currently used by nfsd, cachefiles, and overlayfs.

end_creating() is called after the dentry has been used.
end_creating() drops the reference to the dentry as it is generally no
longer needed.  This is exactly the first section of end_creating_path()
so that function is changed to call the new end_creating()

These calls help encapsulate locking rules so that directory locking can
be changed.

Occasionally this change means that the parent lock is held for a
shorter period of time, for example in cachefiles_commit_tmpfile().
As this function now unlocks after an unlink and before the following
lookup, it is possible that the lookup could again find a positive
dentry, so a while loop is introduced there.

In overlayfs the ovl_lookup_temp() function has ovl_tempname()
split out to be used in ovl_start_creating_temp().  The other use
of ovl_lookup_temp() is preparing for a rename.  When rename handling
is updated, ovl_lookup_temp() will be removed.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-5-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS: tidy up do_unlinkat()
NeilBrown [Thu, 13 Nov 2025 00:18:26 +0000 (11:18 +1100)] 
VFS: tidy up do_unlinkat()

The simplification of locking in the previous patch opens up some room
for tidying up do_unlinkat()

- change all "exit" labels to describe what will happen at the label.
- always goto an exit label on an error - unwrap the "if (!IS_ERR())" branch.
- Move the "slashes" handing inline, but mark it as unlikely()
- simplify use of the "inode" variable - we no longer need to test for NULL.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-4-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoVFS: introduce start_dirop() and end_dirop()
NeilBrown [Thu, 13 Nov 2025 00:18:25 +0000 (11:18 +1100)] 
VFS: introduce start_dirop() and end_dirop()

The fact that directory operations (create,remove,rename) are protected
by a lock on the parent is known widely throughout the kernel.
In order to change this - to instead lock the target dentry  - it is
best to centralise this knowledge so it can be changed in one place.

This patch introduces start_dirop() which is local to VFS code.
It performs the required locking for create and remove.  Rename
will be handled separately.

Various functions with names like start_creating() or start_removing_path(),
some of which already exist, will export this functionality beyond the VFS.

end_dirop() is the partner of start_dirop().  It drops the lock and
releases the reference on the dentry.
It *is* exported so that various end_creating etc functions can be inline.

As vfs_mkdir() drops the dentry on error we cannot use end_dirop() as
that won't unlock when the dentry IS_ERR().  For now we need an explicit
unlock when dentry IS_ERR().  I hope to change vfs_mkdir() to unlock
when it drops a dentry so that explicit unlock can go away.

end_dirop() can always be called on the result of start_dirop(), but not
after vfs_mkdir().  After a vfs_mkdir() we still may need the explicit
unlock as seen in end_creating_path().

As well as adding start_dirop() and end_dirop()
this patch uses them in:
 - simple_start_creating (which requires sharing lookup_noperm_common()
        with libfs.c)
 - start_removing_path / start_removing_user_path_at
 - filename_create / end_creating_path()
 - do_rmdir(), do_unlinkat()

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-3-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agodebugfs: rename end_creating() to debugfs_end_creating()
NeilBrown [Thu, 13 Nov 2025 00:18:24 +0000 (11:18 +1100)] 
debugfs: rename end_creating() to debugfs_end_creating()

By not using the generic end_creating() name here we are free to use it
more globally for a more generic function.
This should have been done when start_creating() was renamed.

For consistency, also rename failed_creating().

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20251113002050.676694-2-neilb@ownmail.net
Tested-by: syzbot@syzkaller.appspotmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
3 weeks agoMerge patch "kbuild: Add '-fms-extensions' to areas with dedicated CFLAGS"
Christian Brauner [Mon, 10 Nov 2025 09:38:07 +0000 (10:38 +0100)] 
Merge patch "kbuild: Add '-fms-extensions' to areas with dedicated CFLAGS"

Nathan Chancellor <nathan@kernel.org> says:

Shared branch between Kbuild and other trees for enabling
'-fms-extensions' for 6.19.

* tag 'kbuild-ms-extensions-6.19' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/kbuild/linux:
  kbuild: Add '-fms-extensions' to areas with dedicated CFLAGS
  Kbuild: enable -fms-extensions
  jfs: Rename _inline to avoid conflict with clang's '-fms-extensions'

Link: https://patch.msgid.link/20251101-kbuild-ms-extensions-dedicated-cflags-v1-1-38004aba524b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agoMerge patch series "credential guards: credential preparation"
Christian Brauner [Mon, 3 Nov 2025 21:44:50 +0000 (22:44 +0100)] 
Merge patch series "credential guards: credential preparation"

Christian Brauner <brauner@kernel.org> says:

This converts most users combining

* prepare_creds()
* modify new creds
* override_creds()
* revert_creds()
* put_cred()

to rely on credentials guards.

* patches from https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-0-b447b82f2c9b@kernel.org:
  trace: use override credential guard
  trace: use prepare credential guard
  coredump: use override credential guard
  coredump: use prepare credential guard
  coredump: split out do_coredump() from vfs_coredump()
  coredump: mark struct mm_struct as const
  coredump: pass struct linux_binfmt as const
  coredump: move revert_cred() before coredump_cleanup()
  sev-dev: use override credential guards
  sev-dev: use prepare credential guard
  sev-dev: use guard for path
  cred: add prepare credential guard

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-0-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agotrace: use override credential guard
Christian Brauner [Mon, 3 Nov 2025 14:57:38 +0000 (15:57 +0100)] 
trace: use override credential guard

Use override credential guards for scoped credential override with
automatic restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-12-b447b82f2c9b@kernel.org
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agotrace: use prepare credential guard
Christian Brauner [Mon, 3 Nov 2025 14:57:37 +0000 (15:57 +0100)] 
trace: use prepare credential guard

Use the prepare credential guard for allocating a new set of
credentials.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-11-b447b82f2c9b@kernel.org
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocoredump: use override credential guard
Christian Brauner [Mon, 3 Nov 2025 14:57:36 +0000 (15:57 +0100)] 
coredump: use override credential guard

Use override credential guards for scoped credential override with
automatic restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-10-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocoredump: use prepare credential guard
Christian Brauner [Mon, 3 Nov 2025 14:57:35 +0000 (15:57 +0100)] 
coredump: use prepare credential guard

Use the prepare credential guard for allocating a new set of
credentials.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-9-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocoredump: split out do_coredump() from vfs_coredump()
Christian Brauner [Mon, 3 Nov 2025 14:57:34 +0000 (15:57 +0100)] 
coredump: split out do_coredump() from vfs_coredump()

Make the function easier to follow and prepare for some of the following
changes.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-8-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocoredump: mark struct mm_struct as const
Christian Brauner [Mon, 3 Nov 2025 14:57:33 +0000 (15:57 +0100)] 
coredump: mark struct mm_struct as const

We don't actually modify it.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-7-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocoredump: pass struct linux_binfmt as const
Christian Brauner [Mon, 3 Nov 2025 14:57:32 +0000 (15:57 +0100)] 
coredump: pass struct linux_binfmt as const

We don't actually modify it.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-6-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocoredump: move revert_cred() before coredump_cleanup()
Christian Brauner [Mon, 3 Nov 2025 14:57:31 +0000 (15:57 +0100)] 
coredump: move revert_cred() before coredump_cleanup()

There's no need to pin the credentials across the coredump_cleanup()
call. Nothing in there depends on elevated credentials.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-5-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agosev-dev: use override credential guards
Christian Brauner [Mon, 3 Nov 2025 14:57:30 +0000 (15:57 +0100)] 
sev-dev: use override credential guards

Use override credential guards for scoped credential override with
automatic restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-4-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agosev-dev: use prepare credential guard
Christian Brauner [Mon, 3 Nov 2025 14:57:29 +0000 (15:57 +0100)] 
sev-dev: use prepare credential guard

Use the prepare credential guard for allocating a new set of
credentials.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-3-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agosev-dev: use guard for path
Christian Brauner [Mon, 3 Nov 2025 14:57:28 +0000 (15:57 +0100)] 
sev-dev: use guard for path

Just use a guard and also move the path_put() out of the credential
change's scope. There's no need to do this with the overridden
credentials.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-2-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocred: add prepare credential guard
Christian Brauner [Mon, 3 Nov 2025 14:57:27 +0000 (15:57 +0100)] 
cred: add prepare credential guard

A lot of code uses the following pattern:

* prepare new credentials
* modify them for their use-case
* drop them

Support that easier with the new guard infrastructure.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-1-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agoMerge patch series "credentials guards: the easy cases"
Christian Brauner [Mon, 3 Nov 2025 21:42:45 +0000 (22:42 +0100)] 
Merge patch series "credentials guards: the easy cases"

Christian Brauner <brauner@kernel.org> says:

This converts all users of override_creds() to rely on credentials
guards. Leave all those that do the prepare_creds() + modify creds +
override_creds() dance alone for now. Some of them qualify for their own
variant.

* patches from https://patch.msgid.link/20251103-work-creds-guards-simple-v1-0-a3e156839e7f@kernel.org:
  net/dns_resolver: use credential guards in dns_query()
  cgroup: use credential guards in cgroup_attach_permissions()
  act: use credential guards in acct_write_process()
  smb: use credential guards in cifs_get_spnego_key()
  nfs: use credential guards in nfs_idmap_get_key()
  nfs: use credential guards in nfs_local_call_write()
  nfs: use credential guards in nfs_local_call_read()
  erofs: use credential guards
  binfmt_misc: use credential guards
  backing-file: use credential guards for mmap
  backing-file: use credential guards for splice write
  backing-file: use credential guards for splice read
  backing-file: use credential guards for writes
  backing-file: use credential guards for reads
  aio: use credential guards
  cred: add {scoped_}with_creds() guards

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-0-a3e156839e7f@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agonet/dns_resolver: use credential guards in dns_query()
Christian Brauner [Mon, 3 Nov 2025 11:27:04 +0000 (12:27 +0100)] 
net/dns_resolver: use credential guards in dns_query()

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-16-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agocgroup: use credential guards in cgroup_attach_permissions()
Christian Brauner [Mon, 3 Nov 2025 11:27:03 +0000 (12:27 +0100)] 
cgroup: use credential guards in cgroup_attach_permissions()

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-15-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agoact: use credential guards in acct_write_process()
Christian Brauner [Mon, 3 Nov 2025 11:27:02 +0000 (12:27 +0100)] 
act: use credential guards in acct_write_process()

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-14-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agosmb: use credential guards in cifs_get_spnego_key()
Christian Brauner [Mon, 3 Nov 2025 11:27:01 +0000 (12:27 +0100)] 
smb: use credential guards in cifs_get_spnego_key()

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-13-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agonfs: use credential guards in nfs_idmap_get_key()
Christian Brauner [Mon, 3 Nov 2025 11:27:00 +0000 (12:27 +0100)] 
nfs: use credential guards in nfs_idmap_get_key()

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-12-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agonfs: use credential guards in nfs_local_call_write()
Christian Brauner [Mon, 3 Nov 2025 11:26:59 +0000 (12:26 +0100)] 
nfs: use credential guards in nfs_local_call_write()

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-11-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agonfs: use credential guards in nfs_local_call_read()
Christian Brauner [Mon, 3 Nov 2025 11:26:58 +0000 (12:26 +0100)] 
nfs: use credential guards in nfs_local_call_read()

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-10-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agoerofs: use credential guards
Christian Brauner [Mon, 3 Nov 2025 11:26:57 +0000 (12:26 +0100)] 
erofs: use credential guards

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-9-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agobinfmt_misc: use credential guards
Christian Brauner [Mon, 3 Nov 2025 11:26:56 +0000 (12:26 +0100)] 
binfmt_misc: use credential guards

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-8-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agobacking-file: use credential guards for mmap
Christian Brauner [Mon, 3 Nov 2025 11:26:55 +0000 (12:26 +0100)] 
backing-file: use credential guards for mmap

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-7-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agobacking-file: use credential guards for splice write
Christian Brauner [Mon, 3 Nov 2025 11:26:54 +0000 (12:26 +0100)] 
backing-file: use credential guards for splice write

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-6-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agobacking-file: use credential guards for splice read
Christian Brauner [Mon, 3 Nov 2025 11:26:53 +0000 (12:26 +0100)] 
backing-file: use credential guards for splice read

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-5-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agobacking-file: use credential guards for writes
Christian Brauner [Mon, 3 Nov 2025 11:26:52 +0000 (12:26 +0100)] 
backing-file: use credential guards for writes

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-4-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
4 weeks agobacking-file: use credential guards for reads
Christian Brauner [Mon, 3 Nov 2025 11:26:51 +0000 (12:26 +0100)] 
backing-file: use credential guards for reads

Use credential guards for scoped credential override with automatic
restoration on scope exit.

Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-3-a3e156839e7f@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>