From 679c92bb5da8f0077bd8839806988636eedc8c3b Mon Sep 17 00:00:00 2001 From: Wang Zhaolong Date: Fri, 11 Jul 2025 19:22:04 +0800 Subject: [PATCH] smb: client: fix use-after-free in cifs_oplock_break hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICJRGE CVE: NA -------------------------------- A race condition can occur in cifs_oplock_break() leading to a use-after-free of the cinode structure when unmounting: cifs_oplock_break() _cifsFileInfo_put(cfile) cifsFileInfo_put_final() cifs_sb_deactive() [last ref, start releasing sb] kill_sb() kill_anon_super() generic_shutdown_super() evict_inodes() dispose_list() evict() destroy_inode() call_rcu(&inode->i_rcu, i_callback) spin_lock(&cinode->open_file_lock) <- OK [later] i_callback() cifs_free_inode() kmem_cache_free(cinode) spin_unlock(&cinode->open_file_lock) <- UAF cifs_done_oplock_break(cinode) <- UAF The issue occurs when umount has already released its reference to the superblock. When _cifsFileInfo_put() calls cifs_sb_deactive(), this releases the last reference, triggering the immediate cleanup of all inodes under RCU. However, cifs_oplock_break() continues to access the cinode after this point, resulting in use-after-free. Fix this by holding an extra reference to the superblock during the entire oplock break operation. This ensures that the superblock and its inodes remain valid until the oplock break completes. Link: https://bugzilla.kernel.org/show_bug.cgi?id=220309 Fixes: b98749cac4a6 ("CIFS: keep FileInfo handle live during oplock break") Signed-off-by: Wang Zhaolong --- fs/cifs/file.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index e346e6c2227a..d8bad5ec1a52 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4205,11 +4205,19 @@ void cifs_oplock_break(struct work_struct *work) struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo, oplock_break); struct inode *inode = d_inode(cfile->dentry); + struct super_block *sb = inode->i_sb; struct cifsInodeInfo *cinode = CIFS_I(inode); struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); struct TCP_Server_Info *server = tcon->ses->server; int rc = 0; + /* + * Hold a reference to the superblock to prevent it and its inodes + * from being freed while we are accessing cinode. Otherwise, + * _cifsFileInfo_put() may release the last reference to the sb and + * trigger inode eviction. + */ + cifs_sb_active(sb); wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_WRITERS, TASK_UNINTERRUPTIBLE); @@ -4254,6 +4262,7 @@ void cifs_oplock_break(struct work_struct *work) } _cifsFileInfo_put(cfile, false /* do not wait for ourself */); cifs_done_oplock_break(cinode); + cifs_sb_deactive(sb); } /* -- Gitee