[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <o6ptrfa7gjdukphqtp6dakq3ykndrjusuhi4fyvpc5ne6amcig@lqbdb2dg7yzv>
Date: Mon, 12 Aug 2024 23:45:29 +0200
From: Mateusz Guzik <mjguzik@...il.com>
To: Mickaël Salaün <mic@...ikod.net>
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 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/
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:
> 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