Thread (11 messages) 11 messages, 3 authors, 2024-08-14

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

flat view

From: Mateusz Guzik <hidden>
Date: 2024-08-12 21:45:42
Also in: linux-fsdevel, lkml, selinux

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/ (local)

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:
quoted hunk ↗ jump to hunk
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);
	}
quoted hunk ↗ jump to hunk
 	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);
quoted hunk ↗ jump to hunk
 	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;
 	}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help