From: Paul Moore <paul@paul-moore.com>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
viro@zeniv.linux.org.uk, serge@hallyn.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: [PATCH v2 2/2] vfs: avoid duplicating creds in faccessat if possible
Date: Wed, 25 Jan 2023 12:07:48 -0500 [thread overview]
Message-ID: <CAHC9VhRG2gcuuN87sKtsPeF-S2BG1DrSCHruAnCAdCkviHuS3g@mail.gmail.com> (raw)
In-Reply-To: <CAGudoHG-42ziSNT0g8asRj8iGzx-Gn=ETZuXkswER3Daov37=A@mail.gmail.com>
On Wed, Jan 25, 2023 at 10:00 AM Mateusz Guzik <mjguzik@gmail.com> wrote:
> On 1/24/23, Paul Moore <paul@paul-moore.com> wrote:
> > Although I'm looking at this again and realized that only
> > do_faccessat() calls access_override_creds(), so why not just fold the
> > new access_need_override_creds() logic into access_override_creds()?
> > Just have one function that takes the flag value, and returns an
> > old_cred/NULL pointer (or pass old_cred to the function by reference
> > and return an error code); that should still provide the performance
> > win Mateusz is looking for while providing additional safety against
> > out-of-sync changes. I would guess the code would be smaller too.
>
> It is unclear from the description if you are arguing for moving the new
> func into access_override_creds almost as is just put prior to existing
> code *or* mixing checks with assignments.
"arguing" is a bit strong of a word for what I was thinking, it was
more of just tossing out an idea to see if it has any merit with you,
the VFS folks, and possibly Linus.
> static bool *access_override_creds(struct cred **ptr)
> [snip]
> if (!uid_eq(cred->fsuid, cred->uid) ||
> !gid_eq(cred->fsgid, cred->gid))
> return false;
> /* remaining checks go here as well */
> [snip]
>
> override_cred = prepare_creds();
> if (!override_cred) {
> *ptr = NULL;
> return true;
> }
>
> override_cred->fsuid = override_cred->uid;
> override_cred->fsgid = override_cred->gid;
> [snip]
>
> If this is what you had in mind, I note it retains all the duplication
> except in one func body which I'm confident does not buy anything,
> provided the warning comment is added.
>
> At the same time the downside is that it uglifies error handling at the
> callsite, so I would say a net loss.
Yes, I was thinking of combining the two functions into one to better
link the cred checks with the cred adjustments.
> Addition of the warning comment makes sense, but concerns after that
> don't sound legitimate to me.
Well, as we talked about earlier, it's really up to the VFS folks to
pick what they want, and they have been suspiciously quiet thus far.
--
paul-moore.com
prev parent reply other threads:[~2023-01-25 17:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-16 21:21 [PATCH v2 1/2] capability: add cap_isidentical Mateusz Guzik
2023-01-16 21:21 ` [PATCH v2 2/2] vfs: avoid duplicating creds in faccessat if possible Mateusz Guzik
2023-01-20 20:45 ` Paul Moore
2023-01-21 0:50 ` Mateusz Guzik
2023-01-21 1:18 ` Mateusz Guzik
2023-01-23 21:29 ` Paul Moore
2023-01-24 10:16 ` Mateusz Guzik
2023-01-24 17:00 ` Paul Moore
2023-01-24 17:14 ` Linus Torvalds
2023-01-24 18:42 ` Mateusz Guzik
2023-01-24 20:37 ` Linus Torvalds
2023-01-24 21:33 ` Paul Moore
2023-01-25 15:00 ` Mateusz Guzik
2023-01-25 16:17 ` Mateusz Guzik
2023-01-25 17:11 ` Paul Moore
2023-01-25 17:07 ` Paul Moore [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHC9VhRG2gcuuN87sKtsPeF-S2BG1DrSCHruAnCAdCkviHuS3g@mail.gmail.com \
--to=paul@paul-moore.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mjguzik@gmail.com \
--cc=serge@hallyn.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).