Skip to contentSkip to conversation

smb: client: fix atomic open with O_DIRECT & O_SYNC

PATCH In review Paulo Alcantara 3 participants 3 messages Mar 7 – Mar 9

Subsystems (3)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH 1/1 smb: client: fix atomic open with O_DIRECT & O_SYNC

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().

---
 fs/smb/client/cifsglob.h | 10 ++++++++++
 fs/smb/client/dir.c      |  1 +
 fs/smb/client/file.c     | 18 +++---------------
 3 files changed, 14 insertions(+), 15 deletions(-)
fs/smb/client/cifsglob.h +10 -0
index 6f9b6c72962b..2f4470f9df58 100644
@@ -2375,4 +2375,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 */
fs/smb/client/dir.c +1 -0
index 953f1fee8cb8..4bc217e9a727 100644
@@ -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
fs/smb/client/file.c +3 -15
index cffcf82c1b69..13dda87f7711 100644
@@ -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);
Signature · 1 line
2.53.0
#1 lore raw

merged into cifs-2.6.git for-next pending additional review and testing

Quoted 92 lines · Paulo Alcantara

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().

---
 fs/smb/client/cifsglob.h | 10 ++++++++++
 fs/smb/client/dir.c      |  1 +
 fs/smb/client/file.c     | 18 +++---------------
 3 files changed, 14 insertions(+), 15 deletions(-)
fs/smb/client/cifsglob.h +10 -0
index 6f9b6c72962b..2f4470f9df58 100644
@@ -2375,4 +2375,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 */
fs/smb/client/dir.c +1 -0
index 953f1fee8cb8..4bc217e9a727 100644
@@ -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
fs/smb/client/file.c +3 -16
index cffcf82c1b69..13dda87f7711 100644
@@ -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);
--

2.53.0

Signature · 3 lines
Thanks,

Steve
Acked-by on v1 1/1
#2 lore raw
In reply to Paulo Alcantara
Quoted 92 lines · Paulo Alcantara

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().

---
 fs/smb/client/cifsglob.h | 10 ++++++++++
 fs/smb/client/dir.c      |  1 +
 fs/smb/client/file.c     | 18 +++---------------
 3 files changed, 14 insertions(+), 15 deletions(-)
fs/smb/client/cifsglob.h +10 -0
index 6f9b6c72962b..2f4470f9df58 100644
@@ -2375,4 +2375,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 */
fs/smb/client/dir.c +1 -0
index 953f1fee8cb8..4bc217e9a727 100644
@@ -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
fs/smb/client/file.c +3 -15
index cffcf82c1b69..13dda87f7711 100644
@@ -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);
Signature · 1 line
2.53.0