Skip to content

Commit 6aa9f1c

Browse files
paliSteve French
authored andcommitted
cifs: Fix access_flags_to_smbopen_mode
When converting access_flags to SMBOPEN mode, check for all possible access flags, not only GENERIC_READ and GENERIC_WRITE flags. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent e94e882 commit 6aa9f1c

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

fs/smb/client/cifssmb.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,15 +1041,31 @@ static __u16 convert_disposition(int disposition)
10411041
static int
10421042
access_flags_to_smbopen_mode(const int access_flags)
10431043
{
1044-
int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE);
1045-
1046-
if (masked_flags == GENERIC_READ)
1047-
return SMBOPEN_READ;
1048-
else if (masked_flags == GENERIC_WRITE)
1044+
/*
1045+
* SYSTEM_SECURITY grants both read and write access to SACL, treat is as read/write.
1046+
* MAXIMUM_ALLOWED grants as many access as possible, so treat it as read/write too.
1047+
* SYNCHRONIZE as is does not grant any specific access, so do not check its mask.
1048+
* If only SYNCHRONIZE bit is specified then fallback to read access.
1049+
*/
1050+
bool with_write_flags = access_flags & (FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA |
1051+
FILE_DELETE_CHILD | FILE_WRITE_ATTRIBUTES | DELETE |
1052+
WRITE_DAC | WRITE_OWNER | SYSTEM_SECURITY |
1053+
MAXIMUM_ALLOWED | GENERIC_WRITE | GENERIC_ALL);
1054+
bool with_read_flags = access_flags & (FILE_READ_DATA | FILE_READ_EA | FILE_EXECUTE |
1055+
FILE_READ_ATTRIBUTES | READ_CONTROL |
1056+
SYSTEM_SECURITY | MAXIMUM_ALLOWED | GENERIC_ALL |
1057+
GENERIC_EXECUTE | GENERIC_READ);
1058+
bool with_execute_flags = access_flags & (FILE_EXECUTE | MAXIMUM_ALLOWED | GENERIC_ALL |
1059+
GENERIC_EXECUTE);
1060+
1061+
if (with_write_flags && with_read_flags)
1062+
return SMBOPEN_READWRITE;
1063+
else if (with_write_flags)
10491064
return SMBOPEN_WRITE;
1050-
1051-
/* just go for read/write */
1052-
return SMBOPEN_READWRITE;
1065+
else if (with_execute_flags)
1066+
return SMBOPEN_EXECUTE;
1067+
else
1068+
return SMBOPEN_READ;
10531069
}
10541070

10551071
int

0 commit comments

Comments
 (0)