Re: [PATCH v2] fs,security: Fix file_set_fowner LSM hook inconsistencies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
>  	}




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux