From: Paulo Alcantara <pc@manguebit.org>
To: Wang Zhaolong <wangzhaolong@huaweicloud.com>,
sfrench@samba.org, pshilov@microsoft.com, aaptel@suse.com
Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH V2] smb: client: fix use-after-free in cifs_oplock_break
Date: Fri, 11 Jul 2025 11:49:49 -0300 [thread overview]
Message-ID: <aa4ecd85deb859ad32ba7f649321084b@manguebit.org> (raw)
In-Reply-To: <20250707010926.31623-1-wangzhaolong@huaweicloud.com>
Wang Zhaolong <wangzhaolong@huaweicloud.com> writes:
> 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 <wangzhaolong@huaweicloud.com>
> ---
> fs/smb/client/file.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
next prev parent reply other threads:[~2025-07-11 14:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 1:09 Wang Zhaolong
2025-07-11 14:49 ` Paulo Alcantara [this message]
2025-07-11 21:10 ` Steve French
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aa4ecd85deb859ad32ba7f649321084b@manguebit.org \
--to=pc@manguebit.org \
--cc=aaptel@suse.com \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pshilov@microsoft.com \
--cc=samba-technical@lists.samba.org \
--cc=sfrench@samba.org \
--cc=wangzhaolong@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®