diff mbox series

smb: client: split cifsFileInfo bitfields to avoid shared-byte RMW races

Message ID 20260930204723.1555769-1-sorenson@redhat.com
State New
Headers show
Series smb: client: split cifsFileInfo bitfields to avoid shared-byte RMW races | expand

Commit Message

Frank Sorenson Sept. 30, 2026, 8:47 p.m. UTC
The invalidHandle, swapfile, oplock_break_cancelled, offload,
and status_file_deleted fields are stored in the same bitfield byte
in struct cifsFileInfo, but are updated in different code paths that
may run simultaneously, and are protected by different locks.  Since
bitfield assignments generate byte-level read-modify-write operations,
a modification to one flag can overwrite a concurrent modification to
another flag.

To avoid these races, convert these flags from a bitfield to
separate bool fields.

Cc: stable@vger.kernel.org
Fixes: 3bc303c254335 ("cifs: convert oplock breaks to use slow_work facility (try #4)")
Fixes: 4e8aea30f7751 ("smb3: enable swap on SMB3 mounts")
Fixes: ffceb7640cbfe ("smb: client: do not defer close open handles to deleted files")
Fixes: 173217bd73365 ("smb3: retrying on failed server close")
Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
 fs/smb/client/cifsglob.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Namjae Jeon Oct. 1, 2026, 1:42 a.m. UTC | #1
On Thu, Oct 1, 2026 at 5:47 AM Frank Sorenson <sorenson@redhat.com> wrote:
>
> The invalidHandle, swapfile, oplock_break_cancelled, offload,
> and status_file_deleted fields are stored in the same bitfield byte
> in struct cifsFileInfo, but are updated in different code paths that
> may run simultaneously, and are protected by different locks.  Since
> bitfield assignments generate byte-level read-modify-write operations,
> a modification to one flag can overwrite a concurrent modification to
> another flag.
>
> To avoid these races, convert these flags from a bitfield to
> separate bool fields.
>
> Cc: stable@vger.kernel.org
> Fixes: 3bc303c254335 ("cifs: convert oplock breaks to use slow_work facility (try #4)")
> Fixes: 4e8aea30f7751 ("smb3: enable swap on SMB3 mounts")
> Fixes: ffceb7640cbfe ("smb: client: do not defer close open handles to deleted files")
> Fixes: 173217bd73365 ("smb3: retrying on failed server close")
> Signed-off-by: Frank Sorenson <sorenson@redhat.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Thanks!
Paulo Alcantara Oct. 1, 2026, 2:17 a.m. UTC | #2
Frank Sorenson <sorenson@redhat.com> writes:

> The invalidHandle, swapfile, oplock_break_cancelled, offload,
> and status_file_deleted fields are stored in the same bitfield byte
> in struct cifsFileInfo, but are updated in different code paths that
> may run simultaneously, and are protected by different locks.  Since
> bitfield assignments generate byte-level read-modify-write operations,
> a modification to one flag can overwrite a concurrent modification to
> another flag.
>
> To avoid these races, convert these flags from a bitfield to
> separate bool fields.
> ...

Applied.
diff mbox series

Patch

diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 79e4e84f8985..5c5b76a9e9fe 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -1450,11 +1450,11 @@  struct cifsFileInfo {
 	struct dentry *dentry;
 	struct tcon_link *tlink;
 	unsigned int f_flags;
-	bool invalidHandle:1;	/* file closed via session abend */
-	bool swapfile:1;
-	bool oplock_break_cancelled:1;
-	bool status_file_deleted:1; /* file has been deleted */
-	bool offload:1; /* offload final part of _put to a wq */
+	bool invalidHandle;	/* file closed via session abend */
+	bool swapfile;
+	bool oplock_break_cancelled;
+	bool status_file_deleted; /* file has been deleted */
+	bool offload; /* offload final part of _put to a wq */
 	__u16 oplock_epoch; /* epoch from the lease break */
 	__u32 oplock_level; /* oplock/lease level from the lease break */
 	int count;