]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb: client: fix atomic open with O_DIRECT & O_SYNC
authorPaulo Alcantara <pc@manguebit.org>
Sat, 7 Mar 2026 21:20:16 +0000 (18:20 -0300)
committerSteve French <stfrench@microsoft.com>
Tue, 10 Mar 2026 22:21:42 +0000 (17:21 -0500)
When user application requests O_DIRECT|O_SYNC along with O_CREAT on
open(2), CREATE_NO_BUFFER and CREATE_WRITE_THROUGH bits were missed in
CREATE request when performing an atomic open, thus leading to
potentially data integrity issues.

Fix this by setting those missing bits in CREATE request when
O_DIRECT|O_SYNC has been specified in cifs_do_create().

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Reviewed-by: David Howells <dhowells@redhat.com>
Acked-by: Henrique Carvalho <henrique.carvalho@suse.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: linux-cifs@vger.kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/cifsglob.h
fs/smb/client/dir.c
fs/smb/client/file.c

index 6f9b6c72962b09260542b711d4c64e7dc42c7845..bb0fe4b602404d499ef80b8e754cf8fc19d8149f 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/utsname.h>
 #include <linux/sched/mm.h>
 #include <linux/netfs.h>
+#include <linux/fcntl.h>
 #include "cifs_fs_sb.h"
 #include "cifsacl.h"
 #include <crypto/internal/hash.h>
@@ -2375,4 +2376,14 @@ static inline bool cifs_forced_shutdown(const struct cifs_sb_info *sbi)
        return cifs_sb_flags(sbi) & CIFS_MOUNT_SHUTDOWN;
 }
 
+static inline int cifs_open_create_options(unsigned int oflags, int opts)
+{
+       /* O_SYNC also has bit for O_DSYNC so following check picks up either */
+       if (oflags & O_SYNC)
+               opts |= CREATE_WRITE_THROUGH;
+       if (oflags & O_DIRECT)
+               opts |= CREATE_NO_BUFFER;
+       return opts;
+}
+
 #endif /* _CIFS_GLOB_H */
index 953f1fee8cb8c3ed8f94df7b765a6c99c96fe26b..4bc217e9a7275d4c6afd8c301f981a8403899262 100644 (file)
@@ -308,6 +308,7 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned
                goto out;
        }
 
+       create_options |= cifs_open_create_options(oflags, create_options);
        /*
         * if we're not using unix extensions, see if we need to set
         * ATTR_READONLY on the create call
index cffcf82c1b6902360f95017ba2bebb9bacc768bf..13dda87f7711f963c19d79182cca55fd2b452c8c 100644 (file)
@@ -584,15 +584,8 @@ static int cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_
  *********************************************************************/
 
        disposition = cifs_get_disposition(f_flags);
-
        /* BB pass O_SYNC flag through on file attributes .. BB */
-
-       /* O_SYNC also has bit for O_DSYNC so following check picks up either */
-       if (f_flags & O_SYNC)
-               create_options |= CREATE_WRITE_THROUGH;
-
-       if (f_flags & O_DIRECT)
-               create_options |= CREATE_NO_BUFFER;
+       create_options |= cifs_open_create_options(f_flags, create_options);
 
 retry_open:
        oparms = (struct cifs_open_parms) {
@@ -1314,13 +1307,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
                rdwr_for_fscache = 1;
 
        desired_access = cifs_convert_flags(cfile->f_flags, rdwr_for_fscache);
-
-       /* O_SYNC also has bit for O_DSYNC so following check picks up either */
-       if (cfile->f_flags & O_SYNC)
-               create_options |= CREATE_WRITE_THROUGH;
-
-       if (cfile->f_flags & O_DIRECT)
-               create_options |= CREATE_NO_BUFFER;
+       create_options |= cifs_open_create_options(cfile->f_flags,
+                                                  create_options);
 
        if (server->ops->get_lease_key)
                server->ops->get_lease_key(inode, &cfile->fid);