overlayfs updates for 6.13
Subsystems (21)
Amir Goldstein
maintainerHi Linus,
Please pull overlayfs updates for 6.13.
This pull request has some changes in code outside of fs/overlayfs:
1. The backing_file API change touches fuse code - that was collaborated with Miklos who authored this API change
2. The additions of revert/override_creds_light() helpers in cred.{h,c} were collaborated with Christian who has suggested those helpers
There was also an overlayfs change in this cycle coming from Christian (file descriptors based layer setup). His changes do not conflict with this branch and I have also tested his change along with the fs-next community test branch.
Most of this branch has been sitting in linux-next for over a week except for one syzbot issue fix that was added three days ago.
The code has gone through the usual overlayfs test routines.
The branch merges cleanly with master branch of the moment.
Thanks,
Amir.
----------------------------------------------------------------
The following changes since commit 2d5404caa8c7bb5c4e0435f94b28834ae5456623:
Linux 6.12-rc7 (2024-11-10 14:19:35 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git ovl-update-6.13
for you to fetch changes up to c8b359dddb418c60df1a69beea01d1b3322bfe83:
ovl: Filter invalid inodes with missing lookup function (2024-11-20 10:23:04 +0100)
----------------------------------------------------------------
overlayfs updates for 6.13
- Fix a syzbot reported NULL pointer deref with bfs lower layers
- Fix a copy up failure of large file from lower fuse fs
- Followup cleanup of backing_file API from Miklos
- Introduction and use of revert/override_creds_light() helpers, that were suggested by Christian as a mitigation to cache line bouncing and false sharing of fields in overlayfs creator_cred long lived struct cred copy.
- Store up to two backing file references (upper and lower) in an ovl_file container instead of storing a single backing file in file->private_data.
This is used to avoid the practice of opening a short lived backing file for the duration of some file operations and to avoid the specialized use of FDPUT_FPUT in such occasions, that was getting in the way of Al's fd_file() conversions.
----------------------------------------------------------------
Amir Goldstein (6):
ovl: pass an explicit reference of creators creds to callers
ovl: do not open non-data lower file for fsync
ovl: allocate a container struct ovl_file for ovl private context
ovl: store upper real file in ovl_file struct
ovl: convert ovl_real_fdget_path() callers to ovl_real_file_path()
ovl: convert ovl_real_fdget() callers to ovl_real_file()
Miklos Szeredi (1):
backing-file: clean up the API
Oleksandr Tymoshenko (1):
ovl: properly handle large files in ovl_security_fileattr
Vasiliy Kovalev (1):
ovl: Filter invalid inodes with missing lookup function
Vinicius Costa Gomes (4):
cred: Add a light version of override/revert_creds() fs/backing-file: Convert to revert/override_creds_light()
ovl: use wrapper ovl_revert_creds()
ovl: Optimize override/revert creds
fs/backing-file.c | 53 ++++--- fs/fuse/passthrough.c | 32 +++-- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/dir.c | 68 ++++++--- fs/overlayfs/file.c | 327 +++++++++++++++++++++++++------------------ fs/overlayfs/inode.c | 27 ++-- fs/overlayfs/namei.c | 10 +- fs/overlayfs/overlayfs.h | 4 + fs/overlayfs/readdir.c | 8 +- fs/overlayfs/util.c | 14 +- fs/overlayfs/xattrs.c | 9 +- include/linux/backing-file.h | 11 +- include/linux/cred.h | 18 +++ kernel/cred.c | 6 +- 14 files changed, 352 insertions(+), 237 deletions(-)
Quoted 4 lines · Amir Goldstein
- Introduction and use of revert/override_creds_light() helpers, that were suggested by Christian as a mitigation to cache line bouncing and false sharing of fields in overlayfs
creator_credlong lived struct cred copy.
So I don't actively hate this, but I do wonder if this shouldn't have been done differently.
In particular, I suspect *most* users of override_creds() actually wants this "light" version, because they all already hold a ref to the cred that they want to use as the override.
We did it that safe way with the extra refcount not because most people would need it, but it was expected to not be a big deal.
Now you found that it *is* a big deal, and instead of just fixing the old interface, you create a whole new interface and the mental burden of having to know the difference between the two.
So may I ask that you look at perhaps just converting the (not very many) users of the non-light cred override to the "light" version?
Because I suspect you will find that they basically *all* convert. I wouldn't be surprised if some of them could convert automatically with a coccinelle script.
Because we actually have several users that have a pattern line
old_cred = override_creds(override_cred);
/* override_cred() gets its own ref */
put_cred(override_cred);because it *didn't* want the new cred, because it's literally a temporary cred that already had the single ref it needed, and the code actually it wants it to go away when it does
revert_creds(old_cred);
End result: I suspect what it *really* would have wanted is basically to have 'override_creds()' not do the refcount at all, and at revert time, it would want "revert_creds()" to return the creds that got reverted, and then it would just do
old_cred = override_creds(override_cred);
...
put_cred(revert_creds(old_cred));instead - which would not change the refcount on 'old_cred' at all at any time (and does it for the override case only at the end when it actually wants it free'd).
And the above is very annoyingly *almost* exactly what your "light" interface does, except your interface is bad too: it doesn't return the reverted creds.
So then users have to remember the override_creds *and* the old creds, just to do their own cred refcounting outside of this all.
In other words, what I really dislike about this all is that
(a) we had a flawed interface
(b) you added *another* flawed interface for one special case you cared about
(c) now we have *two* flawed interfaces instead of one better one
Hmm?
Linus
Quoted 3 lines · Linus Torvalds
So I don't actively hate this, but I do wonder if this shouldn't have been done differently.
Just to clarify: because I understand *why* you wanted this, and because I don't hate it with a passion, I have pulled your changes.
But I really think we could and should do better. Please?
Linus
The pull request you sent on Fri, 22 Nov 2024 10:57:46 +0100:
The pull request you sent on Fri, 22 Nov 2024 10:57:46 +0100:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.gitovl-update-6.13
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/e7675238b9bf4db0b872d5dbcd53efa31914c98f
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html
Quoted 3 lines · Linus Torvalds
So may I ask that you look at perhaps just converting the (not very many) users of the non-light cred override to the "light" version?
I think you could do a completely automated conversion:
(a) add a new "dup_cred()" helper
/* Get the cred without clearing the 'non_rcu' flag */
const struct cred *dup_cred(const struct cred *cred)
{ get_new_cred((struct cred *)cred); return cred; }(b) mindlessly convert:
override_creds(cred) -> override_creds_light(dup_cred(cred))
revert_creds(cred) -> put_cred(revert_creds_light(old)); (c) rename away the "_light" again:
override_creds_light -> override_creds
revert_creds_light -> revert_credsand then finally the only non-automated part would be
(d) simplify any obvious and trivial dup_cred -> put_cred chains.
which might take some effort, but there should be at least a couple of really obvious cases of "that's not necessary".
Because honestly, I think I'd rather see a few cases of
old_creds = override_creds(dup_cred(cred));
...
put_cred(revert_creds(old));that look a bit more complicated, and couldn't be trivially simplified away.
That seems better than the current case of having two very different forms of override_creds() / put_cred() where people have to know deeply when to use one or the other.
No?
Linus
Al Viro
maintainerQuoted 5 lines · Linus Torvalds
(a) add a new "
dup_cred()" helper/* Get the cred without clearing the 'non_rcu' flag */ const struct cred *dup_cred(const struct cred *cred) { get_new_cred((struct cred *)cred); return cred; }
Umm... Something like hold_cred() might be better - dup usually implies copying an object... For grapping a reference we normally go for something like hold/get/grab/pin...
Christian Brauner
maintainerQuoted 16 lines · Linus Torvalds
Quoted 4 lines · Amir Goldstein
- Introduction and use of revert/override_creds_light() helpers, that were suggested by Christian as a mitigation to cache line bouncing and false sharing of fields in overlayfs
creator_credlong lived struct cred copy.So I don't actively hate this, but I do wonder if this shouldn't have been done differently.
In particular, I suspect *most* users of
override_creds()actually wants this "light" version, because they all already hold a ref to the cred that they want to use as the override.We did it that safe way with the extra refcount not because most people would need it, but it was expected to not be a big deal.
Quoted 6 lines
Now you found that it *is* a big deal, and instead of just fixing the old interface, you create a whole new interface and the mental burden of having to know the difference between the two.
So may I ask that you look at perhaps just converting the (not very many) users of the non-light cred override to the "light" version?
I think that could be a good idea in general.
But I have to say I'm feeling a bit defensive after having read your message even though I usually try not to. :)
So just to clarify when that issue was brought up I realized that the cred bump was a big deal for overlayfs but from a quick grep I didn't think for any of the other cases it really mattered that much.
Realistically, overlayfs is the prime example where that override cred matters big time because it's called everywhere and in all core operations one can think of. But so far I at least haven't heard complaints outside of that and so the immediate focus was to bring about a solution for overlayfs.
The reason the revert_creds_light() variant doesn't return the old creds is so that callers don't put_cred() them blindly.
Because for overlayfs (and from a quick glance io_uring and nfs) the refcount for the temporary creds is kept completely independent of the callsites.
The lifetime is bound to the superblock and so the final put on the temporary creds has nothing to do with the callers at all.
Quoted 11 lines · Al Viro
Quoted 5 lines · Linus Torvalds
(a) add a new "
dup_cred()" helper/* Get the cred without clearing the 'non_rcu' flag */ const struct cred *dup_cred(const struct cred *cred) { get_new_cred((struct cred *)cred); return cred; }Umm... Something like
hold_cred()might be better - dup usually implies copying an object...
Ack. "dup" is clearly a horrible name, and I'm ashamed and properly chastised.
Linus
Quoted 4 lines · Christian Brauner
So just to clarify when that issue was brought up I realized that the cred bump was a big deal for overlayfs but from a quick grep I didn't think for any of the other cases it really mattered that much.
Oh, I agree. It's probably not really a performance issue anywhere else. I don't think this has really ever come up before.
So my "please convert everything to one single new model" is not because I think that would help performance, but because I really hate having two differently flawed models when I think one would do.
We have other situations where we really do have two or more different interfaces for the "same" thing, with very special rules: things like fget() vs fget_raw() vs fget_task() (and similar issues wrt fdget).
But I think those other situations have more _reason_ for them.
The whole "override_creds()" thing is _already_ such a special operation, that I hate seeing two subtly different versions of the interface, both with their own quirks.
Because the old interface really isn't some "perfectly tailored" thing. Yes, the performance implications were a surprise to me and I hadn't seen that before, but the "refcounting isn't wonderful" was _not_ really a big surprise at all.
Linus
Christian Brauner
maintainerQuoted 21 lines · Christian Brauner
Quoted 19 lines · Linus Torvalds
Quoted 4 lines · Amir Goldstein
- Introduction and use of revert/override_creds_light() helpers, that were suggested by Christian as a mitigation to cache line bouncing and false sharing of fields in overlayfs
creator_credlong lived struct cred copy.So I don't actively hate this, but I do wonder if this shouldn't have been done differently.
In particular, I suspect *most* users of
override_creds()actually wants this "light" version, because they all already hold a ref to the cred that they want to use as the override.We did it that safe way with the extra refcount not because most people would need it, but it was expected to not be a big deal.
Now you found that it *is* a big deal, and instead of just fixing the old interface, you create a whole new interface and the mental burden of having to know the difference between the two.
Quoted 7 lines
Quoted 2 lines
So may I ask that you look at perhaps just converting the (not very many) users of the non-light cred override to the "light" version?
I think that could be a good idea in general.
But I have to say I'm feeling a bit defensive after having read your message even though I usually try not to. :)
It was just pointed out to me that this was written like I'm not reading you messages - which is obviously not the case. What I means it that I usually try to not be defensive when valid criticism is brought up. :)
Christian Brauner
maintainercover cred: rework {override,revert}_creds()
In reply to Linus TorvaldsFor the v6.13 cycle we switched overlayfs to a variant of override_creds() that doesn't take an extra reference. To this end I suggested introducing {override,revert}_creds_light() which overlayfs could use.
This seems to work rather well. As Linus correctly points out that we should look into unifying both and simply make {override,revert}_creds() do what {override,revert}_creds_light() currently does. Caller's that really need the extra reference count can take it manually.
This series does all that. Afaict, most callers can be directly converted over and can avoid the extra reference count completely.
Lightly tested.
---
Christian Brauner (26):
tree-wide: s/override_creds()/override_creds_light(get_new_cred())/g
cred: return old creds from revert_creds_light()
tree-wide: s/revert_creds()/put_cred(revert_creds_light())/g
cred: remove old {override,revert}_creds() helpers
tree-wide: s/override_creds_light()/override_creds()/g
tree-wide: s/revert_creds_light()/revert_creds()/g
firmware: avoid pointless reference count bump
sev-dev: avoid pointless cred reference count bump
target_core_configfs: avoid pointless cred reference count bump
aio: avoid pointless cred reference count bump
binfmt_misc: avoid pointless cred reference count bump
coredump: avoid pointless cred reference count bump nfs/localio: avoid pointless cred reference count bumps nfs/nfs4idmap: avoid pointless reference count bump nfs/nfs4recover: avoid pointless cred reference count bump
nfsfh: avoid pointless cred reference count bump
open: avoid pointless cred reference count bump
ovl: avoid pointless cred reference count bump
cifs: avoid pointless cred reference count bump
cifs: avoid pointless cred reference count bump
smb: avoid pointless cred reference count bump
io_uring: avoid pointless cred reference count bump
acct: avoid pointless reference count bump
cgroup: avoid pointless cred reference count bump
trace: avoid pointless cred reference count bump
dns_resolver: avoid pointless cred reference count bump
drivers/base/firmware_loader/main.c | 3 +-- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/target/target_core_configfs.c | 3 +-- fs/aio.c | 3 +-- fs/backing-file.c | 20 +++++++------- fs/cachefiles/internal.h | 4 +-- fs/nfsd/auth.c | 4 +-- fs/nfsd/filecache.c | 2 +- fs/nfsd/nfs4recover.c | 3 +-- fs/nfsd/nfsfh.c | 1 - fs/open.c | 10 ++----- fs/overlayfs/copy_up.c | 6 ++--- fs/overlayfs/dir.c | 4 +-- fs/overlayfs/util.c | 4 +-- fs/smb/server/smb_common.c | 4 +-- include/linux/cred.h | 14 ++++------ kernel/cred.c | 50 ----------------------------------- kernel/trace/trace_events_user.c | 3 +-- 18 files changed, 35 insertions(+), 105 deletions(-)
---
base-commit: 228a1157fb9fec47eb135b51c0202b574e079ebf
change-id: 20241124-work-cred-349b65450082
Christian Brauner
maintainerPATCH 1/26 tree-wide: s/override_creds()/override_creds_light(get_new_cred())/g
--- drivers/base/firmware_loader/main.c | 2 +- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/target/target_core_configfs.c | 2 +- fs/aio.c | 2 +- fs/binfmt_misc.c | 2 +- fs/cachefiles/internal.h | 2 +- fs/coredump.c | 2 +- fs/nfs/localio.c | 4 ++-- fs/nfs/nfs4idmap.c | 2 +- fs/nfsd/auth.c | 2 +- fs/nfsd/nfs4recover.c | 2 +- fs/nfsd/nfsfh.c | 2 +- fs/open.c | 2 +- fs/overlayfs/copy_up.c | 2 +- fs/smb/client/cifs_spnego.c | 2 +- fs/smb/client/cifsacl.c | 4 ++-- fs/smb/server/smb_common.c | 2 +- io_uring/io_uring.c | 2 +- io_uring/sqpoll.c | 2 +- kernel/acct.c | 2 +- kernel/cgroup/cgroup.c | 2 +- kernel/trace/trace_events_user.c | 2 +- net/dns_resolver/dns_query.c | 2 +- 23 files changed, 25 insertions(+), 25 deletions(-)
drivers/base/firmware_loader/main.c +1 -1
@@ -912,7 +912,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ret = -ENOMEM ; goto out; } - old_cred =override_creds (kern_cred); + old_cred =override_creds_light (get_new_cred (kern_cred)); ret =fw_get_filesystem_firmware (device, fw->priv,"" ,NULL );
drivers/crypto/ccp/sev-dev.c +1 -1
@@ -244,7 +244,7 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t mif (!cred)return ERR_PTR (-ENOMEM ); cred->fsuid =GLOBAL_ROOT_UID ; - old_cred =override_creds (cred); + old_cred =override_creds_light (get_new_cred (cred)); fp =file_open_root (&root, filename, flags, mode);path_put (&root);
drivers/target/target_core_configfs.c +1 -1
@@ -3756,7 +3756,7 @@ static int __init target_core_init_configfs(void) ret = -ENOMEM ; goto out; } - old_cred =override_creds (kern_cred); + old_cred =override_creds_light (get_new_cred (kern_cred));target_init_dbroot ();revert_creds (old_cred);put_cred (kern_cred);
fs/aio.c +1 -1
@@ -1639,7 +1639,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,static void aio_fsync_work (struct work_struct *work) { struct aio_kiocb *iocb = container_of(work, struct aio_kiocb, fsync.work); -const struct cred *old_cred =override_creds (iocb->fsync.creds); +const struct cred *old_cred =override_creds_light (get_new_cred (iocb->fsync.creds)); iocb->ki_res.res =vfs_fsync (iocb->fsync.file, iocb->fsync.datasync);revert_creds (old_cred);
fs/binfmt_misc.c +1 -1
@@ -826,7 +826,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,* didn't matter much as only a privileged process could open * the register file. */ - old_cred =override_creds (file->f_cred); + old_cred =override_creds_light (get_new_cred (file->f_cred)); f =open_exec (e->interpreter);revert_creds (old_cred);if (IS_ERR (f)) {
fs/cachefiles/internal.h +1 -1
@@ -393,7 +393,7 @@ extern int cachefiles_determine_cache_security(struct cachefiles_cache *cache,static inline void cachefiles_begin_secure (struct cachefiles_cache *cache,const struct cred **_saved_cred) { - *_saved_cred =override_creds (cache->cache_cred); + *_saved_cred =override_creds_light (get_new_cred (cache->cache_cred)); } static inline void cachefiles_end_secure(struct cachefiles_cache *cache,
fs/coredump.c +1 -1
@@ -576,7 +576,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)if (retval <0 ) goto fail_creds; - old_cred =override_creds (cred); + old_cred =override_creds_light (get_new_cred (cred)); ispipe =format_corename (&cn, &cprm, &argv, &argc);
fs/nfs/localio.c +2 -2
@@ -371,7 +371,7 @@ static void nfs_local_call_read(struct work_struct *work)struct iov_iter iter;ssize_t status; - save_cred =override_creds (filp->f_cred); + save_cred =override_creds_light (get_new_cred (filp->f_cred));nfs_local_iter_init (&iter, iocb,READ );
@@ -541,7 +541,7 @@ static void nfs_local_call_write(struct work_struct *work)ssize_t status; current->flags |=PF_LOCAL_THROTTLE |PF_MEMALLOC_NOIO ; - save_cred =override_creds (filp->f_cred); + save_cred =override_creds_light (get_new_cred (filp->f_cred));nfs_local_iter_init (&iter, iocb,WRITE );
fs/nfs/nfs4idmap.c +1 -1
@@ -311,7 +311,7 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,const struct user_key_payload *payload;ssize_t ret; - saved_cred =override_creds (id_resolver_cache); + saved_cred =override_creds_light (get_new_cred (id_resolver_cache)); rkey =nfs_idmap_request_key (name, namelen, type, idmap);revert_creds (saved_cred);
fs/nfsd/auth.c +1 -1
@@ -79,7 +79,7 @@ int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)else new->cap_effective =cap_raise_nfsd_set (new->cap_effective, new->cap_permitted); -put_cred (override_creds (new)); +put_cred (override_creds_light (get_new_cred (new)));put_cred (new);return 0 ;
fs/nfsd/nfs4recover.c +1 -1
@@ -81,7 +81,7 @@ nfs4_save_creds(const struct cred **original_creds) new->fsuid =GLOBAL_ROOT_UID ; new->fsgid =GLOBAL_ROOT_GID ; - *original_creds =override_creds (new); + *original_creds =override_creds_light (get_new_cred (new));put_cred (new);return 0 ; }
fs/nfsd/nfsfh.c +1 -1
@@ -221,7 +221,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net, new->cap_effective =cap_raise_nfsd_set (new->cap_effective, new->cap_permitted); -put_cred (override_creds (new)); +put_cred (override_creds_light (get_new_cred (new)));put_cred (new); }else { error =nfsd_setuser_and_check_port (rqstp, cred, exp);
fs/open.c +1 -1
@@ -448,7 +448,7 @@ static const struct cred *access_override_creds(void)*/ override_cred->non_rcu =1 ; - old_cred =override_creds (override_cred); + old_cred =override_creds_light (get_new_cred (override_cred));/* override_cred() gets its own ref */ put_cred (override_cred);
fs/overlayfs/copy_up.c +1 -1
@@ -741,7 +741,7 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)return err;if (cc->new) - cc->old =override_creds (cc->new); + cc->old =override_creds_light (get_new_cred (cc->new));return 0 ; }
fs/smb/client/cifs_spnego.c +1 -1
@@ -173,7 +173,7 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo, }cifs_dbg (FYI ,"key description = %s\n" , description); - saved_cred =override_creds (spnego_cred); + saved_cred =override_creds_light (get_new_cred (spnego_cred)); spnego_key =request_key (&cifs_spnego_key_type, description,"" );revert_creds (saved_cred);
fs/smb/client/cifsacl.c +2 -2
@@ -292,7 +292,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid)return -EINVAL ; rc =0 ; - saved_cred =override_creds (root_cred); + saved_cred =override_creds_light (get_new_cred (root_cred)); sidkey =request_key (&cifs_idmap_key_type, desc,"" );if (IS_ERR (sidkey)) { rc = -EINVAL ;
@@ -398,7 +398,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid,if (!sidstr)return -ENOMEM ; - saved_cred =override_creds (root_cred); + saved_cred =override_creds_light (get_new_cred (root_cred)); sidkey =request_key (&cifs_idmap_key_type, sidstr,"" );if (IS_ERR (sidkey)) { cifs_dbg(FYI, "%s: Can't map SID %s to a %cid\n",
fs/smb/server/smb_common.c +1 -1
@@ -780,7 +780,7 @@ int __ksmbd_override_fsids(struct ksmbd_work *work, cred->cap_effective =cap_drop_fs_set (cred->cap_effective);WARN_ON (work->saved_cred); - work->saved_cred =override_creds (cred); + work->saved_cred =override_creds_light (get_new_cred (cred));if (!work->saved_cred) {abort_creds (cred);return -EINVAL ;
io_uring/io_uring.c +1 -1
@@ -1704,7 +1704,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)return -EBADF ;if (unlikely ((req->flags &REQ_F_CREDS ) && req->creds !=current_cred ())) - creds =override_creds (req->creds); + creds =override_creds_light (get_new_cred (req->creds));if (!def->audit_skip)audit_uring_entry (req->opcode);
io_uring/sqpoll.c +1 -1
@@ -174,7 +174,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)const struct cred *creds =NULL ;if (ctx->sq_creds !=current_cred ()) - creds =override_creds (ctx->sq_creds); + creds =override_creds_light (get_new_cred (ctx->sq_creds));mutex_lock (&ctx->uring_lock);if (!wq_list_empty (&ctx->iopoll_list))
kernel/acct.c +1 -1
@@ -501,7 +501,7 @@ static void do_acct_process(struct bsd_acct_struct *acct) flim =rlimit (RLIMIT_FSIZE ); current->signal->rlim[RLIMIT_FSIZE ].rlim_cur =RLIM_INFINITY ;/* Perform file operations on behalf of whoever enabled accounting */ - orig_cred =override_creds (file->f_cred); + orig_cred =override_creds_light (get_new_cred (file->f_cred));/* * First check to see if there is enough free_space to continue
kernel/cgroup/cgroup.c +1 -1
@@ -5216,7 +5216,7 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,* permissions using the credentials from file open to protect against * inherited fd attacks. */ - saved_cred =override_creds (of->file->f_cred); + saved_cred =override_creds_light (get_new_cred (of->file->f_cred)); ret =cgroup_attach_permissions (src_cgrp, dst_cgrp, of->file->f_path.dentry->d_sb, threadgroup, ctx->ns);
kernel/trace/trace_events_user.c +1 -1
@@ -1469,7 +1469,7 @@ static int user_event_set_call_visible(struct user_event *user, bool visible)*/ cred->fsuid =GLOBAL_ROOT_UID ; - old_cred =override_creds (cred); + old_cred =override_creds_light (get_new_cred (cred));if (visible) ret =trace_add_event_call (&user->call);
net/dns_resolver/dns_query.c +1 -1
@@ -124,7 +124,7 @@ int dns_query(struct net *net,/* make the upcall, using special credentials to prevent the use of * add_key() to preinstall malicious redirections */ - saved_cred =override_creds (dns_resolver_cache); + saved_cred =override_creds_light (get_new_cred (dns_resolver_cache)); rkey =request_key_net (&key_type_dns_resolver, desc, net, options);revert_creds (saved_cred);kfree (desc);
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 2/26 cred: return old creds from revert_creds_light()
In reply to Christian BraunerSo we can easily convert revert_creds() callers over to drop the reference count explicitly.
--- include/linux/cred.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/cred.h +4 -1
@@ -185,9 +185,12 @@ static inline const struct cred *override_creds_light(const struct cred *overridreturn old; } -static inline void revert_creds_light (const struct cred *revert_cred) +static inline const struct cred *revert_creds_light (const struct cred *revert_cred) { +const struct cred *override_cred = current->cred; +rcu_assign_pointer (current->cred, revert_cred); +return override_cred; }/**
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 3/26 tree-wide: s/revert_creds()/put_cred(revert_creds_light())/g
In reply to Christian BraunerConvert all calls to revert_creds() over to explicitly dropping reference counts in preparation for converting revert_creds() to revert_creds_light() semantics.
--- drivers/base/firmware_loader/main.c | 2 +- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/target/target_core_configfs.c | 2 +- fs/aio.c | 2 +- fs/binfmt_misc.c | 2 +- fs/cachefiles/internal.h | 2 +- fs/coredump.c | 2 +- fs/nfs/localio.c | 4 ++-- fs/nfs/nfs4idmap.c | 2 +- fs/nfsd/auth.c | 2 +- fs/nfsd/filecache.c | 2 +- fs/nfsd/nfs4recover.c | 2 +- fs/open.c | 2 +- fs/overlayfs/copy_up.c | 2 +- fs/smb/client/cifs_spnego.c | 2 +- fs/smb/client/cifsacl.c | 4 ++-- fs/smb/server/smb_common.c | 2 +- io_uring/io_uring.c | 2 +- io_uring/sqpoll.c | 2 +- kernel/acct.c | 2 +- kernel/cgroup/cgroup.c | 2 +- kernel/trace/trace_events_user.c | 2 +- net/dns_resolver/dns_query.c | 2 +- 23 files changed, 25 insertions(+), 25 deletions(-)
drivers/base/firmware_loader/main.c +1 -1
@@ -944,7 +944,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, }else ret =assign_fw (fw, device); -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred));put_cred (kern_cred); out:
drivers/crypto/ccp/sev-dev.c +1 -1
@@ -249,7 +249,7 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t m fp =file_open_root (&root, filename, flags, mode);path_put (&root); -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred));return fp; }
drivers/target/target_core_configfs.c +1 -1
@@ -3758,7 +3758,7 @@ static int __init target_core_init_configfs(void) } old_cred =override_creds_light (get_new_cred (kern_cred));target_init_dbroot (); -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred));put_cred (kern_cred);return 0 ;
fs/aio.c +1 -1
@@ -1642,7 +1642,7 @@ static void aio_fsync_work(struct work_struct *work)const struct cred *old_cred =override_creds_light (get_new_cred (iocb->fsync.creds)); iocb->ki_res.res =vfs_fsync (iocb->fsync.file, iocb->fsync.datasync); -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred));put_cred (iocb->fsync.creds);iocb_put (iocb); }
fs/binfmt_misc.c +1 -1
@@ -828,7 +828,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,*/ old_cred =override_creds_light (get_new_cred (file->f_cred)); f =open_exec (e->interpreter); -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred));if (IS_ERR (f)) {pr_notice ("register: failed to install interpreter file %s\n" , e->interpreter);
fs/cachefiles/internal.h +1 -1
@@ -399,7 +399,7 @@ static inline void cachefiles_begin_secure(struct cachefiles_cache *cache,static inline void cachefiles_end_secure (struct cachefiles_cache *cache,const struct cred *saved_cred) { -revert_creds (saved_cred); +put_cred (revert_creds_light (saved_cred)); }/*
fs/coredump.c +1 -1
@@ -781,7 +781,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)kfree (argv);kfree (cn.corename);coredump_finish (core_dumped); -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred)); fail_creds:put_cred (cred); fail:
fs/nfs/localio.c +2 -2
@@ -381,7 +381,7 @@ static void nfs_local_call_read(struct work_struct *work)nfs_local_read_done (iocb, status);nfs_local_pgio_release (iocb); -revert_creds (save_cred); +put_cred (revert_creds_light (save_cred)); } static int
@@ -554,7 +554,7 @@ static void nfs_local_call_write(struct work_struct *work)nfs_local_vfs_getattr (iocb);nfs_local_pgio_release (iocb); -revert_creds (save_cred); +put_cred (revert_creds_light (save_cred)); current->flags = old_flags; }
fs/nfs/nfs4idmap.c +1 -1
@@ -313,7 +313,7 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen, saved_cred =override_creds_light (get_new_cred (id_resolver_cache)); rkey =nfs_idmap_request_key (name, namelen, type, idmap); -revert_creds (saved_cred); +put_cred (revert_creds_light (saved_cred));if (IS_ERR (rkey)) { ret =PTR_ERR (rkey);
fs/nfsd/auth.c +1 -1
@@ -27,7 +27,7 @@ int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)int flags =nfsexp_flags (cred, exp);/* discard any old override before preparing the new set */ -revert_creds (get_cred (current_real_cred ())); +put_cred (revert_creds_light (get_cred (current_real_cred ()))); new =prepare_creds ();if (!new)return -ENOMEM ;
fs/nfsd/filecache.c +1 -1
@@ -1252,7 +1252,7 @@ nfsd_file_acquire_local(struct net *net, struct svc_cred *cred, beres =nfsd_file_do_acquire (NULL , net, cred, client, fhp, may_flags,NULL , pnf, true); -revert_creds (save_cred); +put_cred (revert_creds_light (save_cred));return beres; }
fs/nfsd/nfs4recover.c +1 -1
@@ -89,7 +89,7 @@ nfs4_save_creds(const struct cred **original_creds)static void nfs4_reset_creds (const struct cred *original) { -revert_creds (original); +put_cred (revert_creds_light (original)); } static void
fs/open.c +1 -1
@@ -523,7 +523,7 @@ static long do_faccessat(int dfd, const char __user *filename, int mode, int fla } out:if (old_cred) -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred));return res; }
fs/overlayfs/copy_up.c +1 -1
@@ -749,7 +749,7 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)static void ovl_revert_cu_creds (struct ovl_cu_creds *cc) {if (cc->new) { -revert_creds (cc->old); +put_cred (revert_creds_light (cc->old));put_cred (cc->new); } }
fs/smb/client/cifs_spnego.c +1 -1
@@ -175,7 +175,7 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,cifs_dbg (FYI ,"key description = %s\n" , description); saved_cred =override_creds_light (get_new_cred (spnego_cred)); spnego_key =request_key (&cifs_spnego_key_type, description,"" ); -revert_creds (saved_cred); +put_cred (revert_creds_light (saved_cred));#ifdef CONFIG_CIFS_DEBUG2 if (cifsFYI && !IS_ERR (spnego_key)) {
fs/smb/client/cifsacl.c +2 -2
@@ -327,7 +327,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) out_key_put:key_put (sidkey); out_revert_creds: -revert_creds (saved_cred); +put_cred (revert_creds_light (saved_cred));return rc; invalidate_key:
@@ -438,7 +438,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid, out_key_put:key_put (sidkey); out_revert_creds: -revert_creds (saved_cred); +put_cred (revert_creds_light (saved_cred));kfree (sidstr);/*
fs/smb/server/smb_common.c +1 -1
@@ -800,7 +800,7 @@ void ksmbd_revert_fsids(struct ksmbd_work *work)WARN_ON (!work->saved_cred); cred =current_cred (); -revert_creds (work->saved_cred); +put_cred (revert_creds_light (work->saved_cred));put_cred (cred); work->saved_cred =NULL ; }
io_uring/io_uring.c +1 -1
@@ -1715,7 +1715,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)audit_uring_exit (!ret, ret);if (creds) -revert_creds (creds); +put_cred (revert_creds_light (creds));if (ret ==IOU_OK ) {if (issue_flags &IO_URING_F_COMPLETE_DEFER )
io_uring/sqpoll.c +1 -1
@@ -192,7 +192,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)if (to_submit &&wq_has_sleeper (&ctx->sqo_sq_wait))wake_up (&ctx->sqo_sq_wait);if (creds) -revert_creds (creds); +put_cred (revert_creds_light (creds)); }return ret;
kernel/acct.c +1 -1
@@ -541,7 +541,7 @@ static void do_acct_process(struct bsd_acct_struct *acct) } out: current->signal->rlim[RLIMIT_FSIZE ].rlim_cur = flim; -revert_creds (orig_cred); +put_cred (revert_creds_light (orig_cred)); }/**
kernel/cgroup/cgroup.c +1 -1
@@ -5220,7 +5220,7 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf, ret =cgroup_attach_permissions (src_cgrp, dst_cgrp, of->file->f_path.dentry->d_sb, threadgroup, ctx->ns); -revert_creds (saved_cred); +put_cred (revert_creds_light (saved_cred));if (ret) goto out_finish;
kernel/trace/trace_events_user.c +1 -1
@@ -1476,7 +1476,7 @@ static int user_event_set_call_visible(struct user_event *user, bool visible)else ret =trace_remove_event_call (&user->call); -revert_creds (old_cred); +put_cred (revert_creds_light (old_cred));put_cred (cred);return ret;
net/dns_resolver/dns_query.c +1 -1
@@ -126,7 +126,7 @@ int dns_query(struct net *net,*/ saved_cred =override_creds_light (get_new_cred (dns_resolver_cache)); rkey =request_key_net (&key_type_dns_resolver, desc, net, options); -revert_creds (saved_cred); +put_cred (revert_creds_light (saved_cred));kfree (desc);if (IS_ERR (rkey)) { ret =PTR_ERR (rkey);
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 4/26 cred: remove old {override,revert}_creds() helpers
In reply to Christian BraunerThey are now unused.
--- include/linux/cred.h | 7 ------- kernel/cred.c | 50 -------------------------------------------------- 2 files changed, 57 deletions(-)
include/linux/cred.h +0 -7
@@ -155,8 +155,6 @@ extern struct cred *prepare_creds(void);extern struct cred *prepare_exec_creds (void );extern int commit_creds (struct cred *);extern void abort_creds (struct cred *); -extern const struct cred *override_creds (const struct cred *); -extern void revert_creds (const struct cred *);extern struct cred *prepare_kernel_cred (struct task_struct *);extern int set_security_override (struct cred *,u32 );extern int set_security_override_from_ctx (struct cred *,const char *);
@@ -172,11 +170,6 @@ static inline bool cap_ambient_invariant_ok(const struct cred *cred) cred->cap_inheritable)); } -/* -* Override creds without bumping reference count. Caller must ensure -* reference remains valid or has taken reference. Almost always not the -* interface you want. Use override_creds()/revert_creds() instead. -*/ static inline const struct cred *override_creds_light (const struct cred *override_cred) {const struct cred *old = current->cred;
kernel/cred.c +0 -50
56 lines not on this page · raw message
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 5/26 tree-wide: s/override_creds_light()/override_creds()/g
In reply to Christian BraunerRename all calls to override_creds_light() back to overrid_creds().
--- drivers/base/firmware_loader/main.c | 2 +- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/target/target_core_configfs.c | 2 +- fs/aio.c | 2 +- fs/backing-file.c | 10 +++++----- fs/binfmt_misc.c | 2 +- fs/cachefiles/internal.h | 2 +- fs/coredump.c | 2 +- fs/nfs/localio.c | 4 ++-- fs/nfs/nfs4idmap.c | 2 +- fs/nfsd/auth.c | 2 +- fs/nfsd/nfs4recover.c | 2 +- fs/nfsd/nfsfh.c | 2 +- fs/open.c | 2 +- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/dir.c | 2 +- fs/overlayfs/util.c | 2 +- fs/smb/client/cifs_spnego.c | 2 +- fs/smb/client/cifsacl.c | 4 ++-- fs/smb/server/smb_common.c | 2 +- include/linux/cred.h | 2 +- io_uring/io_uring.c | 2 +- io_uring/sqpoll.c | 2 +- kernel/acct.c | 2 +- kernel/cgroup/cgroup.c | 2 +- kernel/trace/trace_events_user.c | 2 +- net/dns_resolver/dns_query.c | 2 +- 27 files changed, 33 insertions(+), 33 deletions(-)
drivers/base/firmware_loader/main.c +1 -1
@@ -912,7 +912,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ret = -ENOMEM ; goto out; } - old_cred =override_creds_light (get_new_cred (kern_cred)); + old_cred =override_creds (get_new_cred (kern_cred)); ret =fw_get_filesystem_firmware (device, fw->priv,"" ,NULL );
drivers/crypto/ccp/sev-dev.c +1 -1
@@ -244,7 +244,7 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t mif (!cred)return ERR_PTR (-ENOMEM ); cred->fsuid =GLOBAL_ROOT_UID ; - old_cred =override_creds_light (get_new_cred (cred)); + old_cred =override_creds (get_new_cred (cred)); fp =file_open_root (&root, filename, flags, mode);path_put (&root);
drivers/target/target_core_configfs.c +1 -1
@@ -3756,7 +3756,7 @@ static int __init target_core_init_configfs(void) ret = -ENOMEM ; goto out; } - old_cred =override_creds_light (get_new_cred (kern_cred)); + old_cred =override_creds (get_new_cred (kern_cred));target_init_dbroot ();put_cred (revert_creds_light (old_cred));put_cred (kern_cred);
fs/aio.c +1 -1
@@ -1639,7 +1639,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,static void aio_fsync_work (struct work_struct *work) { struct aio_kiocb *iocb = container_of(work, struct aio_kiocb, fsync.work); -const struct cred *old_cred =override_creds_light (get_new_cred (iocb->fsync.creds)); +const struct cred *old_cred =override_creds (get_new_cred (iocb->fsync.creds)); iocb->ki_res.res =vfs_fsync (iocb->fsync.file, iocb->fsync.datasync);put_cred (revert_creds_light (old_cred));
fs/backing-file.c +5 -5
@@ -176,7 +176,7 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter, !(file->f_mode & FMODE_CAN_ODIRECT))return -EINVAL ; - old_cred =override_creds_light (ctx->cred); + old_cred =override_creds (ctx->cred);if (is_sync_kiocb (iocb)) {rwf_t rwf =iocb_to_rw_flags (flags);
@@ -233,7 +233,7 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,*/ flags &= ~IOCB_DIO_CALLER_COMP ; - old_cred =override_creds_light (ctx->cred); + old_cred =override_creds (ctx->cred);if (is_sync_kiocb (iocb)) {rwf_t rwf =iocb_to_rw_flags (flags);
@@ -281,7 +281,7 @@ ssize_t backing_file_splice_read(struct file *in, struct kiocb *iocb,if (WARN_ON_ONCE (!(in->f_mode &FMODE_BACKING )))return -EIO ; - old_cred =override_creds_light (ctx->cred); + old_cred =override_creds (ctx->cred); ret =vfs_splice_read (in, &iocb->ki_pos, pipe, len, flags);revert_creds_light (old_cred);
@@ -310,7 +310,7 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,if (ret)return ret; - old_cred =override_creds_light (ctx->cred); + old_cred =override_creds (ctx->cred);file_start_write (out); ret = out->f_op->splice_write (pipe, out, &iocb->ki_pos, len, flags);file_end_write (out);
@@ -337,7 +337,7 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,vma_set_file (vma, file); - old_cred =override_creds_light (ctx->cred); + old_cred =override_creds (ctx->cred); ret =call_mmap (vma->vm_file, vma);revert_creds_light (old_cred);
fs/binfmt_misc.c +1 -1
@@ -826,7 +826,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,* didn't matter much as only a privileged process could open * the register file. */ - old_cred =override_creds_light (get_new_cred (file->f_cred)); + old_cred =override_creds (get_new_cred (file->f_cred)); f =open_exec (e->interpreter);put_cred (revert_creds_light (old_cred));if (IS_ERR (f)) {
fs/cachefiles/internal.h +1 -1
@@ -393,7 +393,7 @@ extern int cachefiles_determine_cache_security(struct cachefiles_cache *cache,static inline void cachefiles_begin_secure (struct cachefiles_cache *cache,const struct cred **_saved_cred) { - *_saved_cred =override_creds_light (get_new_cred (cache->cache_cred)); + *_saved_cred =override_creds (get_new_cred (cache->cache_cred)); } static inline void cachefiles_end_secure(struct cachefiles_cache *cache,
fs/coredump.c +1 -1
@@ -576,7 +576,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)if (retval <0 ) goto fail_creds; - old_cred =override_creds_light (get_new_cred (cred)); + old_cred =override_creds (get_new_cred (cred)); ispipe =format_corename (&cn, &cprm, &argv, &argc);
fs/nfs/localio.c +2 -2
@@ -371,7 +371,7 @@ static void nfs_local_call_read(struct work_struct *work)struct iov_iter iter;ssize_t status; - save_cred =override_creds_light (get_new_cred (filp->f_cred)); + save_cred =override_creds (get_new_cred (filp->f_cred));nfs_local_iter_init (&iter, iocb,READ );
@@ -541,7 +541,7 @@ static void nfs_local_call_write(struct work_struct *work)ssize_t status; current->flags |=PF_LOCAL_THROTTLE |PF_MEMALLOC_NOIO ; - save_cred =override_creds_light (get_new_cred (filp->f_cred)); + save_cred =override_creds (get_new_cred (filp->f_cred));nfs_local_iter_init (&iter, iocb,WRITE );
fs/nfs/nfs4idmap.c +1 -1
@@ -311,7 +311,7 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,const struct user_key_payload *payload;ssize_t ret; - saved_cred =override_creds_light (get_new_cred (id_resolver_cache)); + saved_cred =override_creds (get_new_cred (id_resolver_cache)); rkey =nfs_idmap_request_key (name, namelen, type, idmap);put_cred (revert_creds_light (saved_cred));
fs/nfsd/auth.c +1 -1
@@ -79,7 +79,7 @@ int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)else new->cap_effective =cap_raise_nfsd_set (new->cap_effective, new->cap_permitted); -put_cred (override_creds_light (get_new_cred (new))); +put_cred (override_creds (get_new_cred (new)));put_cred (new);return 0 ;
fs/nfsd/nfs4recover.c +1 -1
@@ -81,7 +81,7 @@ nfs4_save_creds(const struct cred **original_creds) new->fsuid =GLOBAL_ROOT_UID ; new->fsgid =GLOBAL_ROOT_GID ; - *original_creds =override_creds_light (get_new_cred (new)); + *original_creds =override_creds (get_new_cred (new));put_cred (new);return 0 ; }
fs/nfsd/nfsfh.c +1 -1
@@ -221,7 +221,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net, new->cap_effective =cap_raise_nfsd_set (new->cap_effective, new->cap_permitted); -put_cred (override_creds_light (get_new_cred (new))); +put_cred (override_creds (get_new_cred (new)));put_cred (new); }else { error =nfsd_setuser_and_check_port (rqstp, cred, exp);
fs/open.c +1 -1
@@ -448,7 +448,7 @@ static const struct cred *access_override_creds(void)*/ override_cred->non_rcu =1 ; - old_cred =override_creds_light (get_new_cred (override_cred)); + old_cred =override_creds (get_new_cred (override_cred));/* override_cred() gets its own ref */ put_cred (override_cred);
fs/overlayfs/copy_up.c +1 -1
@@ -741,7 +741,7 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)return err;if (cc->new) - cc->old =override_creds_light (get_new_cred (cc->new)); + cc->old =override_creds (get_new_cred (cc->new));return 0 ; }
fs/overlayfs/dir.c +1 -1
@@ -580,7 +580,7 @@ static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry,* We must be called with creator creds already, otherwise we risk * leaking creds. */ - old_cred =override_creds_light (override_cred); + old_cred =override_creds (override_cred);WARN_ON_ONCE (old_cred !=ovl_creds (dentry->d_sb));return override_cred;
fs/overlayfs/util.c +1 -1
@@ -65,7 +65,7 @@ const struct cred *ovl_override_creds(struct super_block *sb) {struct ovl_fs *ofs =OVL_FS (sb); -return override_creds_light (ofs->creator_cred); +return override_creds (ofs->creator_cred); }void ovl_revert_creds (const struct cred *old_cred)
fs/smb/client/cifs_spnego.c +1 -1
@@ -173,7 +173,7 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo, }cifs_dbg (FYI ,"key description = %s\n" , description); - saved_cred =override_creds_light (get_new_cred (spnego_cred)); + saved_cred =override_creds (get_new_cred (spnego_cred)); spnego_key =request_key (&cifs_spnego_key_type, description,"" );put_cred (revert_creds_light (saved_cred));
fs/smb/client/cifsacl.c +2 -2
@@ -292,7 +292,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid)return -EINVAL ; rc =0 ; - saved_cred =override_creds_light (get_new_cred (root_cred)); + saved_cred =override_creds (get_new_cred (root_cred)); sidkey =request_key (&cifs_idmap_key_type, desc,"" );if (IS_ERR (sidkey)) { rc = -EINVAL ;
@@ -398,7 +398,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid,if (!sidstr)return -ENOMEM ; - saved_cred =override_creds_light (get_new_cred (root_cred)); + saved_cred =override_creds (get_new_cred (root_cred)); sidkey =request_key (&cifs_idmap_key_type, sidstr,"" );if (IS_ERR (sidkey)) { cifs_dbg(FYI, "%s: Can't map SID %s to a %cid\n",
fs/smb/server/smb_common.c +1 -1
@@ -780,7 +780,7 @@ int __ksmbd_override_fsids(struct ksmbd_work *work, cred->cap_effective =cap_drop_fs_set (cred->cap_effective);WARN_ON (work->saved_cred); - work->saved_cred =override_creds_light (get_new_cred (cred)); + work->saved_cred =override_creds (get_new_cred (cred));if (!work->saved_cred) {abort_creds (cred);return -EINVAL ;
include/linux/cred.h +1 -1
@@ -170,7 +170,7 @@ static inline bool cap_ambient_invariant_ok(const struct cred *cred) cred->cap_inheritable)); } -static inline const struct cred *override_creds_light (const struct cred *override_cred) +static inline const struct cred *override_creds (const struct cred *override_cred) {const struct cred *old = current->cred;
io_uring/io_uring.c +1 -1
@@ -1704,7 +1704,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)return -EBADF ;if (unlikely ((req->flags &REQ_F_CREDS ) && req->creds !=current_cred ())) - creds =override_creds_light (get_new_cred (req->creds)); + creds =override_creds (get_new_cred (req->creds));if (!def->audit_skip)audit_uring_entry (req->opcode);
io_uring/sqpoll.c +1 -1
@@ -174,7 +174,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)const struct cred *creds =NULL ;if (ctx->sq_creds !=current_cred ()) - creds =override_creds_light (get_new_cred (ctx->sq_creds)); + creds =override_creds (get_new_cred (ctx->sq_creds));mutex_lock (&ctx->uring_lock);if (!wq_list_empty (&ctx->iopoll_list))
kernel/acct.c +1 -1
@@ -501,7 +501,7 @@ static void do_acct_process(struct bsd_acct_struct *acct) flim =rlimit (RLIMIT_FSIZE ); current->signal->rlim[RLIMIT_FSIZE ].rlim_cur =RLIM_INFINITY ;/* Perform file operations on behalf of whoever enabled accounting */ - orig_cred =override_creds_light (get_new_cred (file->f_cred)); + orig_cred =override_creds (get_new_cred (file->f_cred));/* * First check to see if there is enough free_space to continue
kernel/cgroup/cgroup.c +1 -1
@@ -5216,7 +5216,7 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,* permissions using the credentials from file open to protect against * inherited fd attacks. */ - saved_cred =override_creds_light (get_new_cred (of->file->f_cred)); + saved_cred =override_creds (get_new_cred (of->file->f_cred)); ret =cgroup_attach_permissions (src_cgrp, dst_cgrp, of->file->f_path.dentry->d_sb, threadgroup, ctx->ns);
kernel/trace/trace_events_user.c +1 -1
@@ -1469,7 +1469,7 @@ static int user_event_set_call_visible(struct user_event *user, bool visible)*/ cred->fsuid =GLOBAL_ROOT_UID ; - old_cred =override_creds_light (get_new_cred (cred)); + old_cred =override_creds (get_new_cred (cred));if (visible) ret =trace_add_event_call (&user->call);
net/dns_resolver/dns_query.c +1 -1
@@ -124,7 +124,7 @@ int dns_query(struct net *net,/* make the upcall, using special credentials to prevent the use of * add_key() to preinstall malicious redirections */ - saved_cred =override_creds_light (get_new_cred (dns_resolver_cache)); + saved_cred =override_creds (get_new_cred (dns_resolver_cache)); rkey =request_key_net (&key_type_dns_resolver, desc, net, options);put_cred (revert_creds_light (saved_cred));kfree (desc);
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 6/26 tree-wide: s/revert_creds_light()/revert_creds()/g
In reply to Christian BraunerRename all calls to revert_creds_light() back to revert_creds().
--- drivers/base/firmware_loader/main.c | 2 +- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/target/target_core_configfs.c | 2 +- fs/aio.c | 2 +- fs/backing-file.c | 10 +++++----- fs/binfmt_misc.c | 2 +- fs/cachefiles/internal.h | 2 +- fs/coredump.c | 2 +- fs/nfs/localio.c | 4 ++-- fs/nfs/nfs4idmap.c | 2 +- fs/nfsd/auth.c | 2 +- fs/nfsd/filecache.c | 2 +- fs/nfsd/nfs4recover.c | 2 +- fs/open.c | 2 +- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/dir.c | 2 +- fs/overlayfs/util.c | 2 +- fs/smb/client/cifs_spnego.c | 2 +- fs/smb/client/cifsacl.c | 4 ++-- fs/smb/server/smb_common.c | 2 +- include/linux/cred.h | 2 +- io_uring/io_uring.c | 2 +- io_uring/sqpoll.c | 2 +- kernel/acct.c | 2 +- kernel/cgroup/cgroup.c | 2 +- kernel/trace/trace_events_user.c | 2 +- net/dns_resolver/dns_query.c | 2 +- 27 files changed, 33 insertions(+), 33 deletions(-)
drivers/base/firmware_loader/main.c +1 -1
@@ -944,7 +944,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, }else ret =assign_fw (fw, device); -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred));put_cred (kern_cred); out:
drivers/crypto/ccp/sev-dev.c +1 -1
@@ -249,7 +249,7 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t m fp =file_open_root (&root, filename, flags, mode);path_put (&root); -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred));return fp; }
drivers/target/target_core_configfs.c +1 -1
@@ -3758,7 +3758,7 @@ static int __init target_core_init_configfs(void) } old_cred =override_creds (get_new_cred (kern_cred));target_init_dbroot (); -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred));put_cred (kern_cred);return 0 ;
fs/aio.c +1 -1
@@ -1642,7 +1642,7 @@ static void aio_fsync_work(struct work_struct *work)const struct cred *old_cred =override_creds (get_new_cred (iocb->fsync.creds)); iocb->ki_res.res =vfs_fsync (iocb->fsync.file, iocb->fsync.datasync); -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred));put_cred (iocb->fsync.creds);iocb_put (iocb); }
fs/backing-file.c +5 -5
@@ -197,7 +197,7 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,backing_aio_cleanup (aio, ret); } out: -revert_creds_light (old_cred); +revert_creds (old_cred);if (ctx->accessed) ctx->accessed (iocb->ki_filp);
@@ -264,7 +264,7 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,backing_aio_cleanup (aio, ret); } out: -revert_creds_light (old_cred); +revert_creds (old_cred);return ret; }
@@ -283,7 +283,7 @@ ssize_t backing_file_splice_read(struct file *in, struct kiocb *iocb, old_cred =override_creds (ctx->cred); ret =vfs_splice_read (in, &iocb->ki_pos, pipe, len, flags); -revert_creds_light (old_cred); +revert_creds (old_cred);if (ctx->accessed) ctx->accessed (iocb->ki_filp);
@@ -314,7 +314,7 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,file_start_write (out); ret = out->f_op->splice_write (pipe, out, &iocb->ki_pos, len, flags);file_end_write (out); -revert_creds_light (old_cred); +revert_creds (old_cred);if (ctx->end_write) ctx->end_write (iocb, ret);
@@ -339,7 +339,7 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma, old_cred =override_creds (ctx->cred); ret =call_mmap (vma->vm_file, vma); -revert_creds_light (old_cred); +revert_creds (old_cred);if (ctx->accessed) ctx->accessed (vma->vm_file);
fs/binfmt_misc.c +1 -1
@@ -828,7 +828,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,*/ old_cred =override_creds (get_new_cred (file->f_cred)); f =open_exec (e->interpreter); -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred));if (IS_ERR (f)) {pr_notice ("register: failed to install interpreter file %s\n" , e->interpreter);
fs/cachefiles/internal.h +1 -1
@@ -399,7 +399,7 @@ static inline void cachefiles_begin_secure(struct cachefiles_cache *cache,static inline void cachefiles_end_secure (struct cachefiles_cache *cache,const struct cred *saved_cred) { -put_cred (revert_creds_light (saved_cred)); +put_cred (revert_creds (saved_cred)); }/*
fs/coredump.c +1 -1
@@ -781,7 +781,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)kfree (argv);kfree (cn.corename);coredump_finish (core_dumped); -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred)); fail_creds:put_cred (cred); fail:
fs/nfs/localio.c +2 -2
@@ -381,7 +381,7 @@ static void nfs_local_call_read(struct work_struct *work)nfs_local_read_done (iocb, status);nfs_local_pgio_release (iocb); -put_cred (revert_creds_light (save_cred)); +put_cred (revert_creds (save_cred)); } static int
@@ -554,7 +554,7 @@ static void nfs_local_call_write(struct work_struct *work)nfs_local_vfs_getattr (iocb);nfs_local_pgio_release (iocb); -put_cred (revert_creds_light (save_cred)); +put_cred (revert_creds (save_cred)); current->flags = old_flags; }
fs/nfs/nfs4idmap.c +1 -1
@@ -313,7 +313,7 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen, saved_cred =override_creds (get_new_cred (id_resolver_cache)); rkey =nfs_idmap_request_key (name, namelen, type, idmap); -put_cred (revert_creds_light (saved_cred)); +put_cred (revert_creds (saved_cred));if (IS_ERR (rkey)) { ret =PTR_ERR (rkey);
fs/nfsd/auth.c +1 -1
@@ -27,7 +27,7 @@ int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)int flags =nfsexp_flags (cred, exp);/* discard any old override before preparing the new set */ -put_cred (revert_creds_light (get_cred (current_real_cred ()))); +put_cred (revert_creds (get_cred (current_real_cred ()))); new =prepare_creds ();if (!new)return -ENOMEM ;
fs/nfsd/filecache.c +1 -1
@@ -1252,7 +1252,7 @@ nfsd_file_acquire_local(struct net *net, struct svc_cred *cred, beres =nfsd_file_do_acquire (NULL , net, cred, client, fhp, may_flags,NULL , pnf, true); -put_cred (revert_creds_light (save_cred)); +put_cred (revert_creds (save_cred));return beres; }
fs/nfsd/nfs4recover.c +1 -1
@@ -89,7 +89,7 @@ nfs4_save_creds(const struct cred **original_creds)static void nfs4_reset_creds (const struct cred *original) { -put_cred (revert_creds_light (original)); +put_cred (revert_creds (original)); } static void
fs/open.c +1 -1
@@ -523,7 +523,7 @@ static long do_faccessat(int dfd, const char __user *filename, int mode, int fla } out:if (old_cred) -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred));return res; }
fs/overlayfs/copy_up.c +1 -1
@@ -749,7 +749,7 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)static void ovl_revert_cu_creds (struct ovl_cu_creds *cc) {if (cc->new) { -put_cred (revert_creds_light (cc->old)); +put_cred (revert_creds (cc->old));put_cred (cc->new); } }
fs/overlayfs/dir.c +1 -1
@@ -575,7 +575,7 @@ static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry, }/* -* Caller is going to match this with revert_creds_light() and drop +* Caller is going to match this with revert_creds() and drop * referenec on the returned creds. * We must be called with creator creds already, otherwise we risk * leaking creds.
fs/overlayfs/util.c +1 -1
@@ -70,7 +70,7 @@ const struct cred *ovl_override_creds(struct super_block *sb)void ovl_revert_creds (const struct cred *old_cred) { -revert_creds_light (old_cred); +revert_creds (old_cred); }/*
fs/smb/client/cifs_spnego.c +1 -1
@@ -175,7 +175,7 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,cifs_dbg (FYI ,"key description = %s\n" , description); saved_cred =override_creds (get_new_cred (spnego_cred)); spnego_key =request_key (&cifs_spnego_key_type, description,"" ); -put_cred (revert_creds_light (saved_cred)); +put_cred (revert_creds (saved_cred));#ifdef CONFIG_CIFS_DEBUG2 if (cifsFYI && !IS_ERR (spnego_key)) {
fs/smb/client/cifsacl.c +2 -2
@@ -327,7 +327,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) out_key_put:key_put (sidkey); out_revert_creds: -put_cred (revert_creds_light (saved_cred)); +put_cred (revert_creds (saved_cred));return rc; invalidate_key:
@@ -438,7 +438,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid, out_key_put:key_put (sidkey); out_revert_creds: -put_cred (revert_creds_light (saved_cred)); +put_cred (revert_creds (saved_cred));kfree (sidstr);/*
fs/smb/server/smb_common.c +1 -1
@@ -800,7 +800,7 @@ void ksmbd_revert_fsids(struct ksmbd_work *work)WARN_ON (!work->saved_cred); cred =current_cred (); -put_cred (revert_creds_light (work->saved_cred)); +put_cred (revert_creds (work->saved_cred));put_cred (cred); work->saved_cred =NULL ; }
include/linux/cred.h +1 -1
@@ -178,7 +178,7 @@ static inline const struct cred *override_creds(const struct cred *override_credreturn old; } -static inline const struct cred *revert_creds_light (const struct cred *revert_cred) +static inline const struct cred *revert_creds (const struct cred *revert_cred) {const struct cred *override_cred = current->cred;
io_uring/io_uring.c +1 -1
@@ -1715,7 +1715,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)audit_uring_exit (!ret, ret);if (creds) -put_cred (revert_creds_light (creds)); +put_cred (revert_creds (creds));if (ret ==IOU_OK ) {if (issue_flags &IO_URING_F_COMPLETE_DEFER )
io_uring/sqpoll.c +1 -1
@@ -192,7 +192,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)if (to_submit &&wq_has_sleeper (&ctx->sqo_sq_wait))wake_up (&ctx->sqo_sq_wait);if (creds) -put_cred (revert_creds_light (creds)); +put_cred (revert_creds (creds)); }return ret;
kernel/acct.c +1 -1
@@ -541,7 +541,7 @@ static void do_acct_process(struct bsd_acct_struct *acct) } out: current->signal->rlim[RLIMIT_FSIZE ].rlim_cur = flim; -put_cred (revert_creds_light (orig_cred)); +put_cred (revert_creds (orig_cred)); }/**
kernel/cgroup/cgroup.c +1 -1
@@ -5220,7 +5220,7 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf, ret =cgroup_attach_permissions (src_cgrp, dst_cgrp, of->file->f_path.dentry->d_sb, threadgroup, ctx->ns); -put_cred (revert_creds_light (saved_cred)); +put_cred (revert_creds (saved_cred));if (ret) goto out_finish;
kernel/trace/trace_events_user.c +1 -1
@@ -1476,7 +1476,7 @@ static int user_event_set_call_visible(struct user_event *user, bool visible)else ret =trace_remove_event_call (&user->call); -put_cred (revert_creds_light (old_cred)); +put_cred (revert_creds (old_cred));put_cred (cred);return ret;
net/dns_resolver/dns_query.c +1 -1
@@ -126,7 +126,7 @@ int dns_query(struct net *net,*/ saved_cred =override_creds (get_new_cred (dns_resolver_cache)); rkey =request_key_net (&key_type_dns_resolver, desc, net, options); -put_cred (revert_creds_light (saved_cred)); +put_cred (revert_creds (saved_cred));kfree (desc);if (IS_ERR (rkey)) { ret =PTR_ERR (rkey);
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 7/26 firmware: avoid pointless reference count bump
In reply to Christian BraunerThe creds are allocated via prepare_kernel_cred() which has already taken a reference.
--- drivers/base/firmware_loader/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/base/firmware_loader/main.c +1 -2
@@ -912,7 +912,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ret = -ENOMEM ; goto out; } - old_cred =override_creds (get_new_cred (kern_cred)); + old_cred =override_creds (kern_cred); ret =fw_get_filesystem_firmware (device, fw->priv,"" ,NULL );
@@ -945,7 +945,6 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ret =assign_fw (fw, device);put_cred (revert_creds (old_cred)); -put_cred (kern_cred); out:if (ret <0 ) {
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 8/26 sev-dev: avoid pointless cred reference count bump
In reply to Christian Braunerand fix a memory leak while at it. The new creds are created via prepare_creds() and then reverted via put_cred(revert_creds()). The additional reference count bump from override_creds() wasn't even taken into account before.
--- drivers/crypto/ccp/sev-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -1
@@ -244,7 +244,7 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t mif (!cred)return ERR_PTR (-ENOMEM ); cred->fsuid =GLOBAL_ROOT_UID ; - old_cred =override_creds (get_new_cred (cred)); + old_cred =override_creds (cred); fp =file_open_root (&root, filename, flags, mode);path_put (&root);
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 9/26 target_core_configfs: avoid pointless cred reference count bump
In reply to Christian BraunerThe creds are allocated via prepare_kernel_cred() which has already taken a reference.
--- drivers/target/target_core_configfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/target/target_core_configfs.c +1 -2
@@ -3756,10 +3756,9 @@ static int __init target_core_init_configfs(void) ret = -ENOMEM ; goto out; } - old_cred =override_creds (get_new_cred (kern_cred)); + old_cred =override_creds (kern_cred);target_init_dbroot ();put_cred (revert_creds (old_cred)); -put_cred (kern_cred);return 0 ;
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 10/26 aio: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/aio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/aio.c +1 -2
@@ -1639,11 +1639,10 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,static void aio_fsync_work (struct work_struct *work) { struct aio_kiocb *iocb = container_of(work, struct aio_kiocb, fsync.work); -const struct cred *old_cred =override_creds (get_new_cred (iocb->fsync.creds)); +const struct cred *old_cred =override_creds (iocb->fsync.creds); iocb->ki_res.res =vfs_fsync (iocb->fsync.file, iocb->fsync.datasync);put_cred (revert_creds (old_cred)); -put_cred (iocb->fsync.creds);iocb_put (iocb); }
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 11/26 binfmt_misc: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/binfmt_misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/binfmt_misc.c +2 -2
@@ -826,9 +826,9 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,* didn't matter much as only a privileged process could open * the register file. */ - old_cred =override_creds (get_new_cred (file->f_cred)); + old_cred =override_creds (file->f_cred); f =open_exec (e->interpreter); -put_cred (revert_creds (old_cred)); +revert_creds (old_cred);if (IS_ERR (f)) {pr_notice ("register: failed to install interpreter file %s\n" , e->interpreter);
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 12/26 coredump: avoid pointless cred reference count bump
In reply to Christian BraunerThe creds are allocated via prepare_creds() which has already taken a reference.
--- fs/coredump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/coredump.c +2 -2
@@ -576,7 +576,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)if (retval <0 ) goto fail_creds; - old_cred =override_creds (get_new_cred (cred)); + old_cred =override_creds (cred); ispipe =format_corename (&cn, &cprm, &argv, &argc);
@@ -781,7 +781,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)kfree (argv);kfree (cn.corename);coredump_finish (core_dumped); -put_cred (revert_creds (old_cred)); +revert_creds (old_cred); fail_creds:put_cred (cred); fail:
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 13/26 nfs/localio: avoid pointless cred reference count bumps
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/nfs/localio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/nfs/localio.c +4 -4
@@ -371,7 +371,7 @@ static void nfs_local_call_read(struct work_struct *work)struct iov_iter iter;ssize_t status; - save_cred =override_creds (get_new_cred (filp->f_cred)); + save_cred =override_creds (filp->f_cred);nfs_local_iter_init (&iter, iocb,READ );
@@ -381,7 +381,7 @@ static void nfs_local_call_read(struct work_struct *work)nfs_local_read_done (iocb, status);nfs_local_pgio_release (iocb); -put_cred (revert_creds (save_cred)); +revert_creds (save_cred); } static int
@@ -541,7 +541,7 @@ static void nfs_local_call_write(struct work_struct *work)ssize_t status; current->flags |=PF_LOCAL_THROTTLE |PF_MEMALLOC_NOIO ; - save_cred =override_creds (get_new_cred (filp->f_cred)); + save_cred =override_creds (filp->f_cred);nfs_local_iter_init (&iter, iocb,WRITE );
@@ -554,7 +554,7 @@ static void nfs_local_call_write(struct work_struct *work)nfs_local_vfs_getattr (iocb);nfs_local_pgio_release (iocb); -put_cred (revert_creds (save_cred)); +revert_creds (save_cred); current->flags = old_flags; }
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 14/26 nfs/nfs4idmap: avoid pointless reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/nfs/nfs4idmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfs/nfs4idmap.c +2 -2
@@ -311,9 +311,9 @@ static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,const struct user_key_payload *payload;ssize_t ret; - saved_cred =override_creds (get_new_cred (id_resolver_cache)); + saved_cred =override_creds (id_resolver_cache); rkey =nfs_idmap_request_key (name, namelen, type, idmap); -put_cred (revert_creds (saved_cred)); +revert_creds (saved_cred);if (IS_ERR (rkey)) { ret =PTR_ERR (rkey);
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 15/26 nfs/nfs4recover: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/nfsd/nfs4recover.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfsd/nfs4recover.c +1 -2
@@ -81,8 +81,7 @@ nfs4_save_creds(const struct cred **original_creds) new->fsuid =GLOBAL_ROOT_UID ; new->fsgid =GLOBAL_ROOT_GID ; - *original_creds =override_creds (get_new_cred (new)); -put_cred (new); + *original_creds =override_creds (new);return 0 ; }
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 16/26 nfsfh: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/nfsd/nfsfh.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfsd/nfsfh.c +1 -2
@@ -221,8 +221,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net, new->cap_effective =cap_raise_nfsd_set (new->cap_effective, new->cap_permitted); -put_cred (override_creds (get_new_cred (new))); -put_cred (new); +put_cred (override_creds (new)); }else { error =nfsd_setuser_and_check_port (rqstp, cred, exp);if (error)
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 17/26 open: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/open.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
fs/open.c +1 -7
@@ -447,13 +447,7 @@ static const struct cred *access_override_creds(void)* freeing. */ override_cred->non_rcu =1 ; - - old_cred =override_creds (get_new_cred (override_cred)); - -/* override_cred() gets its own ref */ -put_cred (override_cred); - -return old_cred; +return override_creds (override_cred); }static long do_faccessat (int dfd,const char __user *filename,int mode,int flags)
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 18/26 ovl: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/overlayfs/copy_up.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/overlayfs/copy_up.c +2 -4
@@ -741,17 +741,15 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)return err;if (cc->new) - cc->old =override_creds (get_new_cred (cc->new)); + cc->old =override_creds (cc->new);return 0 ; }static void ovl_revert_cu_creds (struct ovl_cu_creds *cc) { -if (cc->new) { +if (cc->new)put_cred (revert_creds (cc->old)); -put_cred (cc->new); - } }/*
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 19/26 cifs: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/smb/client/cifs_spnego.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/cifs_spnego.c +2 -2
@@ -173,9 +173,9 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo, }cifs_dbg (FYI ,"key description = %s\n" , description); - saved_cred =override_creds (get_new_cred (spnego_cred)); + saved_cred =override_creds (spnego_cred); spnego_key =request_key (&cifs_spnego_key_type, description,"" ); -put_cred (revert_creds (saved_cred)); +revert_creds (saved_cred);#ifdef CONFIG_CIFS_DEBUG2 if (cifsFYI && !IS_ERR (spnego_key)) {
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 20/26 cifs: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/smb/client/cifsacl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/smb/client/cifsacl.c +4 -4
@@ -292,7 +292,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid)return -EINVAL ; rc =0 ; - saved_cred =override_creds (get_new_cred (root_cred)); + saved_cred =override_creds (root_cred); sidkey =request_key (&cifs_idmap_key_type, desc,"" );if (IS_ERR (sidkey)) { rc = -EINVAL ;
@@ -327,7 +327,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) out_key_put:key_put (sidkey); out_revert_creds: -put_cred (revert_creds (saved_cred)); +revert_creds (saved_cred);return rc; invalidate_key:
@@ -398,7 +398,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid,if (!sidstr)return -ENOMEM ; - saved_cred =override_creds (get_new_cred (root_cred)); + saved_cred =override_creds (root_cred); sidkey =request_key (&cifs_idmap_key_type, sidstr,"" );if (IS_ERR (sidkey)) { cifs_dbg(FYI, "%s: Can't map SID %s to a %cid\n",
@@ -438,7 +438,7 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid, out_key_put:key_put (sidkey); out_revert_creds: -put_cred (revert_creds (saved_cred)); +revert_creds (saved_cred);kfree (sidstr);/*
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 21/26 smb: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- fs/smb/server/smb_common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/smb/server/smb_common.c +1 -3
@@ -780,7 +780,7 @@ int __ksmbd_override_fsids(struct ksmbd_work *work, cred->cap_effective =cap_drop_fs_set (cred->cap_effective);WARN_ON (work->saved_cred); - work->saved_cred =override_creds (get_new_cred (cred)); + work->saved_cred =override_creds (cred);if (!work->saved_cred) {abort_creds (cred);return -EINVAL ;
@@ -799,9 +799,7 @@ void ksmbd_revert_fsids(struct ksmbd_work *work)WARN_ON (!work->saved_cred); - cred =current_cred ();put_cred (revert_creds (work->saved_cred)); -put_cred (cred); work->saved_cred =NULL ; }
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 22/26 io_uring: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- io_uring/io_uring.c | 4 ++-- io_uring/sqpoll.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
io_uring/io_uring.c +2 -2
@@ -1704,7 +1704,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)return -EBADF ;if (unlikely ((req->flags &REQ_F_CREDS ) && req->creds !=current_cred ())) - creds =override_creds (get_new_cred (req->creds)); + creds =override_creds (req->creds);if (!def->audit_skip)audit_uring_entry (req->opcode);
@@ -1715,7 +1715,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)audit_uring_exit (!ret, ret);if (creds) -put_cred (revert_creds (creds)); +revert_creds (creds);if (ret ==IOU_OK ) {if (issue_flags &IO_URING_F_COMPLETE_DEFER )
io_uring/sqpoll.c +2 -2
@@ -174,7 +174,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)const struct cred *creds =NULL ;if (ctx->sq_creds !=current_cred ()) - creds =override_creds (get_new_cred (ctx->sq_creds)); + creds =override_creds (ctx->sq_creds);mutex_lock (&ctx->uring_lock);if (!wq_list_empty (&ctx->iopoll_list))
@@ -192,7 +192,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries)if (to_submit &&wq_has_sleeper (&ctx->sqo_sq_wait))wake_up (&ctx->sqo_sq_wait);if (creds) -put_cred (revert_creds (creds)); +revert_creds (creds); }return ret;
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 23/26 acct: avoid pointless reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- kernel/acct.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/acct.c +2 -2
@@ -501,7 +501,7 @@ static void do_acct_process(struct bsd_acct_struct *acct) flim =rlimit (RLIMIT_FSIZE ); current->signal->rlim[RLIMIT_FSIZE ].rlim_cur =RLIM_INFINITY ;/* Perform file operations on behalf of whoever enabled accounting */ - orig_cred =override_creds (get_new_cred (file->f_cred)); + orig_cred =override_creds (file->f_cred);/* * First check to see if there is enough free_space to continue
@@ -541,7 +541,7 @@ static void do_acct_process(struct bsd_acct_struct *acct) } out: current->signal->rlim[RLIMIT_FSIZE ].rlim_cur = flim; -put_cred (revert_creds (orig_cred)); +revert_creds (orig_cred); }/**
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 24/26 cgroup: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- kernel/cgroup/cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cgroup.c +2 -2
@@ -5216,11 +5216,11 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,* permissions using the credentials from file open to protect against * inherited fd attacks. */ - saved_cred =override_creds (get_new_cred (of->file->f_cred)); + saved_cred =override_creds (of->file->f_cred); ret =cgroup_attach_permissions (src_cgrp, dst_cgrp, of->file->f_path.dentry->d_sb, threadgroup, ctx->ns); -put_cred (revert_creds (saved_cred)); +revert_creds (saved_cred);if (ret) goto out_finish;
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 25/26 trace: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- kernel/trace/trace_events_user.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/trace/trace_events_user.c +1 -2
@@ -1469,7 +1469,7 @@ static int user_event_set_call_visible(struct user_event *user, bool visible)*/ cred->fsuid =GLOBAL_ROOT_UID ; - old_cred =override_creds (get_new_cred (cred)); + old_cred =override_creds (cred);if (visible) ret =trace_add_event_call (&user->call);
@@ -1477,7 +1477,6 @@ static int user_event_set_call_visible(struct user_event *user, bool visible) ret =trace_remove_event_call (&user->call);put_cred (revert_creds (old_cred)); -put_cred (cred);return ret; }
Signature · 1 line
2.45.2
Christian Brauner
maintainerPATCH 26/26 dns_resolver: avoid pointless cred reference count bump
In reply to Christian BraunerNo need for the extra reference count bump.
--- net/dns_resolver/dns_query.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/dns_resolver/dns_query.c +2 -2
@@ -124,9 +124,9 @@ int dns_query(struct net *net,/* make the upcall, using special credentials to prevent the use of * add_key() to preinstall malicious redirections */ - saved_cred =override_creds (get_new_cred (dns_resolver_cache)); + saved_cred =override_creds (dns_resolver_cache); rkey =request_key_net (&key_type_dns_resolver, desc, net, options); -put_cred (revert_creds (saved_cred)); +revert_creds (saved_cred);kfree (desc);if (IS_ERR (rkey)) { ret =PTR_ERR (rkey);
Signature · 1 line
2.45.2
Amir Goldstein
maintainerRe: [PATCH 07/26] firmware: avoid pointless reference count bump
In reply to Christian BraunerQuoted 23 lines · Christian Brauner
The creds are allocated via
prepare_kernel_cred()which has already taken a reference.Signed-off-by Christian Brauner <[email protected]>--- drivers/base/firmware_loader/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/base/firmware_loader/main.c +1
-1@@ -912,7 +912,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ret = -ENOMEM ; goto out; } - old_cred =override_creds (get_new_cred (kern_cred)); + old_cred =override_creds (kern_cred); ret =fw_get_filesystem_firmware (device, fw->priv,"" ,NULL );
drivers/base/firmware_loader/main.c _request_firmware(const struct firmware **firmware_p, const char *name, · line 948
Quoted 4 lines
drivers/base/firmware_loader/main.c +0
-1@@ -945,7 +945,6 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ret =assign_fw (fw, device);put_cred (revert_creds (old_cred)); -put_cred (kern_cred);
This may seem like nit picking, but I think that:
revert_creds(old_cred));
put_cred(kern_cred);Is nicer. It is more balanced and it is more consistent with the majority of patches in this series which in a balanced manner remove both the get_new_cred from the override_creds line and the put_cred from the revert_creds line.
If someone wanted to, both old_cred and kern_cred could be converted to use scoped cleanup handlers. This is more apparent when the cleanup is explicit on the local kern_cred var.
The same comment applies to a few other patches in this series.
Thanks,
Amir.
Amir Goldstein
maintainerRe: [PATCH 18/26] ovl: avoid pointless cred reference count bump
In reply to Christian BraunerQuoted 19 lines · Christian Brauner
No need for the extra reference count bump.
Signed-off-by Christian Brauner <[email protected]>--- fs/overlayfs/copy_up.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)fs/overlayfs/copy_up.c +1
-1@@ -741,17 +741,15 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)return err;if (cc->new) - cc->old =override_creds (get_new_cred (cc->new)); + cc->old =override_creds (cc->new);
fs/overlayfs/copy_up.c static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc) · line 754
Quoted 10 lines
fs/overlayfs/copy_up.c +1
-3return 0 ; }static void ovl_revert_cu_creds (struct ovl_cu_creds *cc) { -if (cc->new) { +if (cc->new)put_cred (revert_creds (cc->old)); -put_cred (cc->new); - }
Same comment here, I think this will read more clearly as
revert_creds(cc->old));
put_cred(cc->new);and better reflects the counterpart of ovl_prep_cu_creds().
Thanks,
Amir.
Amir Goldstein
maintainerRe: [PATCH 00/26] cred: rework {override,revert}_creds()
In reply to Christian BraunerQuoted 11 lines · Christian Brauner
For the v6.13 cycle we switched overlayfs to a variant of
override_creds()that doesn't take an extra reference. To this end I suggested introducing {override,revert}_creds_light() which overlayfs could use.This seems to work rather well. As Linus correctly points out that we should look into unifying both and simply make {override,revert}_creds() do what {override,revert}_creds_light() currently does. Caller's that really need the extra reference count can take it manually.
Quoted 4 lines
This series does all that. Afaict, most callers can be directly converted over and can avoid the extra reference count completely.
Lightly tested.
FWIW, your work.cred branch passes the overlayfs tests.
Thanks,
Amir.
Quoted 53 lines
---
Christian Brauner (26):
tree-wide: s/override_creds()/override_creds_light(get_new_cred())/g
cred: return old creds fromrevert_creds_light()
tree-wide: s/revert_creds()/put_cred(revert_creds_light())/g
cred: remove old {override,revert}_creds() helpers
tree-wide: s/override_creds_light()/override_creds()/g
tree-wide: s/revert_creds_light()/revert_creds()/g
firmware: avoid pointless reference count bump
sev-dev: avoid pointless cred reference count bump
target_core_configfs: avoid pointless cred reference count bump
aio: avoid pointless cred reference count bump
binfmt_misc: avoid pointless cred reference count bump
coredump: avoid pointless cred reference count bump nfs/localio: avoid pointless cred reference count bumps nfs/nfs4idmap: avoid pointless reference count bump nfs/nfs4recover: avoid pointless cred reference count bump
nfsfh: avoid pointless cred reference count bump
open: avoid pointless cred reference count bump
ovl: avoid pointless cred reference count bump
cifs: avoid pointless cred reference count bump
cifs: avoid pointless cred reference count bump
smb: avoid pointless cred reference count bump
io_uring: avoid pointless cred reference count bump
acct: avoid pointless reference count bump
cgroup: avoid pointless cred reference count bump
trace: avoid pointless cred reference count bump
dns_resolver: avoid pointless cred reference count bumpdrivers/base/firmware_loader/main.c | 3 +-- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/target/target_core_configfs.c | 3 +-- fs/aio.c | 3 +-- fs/backing-file.c | 20 +++++++------- fs/cachefiles/internal.h | 4 +-- fs/nfsd/auth.c | 4 +-- fs/nfsd/filecache.c | 2 +- fs/nfsd/nfs4recover.c | 3 +-- fs/nfsd/nfsfh.c | 1 - fs/open.c | 10 ++----- fs/overlayfs/copy_up.c | 6 ++--- fs/overlayfs/dir.c | 4 +-- fs/overlayfs/util.c | 4 +-- fs/smb/server/smb_common.c | 4 +-- include/linux/cred.h | 14 ++++------ kernel/cred.c | 50 ----------------------------------- kernel/trace/trace_events_user.c | 3 +-- 18 files changed, 35 insertions(+), 105 deletions(-)---
base-commit:228a1157fb9fec47eb135b51c0202b574e079ebf
change-id: 20241124-work-cred-349b65450082
Re: [PATCH 00/26] cred: rework {override,revert}_creds()
In reply to Christian BraunerQuoted 5 lines · Christian Brauner
This series does all that. Afaict, most callers can be directly converted over and can avoid the extra reference count completely.
Lightly tested.
Thanks, this looks good to me. I only had two reactions:
(a) I was surprised that using get_new_cred() apparently "just worked".
I was expecting us to have cases where the cred was marked 'const', because I had this memory of us actively marking things const to make sure people didn't play games with modifying the creds in-place (and then casting away the const just for ref updates).
But apparently that's never the case for override_creds() users, so your patch actually ended up even simpler than I expected in that you didn't end up needing any new helper for just incrementing the refcount on a const cred.
(b) a (slight) reaction was to wish for a short "why" on the
pointless reference bumps
partly to show that it was thought about, but also partly to discourage people from doing it entirely mindlessly in other cases.
I mean, sometimes the reference bumps were just obviously pointless because they ended up being right next to each other after being exposed, like the get/put pattern in access_override_creds().
But in some other cases, like the aio_write case, I think it would have been good to just say
"The refcount is held by iocb->fsync.creds that cannot change over
the operation"
or similar. Or - very similarly - the binfmt_misc uses "file->f_cred", and again, file->f_cred is set at open time and never changed, so we can rely on it staying around for the file lifetime.
I actually don't know if there were any exceptions to this (ie cases where the source of the override cred could actually go away from under us during the operation) where you didn't end up removing the refcount games as a result. You did have a couple of cases where you actually explained why the bump wasn't necessary, but there were a couple where I would have wished for that "the reference count is held by X, which is stable over the whole sequence" kind of notes.
But not a big deal. Even in this form, I think this is a clear and good improvement.
Thanks,
Linus
Al Viro
maintainerRe: [PATCH 08/26] sev-dev: avoid pointless cred reference count bump
In reply to Christian BraunerQuoted 8 lines · Christian Brauner
drivers/crypto/ccp/sev-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/ccp/sev-dev.c +0
-0
drivers/crypto/ccp/sev-dev.c static struct file *open_file_as_root(const char *filename, int flags, umode_t m · line 250
Quoted 8 lines
drivers/crypto/ccp/sev-dev.c +1
-1@@ -244,7 +244,7 @@ static struct file *open_file_as_root(const char *filename, int flags, umode_t mif (!cred)return ERR_PTR (-ENOMEM ); cred->fsuid =GLOBAL_ROOT_UID ; - old_cred =override_creds (get_new_cred (cred)); + old_cred =override_creds (cred); fp =file_open_root (&root, filename, flags, mode);path_put (&root);
Looks sane, but the use of file reads/writes in there does not.
At the very least, this
nwrite = kernel_write(fp, sev_init_ex_buffer, NV_LENGTH, &offset);
vfs_fsync(fp, 0);
filp_close(fp, NULL);
if (nwrite != NV_LENGTH) {
dev_err(sev->dev,
"SEV: failed to write %u bytes to non volatile memory area, ret %ld\n",
NV_LENGTH, nwrite);
return -EIO;
}is either too much or too little - if it's serious about reporting errors, it would better check what fsync and close return...
Oh, well - unrelated to your patchset, obviously
Al Viro
maintainerRe: [PATCH 09/26] target_core_configfs: avoid pointless cred reference count bump
In reply to Christian BraunerQuoted 13 lines · Christian Brauner
The creds are allocated via
prepare_kernel_cred()which has already taken a reference.Signed-off-by Christian Brauner <[email protected]>--- drivers/target/target_core_configfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/target/target_core_configfs.c +0
-0
drivers/target/target_core_configfs.c static int __init target_core_init_configfs(void) · line 3762
Quoted 8 lines
drivers/target/target_core_configfs.c +1
-2@@ -3756,10 +3756,9 @@ static int __init target_core_init_configfs(void) ret = -ENOMEM ; goto out; } - old_cred =override_creds (get_new_cred (kern_cred)); + old_cred =override_creds (kern_cred);target_init_dbroot ();put_cred (revert_creds (old_cred)); -put_cred (kern_cred);
FWIW, I agree with Amir -
revert_creds(old_cred); put_cred(kern_cred);
might be easier to follow. In effect, you have two scopes here - from prepare_kernel_cred() to put_cred() and, nested in it, from override_creds() to revert_creds().
I'm not saying that __cleanup() is the right tool in those cases, but the closing brackets of those scopes would be better off separated.
Al Viro
maintainerRe: [PATCH 21/26] smb: avoid pointless cred reference count bump
In reply to Christian BraunerQuoted 12 lines · Christian Brauner
No need for the extra reference count bump.
Signed-off-by Christian Brauner <[email protected]>--- fs/smb/server/smb_common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/smb/server/smb_common.c +0
-0
fs/smb/server/smb_common.c int __ksmbd_override_fsids(struct ksmbd_work *work, · line 786
Quoted 8 lines
fs/smb/server/smb_common.c +1
-1@@ -780,7 +780,7 @@ int __ksmbd_override_fsids(struct ksmbd_work *work, cred->cap_effective =cap_drop_fs_set (cred->cap_effective);WARN_ON (work->saved_cred); - work->saved_cred =override_creds (get_new_cred (cred)); + work->saved_cred =override_creds (cred);if (!work->saved_cred) {abort_creds (cred);return -EINVAL ;
Won't that leave a dangling pointer?
Christian Brauner
maintainerRe: [PATCH 21/26] smb: avoid pointless cred reference count bump
Quoted 15 lines · Al Viro
Quoted 14 lines · Christian Brauner
No need for the extra reference count bump.
Signed-off-by Christian Brauner <[email protected]>--- fs/smb/server/smb_common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/smb/server/smb_common.c +0
-0@@ -780,7 +780,7 @@ int __ksmbd_override_fsids(struct ksmbd_work *work, cred->cap_effective =cap_drop_fs_set (cred->cap_effective);
Quoted 8 lines
fs/smb/server/smb_common.c int __ksmbd_override_fsids(struct ksmbd_work *work, · line 786
Quoted 6 lines
fs/smb/server/smb_common.c +1
-1WARN_ON (work->saved_cred); - work->saved_cred =override_creds (get_new_cred (cred)); + work->saved_cred =override_creds (cred);if (!work->saved_cred) {abort_creds (cred);return -EINVAL ;Won't that leave a dangling pointer?
Afaict, the whole check doesn't make sense because I don't see how override_creds() could be called on a task with current->cred == NULL. There's no way to opt out of having current->cred set.
Christian Brauner
maintainerRe: [PATCH 18/26] ovl: avoid pointless cred reference count bump
In reply to Amir GoldsteinQuoted 32 lines · Amir Goldstein
Quoted 19 lines · Christian Brauner
No need for the extra reference count bump.
Signed-off-by Christian Brauner <[email protected]>--- fs/overlayfs/copy_up.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)fs/overlayfs/copy_up.c +1
-1@@ -741,17 +741,15 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)return err;if (cc->new) - cc->old =override_creds (get_new_cred (cc->new)); + cc->old =override_creds (cc->new);fs/overlayfs/copy_up.c static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc) · line 754
Quoted 10 lines
fs/overlayfs/copy_up.c +1
-3return 0 ; }static void ovl_revert_cu_creds (struct ovl_cu_creds *cc) { -if (cc->new) { +if (cc->new)put_cred (revert_creds (cc->old)); -put_cred (cc->new); - }Same comment here, I think this will read more clearly as
Quoted 4 lines
revert_creds(cc->old)); put_cred(cc->new);and better reflects the counterpart of
ovl_prep_cu_creds().
Ok, done.
Christian Brauner
maintainerRe: [PATCH 09/26] target_core_configfs: avoid pointless cred reference count bump
In reply to Al ViroQuoted 24 lines · Al Viro
Quoted 13 lines · Christian Brauner
The creds are allocated via
prepare_kernel_cred()which has already taken a reference.Signed-off-by Christian Brauner <[email protected]>--- drivers/target/target_core_configfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/target/target_core_configfs.c +0
-0drivers/target/target_core_configfs.c static int __init target_core_init_configfs(void) · line 3762
Quoted 8 lines
drivers/target/target_core_configfs.c +1
-2@@ -3756,10 +3756,9 @@ static int __init target_core_init_configfs(void) ret = -ENOMEM ; goto out; } - old_cred =override_creds (get_new_cred (kern_cred)); + old_cred =override_creds (kern_cred);target_init_dbroot ();put_cred (revert_creds (old_cred)); -put_cred (kern_cred);FWIW, I agree with Amir -
Quoted 2 lines
revert_creds(old_cred); put_cred(kern_cred);
Ok, done.
Christian Brauner
maintainerRe: [PATCH 00/26] cred: rework {override,revert}_creds()
In reply to Linus TorvaldsQuoted 10 lines · Linus Torvalds
Quoted 5 lines · Christian Brauner
This series does all that. Afaict, most callers can be directly converted over and can avoid the extra reference count completely.
Lightly tested.
Thanks, this looks good to me. I only had two reactions:
(a) I was surprised that using
get_new_cred()apparently "just worked".
There's only one case and that's io_uring where we can just cast because we only need it temporarily during the conversion part of the patch series. Later we don't take any reference count anymore in io_uring.
Quoted 2 lines
(b) a (slight) reaction was to wish for a short "why" on the
pointless reference bumps
Yeah, sorry for some of the patches I just quickly jotted down the same line in the commit message. I updated all those commit messages with actual explanations why that's safe.
Quoted 2 lines
But not a big deal. Even in this form, I think this is a clear and good improvement.
Cool.
Amir Goldstein
maintainerRe: [PATCH 00/26] cred: rework {override,revert}_creds()
In reply to Linus TorvaldsQuoted 38 lines · Linus Torvalds
Quoted 5 lines · Christian Brauner
This series does all that. Afaict, most callers can be directly converted over and can avoid the extra reference count completely.
Lightly tested.
Thanks, this looks good to me. I only had two reactions:
(a) I was surprised that using
get_new_cred()apparently "just worked".I was expecting us to have cases where the cred was marked 'const', because I had this memory of us actively marking things const to make sure people didn't play games with modifying the creds in-place (and then casting away the const just for ref updates).
But apparently that's never the case for
override_creds()users, so your patch actually ended up even simpler than I expected in that you didn't end up needing any new helper for just incrementing the refcount on a const cred.(b) a (slight) reaction was to wish for a short "why" on the
pointless reference bumpspartly to show that it was thought about, but also partly to discourage people from doing it entirely mindlessly in other cases.
I mean, sometimes the reference bumps were just obviously pointless because they ended up being right next to each other after being exposed, like the get/put pattern in
access_override_creds().But in some other cases, like the
aio_writecase, I think it would have been good to just say"The refcount is held by
iocb->fsync.credsthat cannot change over
the operation"
Quoted 8 lines
or similar. Or - very similarly - the
binfmt_miscuses "file->f_cred", and again,file->f_credis set at open time and never changed, so we can rely on it staying around for the file lifetime.I actually don't know if there were any exceptions to this (ie cases where the source of the override cred could actually go away from under us during the operation) where you didn't end up removing the refcount games as a result.
I was asking myself the same question.
I see that cachefiles_{begin,end}_secure() bump the refcount, but they mostly follow a very similar pattern to the cases that do not bump the refcount, so I wonder if you left this out because they were hidden in those inline helpers
or because of the non-trivial case of cachefiles_determine_cache_security() which replaces the 'master' cache_creds?
Other that that, I stared at the creds code in nfsd_file_acquire_local() and nfsd_setuser() more than I would like to admit, with lines like:
/* discard any old override before preparing the new set */
put_cred(revert_creds(get_cred(current_real_cred())));And my only conclusion was this code is complicated enough, so it'd better not use borrowed creds..
Thanks,
Amir.
Re: [PATCH 15/26] nfs/nfs4recover: avoid pointless cred reference count bump
In reply to Christian BraunerQuoted 26 lines · Christian Brauner
No need for the extra reference count bump.
Signed-off-by Christian Brauner <[email protected]>--- fs/nfsd/nfs4recover.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/nfsd/nfs4recover.c +1
-2@@ -81,8 +81,7 @@ nfs4_save_creds(const struct cred **original_creds) new->fsuid =GLOBAL_ROOT_UID ; new->fsgid =GLOBAL_ROOT_GID ; - *original_creds =override_creds (get_new_cred (new)); -put_cred (new); + *original_creds =override_creds (new);return 0 ; }Signature · 2 lines
-- 2.45.2
Signature · 1 line
Chuck Lever
Re: [PATCH 16/26] nfsfh: avoid pointless cred reference count bump
In reply to Christian BraunerQuoted 26 lines · Christian Brauner
No need for the extra reference count bump.
Signed-off-by Christian Brauner <[email protected]>--- fs/nfsd/nfsfh.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/nfsd/nfsfh.c +1
-2@@ -221,8 +221,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net, new->cap_effective =cap_raise_nfsd_set (new->cap_effective, new->cap_permitted); -put_cred (override_creds (get_new_cred (new))); -put_cred (new); +put_cred (override_creds (new)); }else { error =nfsd_setuser_and_check_port (rqstp, cred, exp);if (error)Signature · 2 lines
-- 2.45.2
Signature · 1 line
Chuck Lever
Re: [PATCH 00/26] cred: rework {override,revert}_creds()
In reply to Christian BraunerQuoted 63 lines · Christian Brauner
For the v6.13 cycle we switched overlayfs to a variant of
override_creds()that doesn't take an extra reference. To this end I suggested introducing {override,revert}_creds_light() which overlayfs could use.This seems to work rather well. As Linus correctly points out that we should look into unifying both and simply make {override,revert}_creds() do what {override,revert}_creds_light() currently does. Caller's that really need the extra reference count can take it manually.
This series does all that. Afaict, most callers can be directly converted over and can avoid the extra reference count completely.
Lightly tested.
---
Christian Brauner (26):
tree-wide: s/override_creds()/override_creds_light(get_new_cred())/g
cred: return old creds fromrevert_creds_light()
tree-wide: s/revert_creds()/put_cred(revert_creds_light())/g
cred: remove old {override,revert}_creds() helpers
tree-wide: s/override_creds_light()/override_creds()/g
tree-wide: s/revert_creds_light()/revert_creds()/g
firmware: avoid pointless reference count bump
sev-dev: avoid pointless cred reference count bump
target_core_configfs: avoid pointless cred reference count bump
aio: avoid pointless cred reference count bump
binfmt_misc: avoid pointless cred reference count bump
coredump: avoid pointless cred reference count bump nfs/localio: avoid pointless cred reference count bumps nfs/nfs4idmap: avoid pointless reference count bump nfs/nfs4recover: avoid pointless cred reference count bump
nfsfh: avoid pointless cred reference count bump
open: avoid pointless cred reference count bump
ovl: avoid pointless cred reference count bump
cifs: avoid pointless cred reference count bump
cifs: avoid pointless cred reference count bump
smb: avoid pointless cred reference count bump
io_uring: avoid pointless cred reference count bump
acct: avoid pointless reference count bump
cgroup: avoid pointless cred reference count bump
trace: avoid pointless cred reference count bump
dns_resolver: avoid pointless cred reference count bumpdrivers/base/firmware_loader/main.c | 3 +-- drivers/crypto/ccp/sev-dev.c | 2 +- drivers/target/target_core_configfs.c | 3 +-- fs/aio.c | 3 +-- fs/backing-file.c | 20 +++++++------- fs/cachefiles/internal.h | 4 +-- fs/nfsd/auth.c | 4 +-- fs/nfsd/filecache.c | 2 +- fs/nfsd/nfs4recover.c | 3 +-- fs/nfsd/nfsfh.c | 1 - fs/open.c | 10 ++----- fs/overlayfs/copy_up.c | 6 ++--- fs/overlayfs/dir.c | 4 +-- fs/overlayfs/util.c | 4 +-- fs/smb/server/smb_common.c | 4 +-- include/linux/cred.h | 14 ++++------ kernel/cred.c | 50 ----------------------------------- kernel/trace/trace_events_user.c | 3 +-- 18 files changed, 35 insertions(+), 105 deletions(-)
Quoted 5 lines
---
base-commit:228a1157fb9fec47eb135b51c0202b574e079ebf
change-id: 20241124-work-cred-349b65450082
Nice work. Looks like a fairly straightforward changeover and the new API seems more intuitive. You can add:
Christian Brauner
maintainerRe: [PATCH 00/26] cred: rework {override,revert}_creds()
In reply to Amir GoldsteinQuoted 58 lines · Amir Goldstein
Quoted 38 lines · Linus Torvalds
Quoted 5 lines · Christian Brauner
This series does all that. Afaict, most callers can be directly converted over and can avoid the extra reference count completely.
Lightly tested.
Thanks, this looks good to me. I only had two reactions:
(a) I was surprised that using
get_new_cred()apparently "just worked".I was expecting us to have cases where the cred was marked 'const', because I had this memory of us actively marking things const to make sure people didn't play games with modifying the creds in-place (and then casting away the const just for ref updates).
But apparently that's never the case for
override_creds()users, so your patch actually ended up even simpler than I expected in that you didn't end up needing any new helper for just incrementing the refcount on a const cred.(b) a (slight) reaction was to wish for a short "why" on the
pointless reference bumpspartly to show that it was thought about, but also partly to discourage people from doing it entirely mindlessly in other cases.
I mean, sometimes the reference bumps were just obviously pointless because they ended up being right next to each other after being exposed, like the get/put pattern in
access_override_creds().But in some other cases, like the
aio_writecase, I think it would have been good to just say"The refcount is held by
iocb->fsync.credsthat cannot change over
the operation"Quoted 8 lines
or similar. Or - very similarly - the
binfmt_miscuses "file->f_cred", and again,file->f_credis set at open time and never changed, so we can rely on it staying around for the file lifetime.I actually don't know if there were any exceptions to this (ie cases where the source of the override cred could actually go away from under us during the operation) where you didn't end up removing the refcount games as a result.
I was asking myself the same question.
I see that cachefiles_{begin,end}_secure() bump the refcount, but they mostly follow a very similar pattern to the cases that do not bump the refcount, so I wonder if you left this out because they were hidden in those inline helpers
or because of the non-trivial case ofcachefiles_determine_cache_security()which replaces the 'master'cache_creds?
Quoted 8 lines
Other that that, I stared at the creds code in
nfsd_file_acquire_local()andnfsd_setuser()more than I would like to admit, with lines like:/* discard any old override before preparing the new set */ put_cred(revert_creds(get_cred(current_real_cred())));And my only conclusion was this code is complicated enough, so it'd better not use borrowed creds..
I actually ported cachefilesd and and nfsd in v2. I simply missed them.