[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240813.iidaejohj5Oo@digikod.net>
Date: Tue, 13 Aug 2024 12:09:19 +0200
From: Mickaël Salaün <mic@...ikod.net>
To: Mateusz Guzik <mjguzik@...il.com>
Cc: Christian Brauner <brauner@...nel.org>,
Paul Moore <paul@...l-moore.com>, linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-security-module@...r.kernel.org, selinux@...r.kernel.org, Jan Kara <jack@...e.cz>,
Tahera Fahimi <fahimitahera@...il.com>, Al Viro <viro@...iv.linux.org.uk>,
Casey Schaufler <casey@...aufler-ca.com>, James Morris <jmorris@...ei.org>, Jann Horn <jannh@...gle.com>,
Ondrej Mosnacek <omosnace@...hat.com>, "Serge E . Hallyn" <serge@...lyn.com>,
Stephen Smalley <stephen.smalley.work@...il.com>
Subject: Re: [PATCH v2] fs,security: Fix file_set_fowner LSM hook
inconsistencies
On Mon, Aug 12, 2024 at 11:45:29PM +0200, Mateusz Guzik wrote:
> On Mon, Aug 12, 2024 at 07:44:17PM +0200, Mickaël Salaün wrote:
>
> No opinion about the core idea, I'll note though that this conflicts
> with a patch to move f_owner out of the struct:
> https://lore.kernel.org/linux-fsdevel/20240809-koriander-biobauer-6237cbc106f3@brauner/
Thanks for the heads-up.
>
> Presumably nothing which can't get sorted out with some shoveling.
>
> I do have actionable remark concerning creds though: both get_cred and
> put_cred are slow. Sorting that out is on my todo list.
>
> In the meantime adding more calls can be avoided:
OK, I'll add that in the next version.
>
> > diff --git a/fs/file_table.c b/fs/file_table.c
> > index 4f03beed4737..d28b76aef4f3 100644
> > --- a/fs/file_table.c
> > +++ b/fs/file_table.c
> > @@ -66,6 +66,7 @@ static inline void file_free(struct file *f)
> > if (likely(!(f->f_mode & FMODE_NOACCOUNT)))
> > percpu_counter_dec(&nr_files);
> > put_cred(f->f_cred);
> > + put_cred(f->f_owner.cred);
>
> if (likely(f->f_cred == f->f_owner.cred)) {
> put_cred_many(f->f_cred, 2);
> } else {
> put_cred(f->f_cred);
> put_cred(f->f_owner.cred);
> }
>
> > if (unlikely(f->f_mode & FMODE_BACKING)) {
> > path_put(backing_file_user_path(f));
> > kfree(backing_file(f));
> > @@ -149,9 +150,11 @@ static int init_file(struct file *f, int flags, const struct cred *cred)
> > int error;
> >
> > f->f_cred = get_cred(cred);
> > + f->f_owner.cred = get_cred(cred);
>
> f->f_cred = f->f_owner.cred = get_cred_many(cred, 2);
>
> > error = security_file_alloc(f);
> > if (unlikely(error)) {
> > put_cred(f->f_cred);
> > + put_cred(f->f_owner.cred);
>
> put_cred_many(cred, 2);
>
> > return error;
> > }
>
Powered by blists - more mailing lists