Skip to content

Commit b95cd1b

Browse files
pcacjrsmfrench
authored andcommitted
smb: client: fix missing timestamp updates after utime(2)
Don't reuse open handle when changing timestamps to prevent the server from disabling automatic timestamp updates as per MS-FSA 2.1.4.17. ---8<--- import os import time filename = '/mnt/foo' def print_stat(prefix): st = os.stat(filename) print(prefix, ': ', time.ctime(st.st_atime), time.ctime(st.st_ctime)) fd = os.open(filename, os.O_CREAT|os.O_TRUNC|os.O_WRONLY, 0o644) print_stat('old') os.utime(fd, None) time.sleep(2) os.write(fd, b'foo') os.close(fd) time.sleep(2) print_stat('new') ---8<--- Before patch: $ mount.cifs //srv/share /mnt -o ... $ python3 run.py old : Fri Oct 3 14:01:21 2025 Fri Oct 3 14:01:21 2025 new : Fri Oct 3 14:01:21 2025 Fri Oct 3 14:01:21 2025 After patch: $ mount.cifs //srv/share /mnt -o ... $ python3 run.py old : Fri Oct 3 17:03:34 2025 Fri Oct 3 17:03:34 2025 new : Fri Oct 3 17:03:36 2025 Fri Oct 3 17:03:36 2025 Fixes: b6f2a0f ("cifs: for compound requests, use open handle if possible") Signed-off-by: Paulo Alcantara (Red Hat) <[email protected]> Cc: Frank Sorenson <[email protected]> Reviewed-by: David Howells <[email protected]> Cc: [email protected] Signed-off-by: Steve French <[email protected]>
1 parent 57ce9f7 commit b95cd1b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

fs/smb/client/smb2inode.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,31 +1382,33 @@ int
13821382
smb2_set_file_info(struct inode *inode, const char *full_path,
13831383
FILE_BASIC_INFO *buf, const unsigned int xid)
13841384
{
1385-
struct cifs_open_parms oparms;
1385+
struct kvec in_iov = { .iov_base = buf, .iov_len = sizeof(*buf), };
13861386
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1387+
struct cifsFileInfo *cfile = NULL;
1388+
struct cifs_open_parms oparms;
13871389
struct tcon_link *tlink;
13881390
struct cifs_tcon *tcon;
1389-
struct cifsFileInfo *cfile;
1390-
struct kvec in_iov = { .iov_base = buf, .iov_len = sizeof(*buf), };
1391-
int rc;
1392-
1393-
if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
1394-
(buf->LastWriteTime == 0) && (buf->ChangeTime == 0) &&
1395-
(buf->Attributes == 0))
1396-
return 0; /* would be a no op, no sense sending this */
1391+
int rc = 0;
13971392

13981393
tlink = cifs_sb_tlink(cifs_sb);
13991394
if (IS_ERR(tlink))
14001395
return PTR_ERR(tlink);
14011396
tcon = tlink_tcon(tlink);
14021397

1403-
cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
1398+
if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
1399+
(buf->LastWriteTime == 0) && (buf->ChangeTime == 0)) {
1400+
if (buf->Attributes == 0)
1401+
goto out; /* would be a no op, no sense sending this */
1402+
cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
1403+
}
1404+
14041405
oparms = CIFS_OPARMS(cifs_sb, tcon, full_path, FILE_WRITE_ATTRIBUTES,
14051406
FILE_OPEN, 0, ACL_NO_MODE);
14061407
rc = smb2_compound_op(xid, tcon, cifs_sb,
14071408
full_path, &oparms, &in_iov,
14081409
&(int){SMB2_OP_SET_INFO}, 1,
14091410
cfile, NULL, NULL, NULL);
1411+
out:
14101412
cifs_put_tlink(tlink);
14111413
return rc;
14121414
}

0 commit comments

Comments
 (0)