]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
cifs: open files should not hold ref on superblock
authorShyam Prasad N <sprasad@microsoft.com>
Wed, 4 Mar 2026 12:45:53 +0000 (18:15 +0530)
committerSteve French <stfrench@microsoft.com>
Wed, 4 Mar 2026 16:11:39 +0000 (10:11 -0600)
commit340cea84f691c5206561bb2e0147158fe02070be
treeec6a45086fff2d598b8e62c96caec18e1819f95f
parent26bc83b88bbbf054f0980a4a42047a8d1e210e4c
cifs: open files should not hold ref on superblock

Today whenever we deal with a file, in addition to holding
a reference on the dentry, we also get a reference on the
superblock. This happens in two cases:
1. when a new cinode is allocated
2. when an oplock break is being processed

The reasoning for holding the superblock ref was to make sure
that when umount happens, if there are users of inodes and
dentries, it does not try to clean them up and wait for the
last ref to superblock to be dropped by last of such users.

But the side effect of doing that is that umount silently drops
a ref on the superblock and we could have deferred closes and
lease breaks still holding these refs.

Ideally, we should ensure that all of these users of inodes and
dentries are cleaned up at the time of umount, which is what this
code is doing.

This code change allows these code paths to use a ref on the
dentry (and hence the inode). That way, umount is
ensured to clean up SMB client resources when it's the last
ref on the superblock (For ex: when same objects are shared).

The code change also moves the call to close all the files in
deferred close list to the umount code path. It also waits for
oplock_break workers to be flushed before calling
kill_anon_super (which eventually frees up those objects).

Fixes: 24261fc23db9 ("cifs: delay super block destruction until all cifsFileInfo objects are gone")
Fixes: 705c79101ccf ("smb: client: fix use-after-free in cifs_oplock_break")
Cc: <stable@vger.kernel.org>
Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/cifsfs.c
fs/smb/client/cifsproto.h
fs/smb/client/file.c
fs/smb/client/misc.c
fs/smb/client/trace.h