cifs: Improve access without FILE_READ_ATTRIBUTES permission
Subsystems (2)
PATCH 1/2 cifs: Do not issue SMB2 CREATE always with FILE_READ_ATTRIBUTES
In reply to Pali RohárNot all SMB2 operations require FILE_READ_ATTRIBUTES access and therefore do not automatically request for FILE_READ_ATTRIBUTES access in every one SMB2 CREATE command.
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).
--- fs/smb/client/smb2file.c | 1 - 1 file changed, 1 deletion(-)
fs/smb/client/smb2file.c +0 -1
@@ -162,7 +162,6 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32if (smb2_path ==NULL )return -ENOMEM ; - oparms->desired_access |=FILE_READ_ATTRIBUTES ; smb2_oplock =SMB2_OPLOCK_LEVEL_BATCH ; rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
Signature · 1 line
2.20.1
PATCH 2/2 cifs: Improve stat() to work also without FILE_READ_ATTRIBUTES
In reply to Pali RohárIf SMB2_OP_QUERY_INFO (called when POSIX extensions are not used) failed with STATUS_ACCESS_DENIED then it means that caller does not have permission to open the path with FILE_READ_ATTRIBUTES access and therefore cannot issue SMB2_OP_QUERY_INFO command.
This will result in the -EACCES error from stat() sycall.
There is an alternative way how to query limited information about path but still suitable for stat() syscall. SMB2 OPEN/CREATE operation returns in its successful response subset of query information.
So try to open the path without FILE_READ_ATTRIBUTES but with MAXIMUM_ALLOWED access which will grant the maximum possible access to the file and the response will contain required query information for stat() syscall.
This will improve smb2_query_path_info() to query also files which do not grant FILE_READ_ATTRIBUTES access to caller.
Note that this change depends on the previous change:
"cifs: Do not issue SMB2 CREATE always with FILE_READ_ATTRIBUTES"
--- fs/smb/client/cifspdu.h | 1 + fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 71 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-)
fs/smb/client/cifspdu.h +1 -0
@@ -217,6 +217,7 @@/* of an input/output request */ #define SYSTEM_SECURITY 0x01000000/* The system access control list */ /* can be read and changed */ +#define MAXIMUM_ALLOWED 0x02000000#define GENERIC_ALL 0x10000000#define GENERIC_EXECUTE 0x20000000#define GENERIC_WRITE 0x40000000
fs/smb/client/smb2glob.h +1 -0
@@ -38,6 +38,7 @@ enum smb2_compound_ops {SMB2_OP_SET_REPARSE ,SMB2_OP_GET_REPARSE ,SMB2_OP_QUERY_WSL_EA , + SMB2_OP_OPEN_QUERY, };/* Used when constructing chained read requests. */
fs/smb/client/smb2inode.c +70 -1
95 lines not on this page · raw message
Signature · 1 line
2.20.1
cover cifs: Improve access without FILE_READ_ATTRIBUTES permission
Linux SMB client currently is not able to access files for which do not have FILE_READ_ATTRIBUTES permission.
For example it is not able to write data into file on SMB server to which has only write access (no read or read attributes access). And applications are not able to get result of stat() syscall on such file.
Test case against Windows SMB server:
1) On SMB server prepare file with only GENERIC_WRITE access for Everyone:
ACL:S-1-1-0:ALLOWED/0x0/0x40000000
2) On SMB server remove all access for file's parent directory
3) Mount share by Linux SMB client and try to append data to that file:
echo test >> /mnt/share/dir/file
4) Try to call: stat /mnt/share/dir/file
Without this change the write test fails because Linux SMB client is trying to open SMB path "\dir\file" with GENERIC_WRITE|FILE_READ_ATTRIBUTES. With this change the test pass as Linux SMB client is not opening file with FILE_READ_ATTRIBUTES access anymore.
Similarly without this change the stat test always fails as Linux SMB client is trying to read attributes via SMB2_OP_QUERY_INFO. With this change, if SMB2_OP_QUERY_INFO fails then Linux SMB client fallbacks for reading stat attributes via OPEN with MAXIMUM_ALLOWED access (which will pass if there is some permission) and OPEN reply will contain attributes required for stat().
Pali Rohár (2):
cifs: Do not issue SMB2 CREATE always with FILE_READ_ATTRIBUTES
cifs: Improve stat() to work also without FILE_READ_ATTRIBUTES
fs/smb/client/cifspdu.h | 1 + fs/smb/client/smb2file.c | 1 - fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 71 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
The obvious question to check is whether this would lead to any issues if desired_access is not passed in in oparms in any cases (ie if it ends up 0), and also that this would not hurt any cases where we want to keep the handle cached (deferred close) but don't have sufficient permission for it to be usable by the subsequent operation (e.g. revalidate or stat)
Quoted 46 lines · Pali Rohár
Linux SMB client currently is not able to access files for which do not have
FILE_READ_ATTRIBUTESpermission.For example it is not able to write data into file on SMB server to which has only write access (no read or read attributes access). And applications are not able to get result of
stat()syscall on such file.Test case against Windows SMB server:
1) On SMB server prepare file with only
GENERIC_WRITEaccess for Everyone:ACL:S-1-1-0:ALLOWED/0x0/0x400000002) On SMB server remove all access for file's parent directory
3) Mount share by Linux SMB client and try to append data to that file:
echo test >>/mnt/share/dir/file4) Try to call: stat
/mnt/share/dir/fileWithout this change the write test fails because Linux SMB client is trying to open SMB path "\dir\file" with GENERIC_WRITE|FILE_READ_ATTRIBUTES. With this change the test pass as Linux SMB client is not opening file with
FILE_READ_ATTRIBUTESaccess anymore.Similarly without this change the stat test always fails as Linux SMB client is trying to read attributes via
SMB2_OP_QUERY_INFO. With this change, ifSMB2_OP_QUERY_INFOfails then Linux SMB client fallbacks for reading stat attributes via OPEN withMAXIMUM_ALLOWEDaccess (which will pass if there is some permission) and OPEN reply will contain attributes required forstat().Pali Rohár (2):
cifs: Do not issue SMB2 CREATE always withFILE_READ_ATTRIBUTES
cifs: Improvestat()to work also withoutFILE_READ_ATTRIBUTESfs/smb/client/cifspdu.h | 1 + fs/smb/client/smb2file.c | 1 - fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 71 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-)--
2.20.1
Signature · 3 lines
Thanks, Steve
Quoted 3 lines · On Saturday 05 October 2024 13:32:12 Steve French wrote:
The obvious question to check is whether this would lead to any issues if
desired_accessis not passed in in oparms in any cases (ie if it ends up 0),
This is good point. IIRC if zero value is in OPEN/CREATE desired_access request then SMB server returns STATUS_ACCESS_DENIED.
So it needs to be checked that desired_access is filled in all usage correctly.
Quoted 4 lines
and also that this would not hurt any cases where we want to keep the handle cached (deferred close) but don't have sufficient permission for it to be usable by the subsequent operation (e.g. revalidate or stat)
I see, so the code needs to be properly checked or tested that all these conditions are handled.
Quoted 53 lines · Pali Rohár
Quoted 46 lines
Linux SMB client currently is not able to access files for which do not have
FILE_READ_ATTRIBUTESpermission.For example it is not able to write data into file on SMB server to which has only write access (no read or read attributes access). And applications are not able to get result of
stat()syscall on such file.Test case against Windows SMB server:
1) On SMB server prepare file with only
GENERIC_WRITEaccess for Everyone:ACL:S-1-1-0:ALLOWED/0x0/0x400000002) On SMB server remove all access for file's parent directory
3) Mount share by Linux SMB client and try to append data to that file:
echo test >>/mnt/share/dir/file4) Try to call: stat
/mnt/share/dir/fileWithout this change the write test fails because Linux SMB client is trying to open SMB path "\dir\file" with GENERIC_WRITE|FILE_READ_ATTRIBUTES. With this change the test pass as Linux SMB client is not opening file with
FILE_READ_ATTRIBUTESaccess anymore.Similarly without this change the stat test always fails as Linux SMB client is trying to read attributes via
SMB2_OP_QUERY_INFO. With this change, ifSMB2_OP_QUERY_INFOfails then Linux SMB client fallbacks for reading stat attributes via OPEN withMAXIMUM_ALLOWEDaccess (which will pass if there is some permission) and OPEN reply will contain attributes required forstat().Pali Rohár (2):
cifs: Do not issue SMB2 CREATE always withFILE_READ_ATTRIBUTES
cifs: Improvestat()to work also withoutFILE_READ_ATTRIBUTESfs/smb/client/cifspdu.h | 1 + fs/smb/client/smb2file.c | 1 - fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 71 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-)--
2.20.1Signature · 3 lines
Thanks, Steve
Quoted 10 lines · On Saturday 05 October 2024 20:44:53 Pali Rohár wrote:
Quoted 3 lines · On Saturday 05 October 2024 13:32:12 Steve French wrote:
The obvious question to check is whether this would lead to any issues if
desired_accessis not passed in in oparms in any cases (ie if it ends up 0),This is good point. IIRC if zero value is in OPEN/CREATE
desired_accessrequest then SMB server returnsSTATUS_ACCESS_DENIED.So it needs to be checked that
desired_accessis filled in all usage correctly.
I have done checks and seems that all callers put some non-zero desired access to smb2_open_file() call. So I think this should not be an issue.
Quoted 7 lines
Quoted 4 lines
and also that this would not hurt any cases where we want to keep the handle cached (deferred close) but don't have sufficient permission for it to be usable by the subsequent operation (e.g. revalidate or stat)
I see, so the code needs to be properly checked or tested that all these conditions are handled.
It looks like that when rdwr_for_fscache is used then proper read/write desired access is asked.
During testing I have not spotted issues.
Also to note, I checked SMB1 code and it already does not automatically add FILE_READ_ATTRIBUTES to desired access during open.
Could you schedule this change for some testing?
Quoted 53 lines
Quoted 53 lines · Pali Rohár
Quoted 46 lines
Linux SMB client currently is not able to access files for which do not have
FILE_READ_ATTRIBUTESpermission.For example it is not able to write data into file on SMB server to which has only write access (no read or read attributes access). And applications are not able to get result of
stat()syscall on such file.Test case against Windows SMB server:
1) On SMB server prepare file with only
GENERIC_WRITEaccess for Everyone:ACL:S-1-1-0:ALLOWED/0x0/0x400000002) On SMB server remove all access for file's parent directory
3) Mount share by Linux SMB client and try to append data to that file:
echo test >>/mnt/share/dir/file4) Try to call: stat
/mnt/share/dir/fileWithout this change the write test fails because Linux SMB client is trying to open SMB path "\dir\file" with GENERIC_WRITE|FILE_READ_ATTRIBUTES. With this change the test pass as Linux SMB client is not opening file with
FILE_READ_ATTRIBUTESaccess anymore.Similarly without this change the stat test always fails as Linux SMB client is trying to read attributes via
SMB2_OP_QUERY_INFO. With this change, ifSMB2_OP_QUERY_INFOfails then Linux SMB client fallbacks for reading stat attributes via OPEN withMAXIMUM_ALLOWEDaccess (which will pass if there is some permission) and OPEN reply will contain attributes required forstat().Pali Rohár (2):
cifs: Do not issue SMB2 CREATE always withFILE_READ_ATTRIBUTES
cifs: Improvestat()to work also withoutFILE_READ_ATTRIBUTESfs/smb/client/cifspdu.h | 1 + fs/smb/client/smb2file.c | 1 - fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 71 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-)--
2.20.1Signature · 3 lines
Thanks, Steve
v2 cover cifs: Improve access without FILE_READ_ATTRIBUTES permission
In reply to Pali RohárLinux SMB client currently is not able to access files for which do not have FILE_READ_ATTRIBUTES permission.
For example it is not able to write data into file on SMB server to which has only write access (no read or read attributes access). And applications are not able to get result of stat() syscall on such file.
Test case against Windows SMB server:
1) On SMB server prepare file with only GENERIC_WRITE access for Everyone:
ACL:S-1-1-0:ALLOWED/0x0/0x40000000
2) On SMB server remove all access for file's parent directory
3) Mount share by Linux SMB client and try to append data to that file:
echo test >> /mnt/share/dir/file
4) Try to call: stat /mnt/share/dir/file
Without this change the write test fails because Linux SMB client is trying to open SMB path "\dir\file" with GENERIC_WRITE|FILE_READ_ATTRIBUTES. With this change the test pass as Linux SMB client is not opening file with FILE_READ_ATTRIBUTES access anymore.
Similarly without this change the stat test always fails as Linux SMB client is trying to read attributes via SMB2_OP_QUERY_INFO. With this change, if SMB2_OP_QUERY_INFO fails then Linux SMB client fallbacks for reading stat attributes via OPEN with MAXIMUM_ALLOWED access (which will pass if there is some permission) and OPEN reply will contain attributes required for stat().
Changes in v2:
* At first attempt still try to open with FILE_READ_ATTRIBUTES and fallback to open without FILE_READ_ATTRIBUTES only on -EACCESS.
Pali Rohár (2):
cifs: Add fallback for SMB2 CREATE without FILE_READ_ATTRIBUTES
cifs: Improve stat() to work also without FILE_READ_ATTRIBUTES
fs/smb/client/cifspdu.h | 1 + fs/smb/client/smb2file.c | 12 ++++++- fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 71 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/2 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).
--- fs/smb/client/smb2file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/smb/client/smb2file.c +10 -1
@@ -152,16 +152,25 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32int err_buftype =CIFS_NO_BUFFER ;struct cifs_fid *fid = oparms->fid;struct network_resiliency_req nr_ioctl_req; +bool retry_without_read_attributes = false; smb2_path =cifs_convert_path_to_utf16 (oparms->path, oparms->cifs_sb);if (smb2_path ==NULL )return -ENOMEM ; - oparms->desired_access |=FILE_READ_ATTRIBUTES ; +if (!(oparms->desired_access &FILE_READ_ATTRIBUTES )) { + oparms->desired_access |=FILE_READ_ATTRIBUTES ; + retry_without_read_attributes = true; + } smb2_oplock =SMB2_OPLOCK_LEVEL_BATCH ; rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, &err_buftype); +if (rc == -EACCES && retry_without_read_attributes) { + oparms->desired_access &= ~FILE_READ_ATTRIBUTES ; + rc =SMB2_open (xid, oparms, smb2_path, &smb2_oplock, smb2_data,NULL , &err_iov, + &err_buftype); + }if (rc && data) {struct smb2_hdr *hdr = err_iov.iov_base;
Signature · 1 line
2.20.1
PATCH v2 2/2 cifs: Improve stat() to work also without FILE_READ_ATTRIBUTES
In reply to Pali RohárIf SMB2_OP_QUERY_INFO (called when POSIX extensions are not used) failed with STATUS_ACCESS_DENIED then it means that caller does not have permission to open the path with FILE_READ_ATTRIBUTES access and therefore cannot issue SMB2_OP_QUERY_INFO command.
This will result in the -EACCES error from stat() sycall.
There is an alternative way how to query limited information about path but still suitable for stat() syscall. SMB2 OPEN/CREATE operation returns in its successful response subset of query information.
So try to open the path without FILE_READ_ATTRIBUTES but with MAXIMUM_ALLOWED access which will grant the maximum possible access to the file and the response will contain required query information for stat() syscall.
This will improve smb2_query_path_info() to query also files which do not grant FILE_READ_ATTRIBUTES access to caller.
--- fs/smb/client/cifspdu.h | 1 + fs/smb/client/smb2file.c | 3 +- fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 71 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 74 insertions(+), 2 deletions(-)
fs/smb/client/cifspdu.h +1 -0
@@ -217,6 +217,7 @@/* of an input/output request */ #define SYSTEM_SECURITY 0x01000000/* The system access control list */ /* can be read and changed */ +#define MAXIMUM_ALLOWED 0x02000000#define GENERIC_ALL 0x10000000#define GENERIC_EXECUTE 0x20000000#define GENERIC_WRITE 0x40000000
fs/smb/client/smb2file.c +2 -1
@@ -158,7 +158,8 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32if (smb2_path ==NULL )return -ENOMEM ; -if (!(oparms->desired_access &FILE_READ_ATTRIBUTES )) { +if (!(oparms->desired_access &FILE_READ_ATTRIBUTES ) && + !(oparms->desired_access &MAXIMUM_ALLOWED )) { oparms->desired_access |=FILE_READ_ATTRIBUTES ; retry_without_read_attributes = true; }
fs/smb/client/smb2glob.h +1 -0
@@ -38,6 +38,7 @@ enum smb2_compound_ops {SMB2_OP_SET_REPARSE ,SMB2_OP_GET_REPARSE ,SMB2_OP_QUERY_WSL_EA , + SMB2_OP_OPEN_QUERY, };/* Used when constructing chained read requests. */
fs/smb/client/smb2inode.c +70 -1
95 lines not on this page · raw message
Signature · 1 line
2.20.1