Skip to content

Commit 4a7d272

Browse files
pcacjrsmfrench
authored andcommitted
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(). Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Paulo Alcantara (Red Hat) <[email protected]> Reviewed-by: David Howells <[email protected]> Acked-by: Henrique Carvalho <[email protected]> Cc: Tom Talpey <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Steve French <[email protected]>
1 parent 1f318b9 commit 4a7d272

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

fs/smb/client/cifsglob.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/utsname.h>
2121
#include <linux/sched/mm.h>
2222
#include <linux/netfs.h>
23+
#include <linux/fcntl.h>
2324
#include "cifs_fs_sb.h"
2425
#include "cifsacl.h"
2526
#include <crypto/internal/hash.h>
@@ -2375,4 +2376,14 @@ static inline bool cifs_forced_shutdown(const struct cifs_sb_info *sbi)
23752376
return cifs_sb_flags(sbi) & CIFS_MOUNT_SHUTDOWN;
23762377
}
23772378

2379+
static inline int cifs_open_create_options(unsigned int oflags, int opts)
2380+
{
2381+
/* O_SYNC also has bit for O_DSYNC so following check picks up either */
2382+
if (oflags & O_SYNC)
2383+
opts |= CREATE_WRITE_THROUGH;
2384+
if (oflags & O_DIRECT)
2385+
opts |= CREATE_NO_BUFFER;
2386+
return opts;
2387+
}
2388+
23782389
#endif /* _CIFS_GLOB_H */

fs/smb/client/dir.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned
308308
goto out;
309309
}
310310

311+
create_options |= cifs_open_create_options(oflags, create_options);
311312
/*
312313
* if we're not using unix extensions, see if we need to set
313314
* ATTR_READONLY on the create call

fs/smb/client/file.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,8 @@ static int cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_
584584
*********************************************************************/
585585

586586
disposition = cifs_get_disposition(f_flags);
587-
588587
/* BB pass O_SYNC flag through on file attributes .. BB */
589-
590-
/* O_SYNC also has bit for O_DSYNC so following check picks up either */
591-
if (f_flags & O_SYNC)
592-
create_options |= CREATE_WRITE_THROUGH;
593-
594-
if (f_flags & O_DIRECT)
595-
create_options |= CREATE_NO_BUFFER;
588+
create_options |= cifs_open_create_options(f_flags, create_options);
596589

597590
retry_open:
598591
oparms = (struct cifs_open_parms) {
@@ -1314,13 +1307,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
13141307
rdwr_for_fscache = 1;
13151308

13161309
desired_access = cifs_convert_flags(cfile->f_flags, rdwr_for_fscache);
1317-
1318-
/* O_SYNC also has bit for O_DSYNC so following check picks up either */
1319-
if (cfile->f_flags & O_SYNC)
1320-
create_options |= CREATE_WRITE_THROUGH;
1321-
1322-
if (cfile->f_flags & O_DIRECT)
1323-
create_options |= CREATE_NO_BUFFER;
1310+
create_options |= cifs_open_create_options(cfile->f_flags,
1311+
create_options);
13241312

13251313
if (server->ops->get_lease_key)
13261314
server->ops->get_lease_key(inode, &cfile->fid);

0 commit comments

Comments
 (0)