Skip to content

Commit 6cf41fc

Browse files
committed
backing file: free directly
Backing files as used by overlayfs are never installed into file descriptor tables and are explicitly documented as such. They aren't subject to rcu access conditions like regular files are. Their lifetime is bound to the lifetime of the overlayfs file, i.e., they're stashed in ovl_file->private_data and go away otherwise. If they're set as vma->vm_file - which is their main purpose - then they're subject to regular refcount rules and vma->vm_file can't be installed into an fdtable after having been set. All in all I don't see any need for rcu delay here. So free it directly. This all hinges on such hybrid beasts to never actually be installed into fdtables which - as mentioned before - is not allowed. So add an explicit WARN_ON_ONCE() so we catch any case where someone is suddenly trying to install one of those things into a file descriptor table so we can have a nice long chat with them. Link: https://lore.kernel.org/r/20231005-sakralbau-wappnen-f5c31755ed70@brauner Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 7116c0a commit 6cf41fc

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

fs/file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ void fd_install(unsigned int fd, struct file *file)
604604
struct files_struct *files = current->files;
605605
struct fdtable *fdt;
606606

607+
if (WARN_ON_ONCE(unlikely(file->f_mode & FMODE_BACKING)))
608+
return;
609+
607610
rcu_read_lock_sched();
608611

609612
if (unlikely(files->resize_in_progress)) {

fs/file_table.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ struct path *backing_file_real_path(struct file *f)
6161
}
6262
EXPORT_SYMBOL_GPL(backing_file_real_path);
6363

64-
static void file_free_rcu(struct rcu_head *head)
65-
{
66-
struct file *f = container_of(head, struct file, f_rcuhead);
67-
68-
kfree(backing_file(f));
69-
}
70-
7164
static inline void file_free(struct file *f)
7265
{
7366
security_file_free(f);
@@ -76,7 +69,7 @@ static inline void file_free(struct file *f)
7669
put_cred(f->f_cred);
7770
if (unlikely(f->f_mode & FMODE_BACKING)) {
7871
path_put(backing_file_real_path(f));
79-
call_rcu(&f->f_rcuhead, file_free_rcu);
72+
kfree(backing_file(f));
8073
} else {
8174
kmem_cache_free(filp_cachep, f);
8275
}

0 commit comments

Comments
 (0)