Skip to content

Commit e255612

Browse files
paliSteve French
authored andcommitted
cifs: Add fallback for SMB2 CREATE without FILE_READ_ATTRIBUTES
Some operations, like WRITE, does not require FILE_READ_ATTRIBUTES access. So when FILE_READ_ATTRIBUTES is not explicitly requested for smb2_open_file() then first try to do SMB2 CREATE with FILE_READ_ATTRIBUTES access (like it was before) and then fallback to SMB2 CREATE without FILE_READ_ATTRIBUTES access (less common case). This change allows to complete WRITE operation to a file when it does not grant FILE_READ_ATTRIBUTES permission and its parent directory does not grant READ_DATA permission (parent directory READ_DATA is implicit grant of child FILE_READ_ATTRIBUTES permission). Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 4236ac9 commit e255612

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/smb/client/smb2file.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,25 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32
152152
int err_buftype = CIFS_NO_BUFFER;
153153
struct cifs_fid *fid = oparms->fid;
154154
struct network_resiliency_req nr_ioctl_req;
155+
bool retry_without_read_attributes = false;
155156

156157
smb2_path = cifs_convert_path_to_utf16(oparms->path, oparms->cifs_sb);
157158
if (smb2_path == NULL)
158159
return -ENOMEM;
159160

160-
oparms->desired_access |= FILE_READ_ATTRIBUTES;
161+
if (!(oparms->desired_access & FILE_READ_ATTRIBUTES)) {
162+
oparms->desired_access |= FILE_READ_ATTRIBUTES;
163+
retry_without_read_attributes = true;
164+
}
161165
smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH;
162166

163167
rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
164168
&err_buftype);
169+
if (rc == -EACCES && retry_without_read_attributes) {
170+
oparms->desired_access &= ~FILE_READ_ATTRIBUTES;
171+
rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
172+
&err_buftype);
173+
}
165174
if (rc && data) {
166175
struct smb2_hdr *hdr = err_iov.iov_base;
167176

0 commit comments

Comments
 (0)