mirror of
https://github.com/torvalds/linux.git
synced 2026-10-09 12:06:03 +02:00
ksmbd: fix maximum allowed access checks
The DACL permission check looks for an ACE matching the current user and falls back to the Everyone ACE. It does not consider an Authenticated Users ACE, even though an authenticated session is a member of that well-known group. As a result, opening a file whose access is granted through S-1-5-11 can incorrectly fail with STATUS_ACCESS_DENIED. Treat an Authenticated Users ACE as a fallback entry alongside Everyone. The maximal access calculation also combines access masks from every ACE, regardless of whether its SID applies to the current user. This can grant rights belonging to an unrelated principal. Process only ACEs applying to the user, Everyone, or Authenticated Users, and accumulate allowed and denied masks in ACL order. Preserve explicitly requested access bits so they are validated against the resulting maximal mask. When ACCESS_SYSTEM_SECURITY is denied, report STATUS_PRIVILEGE_NOT_HELD instead of the generic STATUS_ACCESS_DENIED. Access to the system ACL requires a security privilege that ksmbd does not grant. For regular files, include FILE_EXECUTE in maximal access when the client requested GENERIC_EXECUTE and the DACL grants the complete file-read set. Keep a direct FILE_EXECUTE request subject to the explicit DACL bit. This matches the POSIX file ACL mapping without broadening specific execute requests. Do not replace rights from an applicable NT ACE with a POSIX ACL entry. The POSIX ACL is only a fallback when no user, Everyone, or Authenticated Users ACE applies; otherwise it can incorrectly broaden the stored DACL. This fixes smb2.maximum_allowed.maximum_allowed. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
This commit is contained in:
parent
df35438ba9
commit
cc2f133e80
|
|
@ -3619,6 +3619,7 @@ int smb2_open(struct ksmbd_work *work)
|
|||
|
||||
if (file_present && !(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) {
|
||||
rc = smb_check_perm_dacl(conn, &path, &daccess,
|
||||
req->DesiredAccess,
|
||||
sess->user->uid);
|
||||
if (rc)
|
||||
goto err_out;
|
||||
|
|
@ -4191,8 +4192,12 @@ int smb2_open(struct ksmbd_work *work)
|
|||
rsp->hdr.Status = STATUS_INVALID_PARAMETER;
|
||||
else if (rc == -EOPNOTSUPP)
|
||||
rsp->hdr.Status = STATUS_NOT_SUPPORTED;
|
||||
else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV)
|
||||
rsp->hdr.Status = STATUS_ACCESS_DENIED;
|
||||
else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV) {
|
||||
if (req->DesiredAccess & FILE_ACCESS_SYSTEM_SECURITY_LE)
|
||||
rsp->hdr.Status = STATUS_PRIVILEGE_NOT_HELD;
|
||||
else
|
||||
rsp->hdr.Status = STATUS_ACCESS_DENIED;
|
||||
}
|
||||
else if (rc == -ENOENT)
|
||||
rsp->hdr.Status = STATUS_OBJECT_NAME_INVALID;
|
||||
else if (rc == -EPERM)
|
||||
|
|
|
|||
|
|
@ -1432,7 +1432,7 @@ bool smb_inherit_flags(int flags, bool is_dir)
|
|||
}
|
||||
|
||||
int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
|
||||
__le32 *pdaccess, int uid)
|
||||
__le32 *pdaccess, __le32 raw_daccess, int uid)
|
||||
{
|
||||
struct mnt_idmap *idmap = mnt_idmap(path->mnt);
|
||||
struct smb_ntsd *pntsd = NULL;
|
||||
|
|
@ -1442,10 +1442,11 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
|
|||
unsigned int dacl_offset;
|
||||
size_t dacl_struct_end;
|
||||
struct smb_sid sid;
|
||||
int granted = le32_to_cpu(*pdaccess & ~FILE_MAXIMAL_ACCESS_LE);
|
||||
int requested = le32_to_cpu(*pdaccess & ~FILE_MAXIMAL_ACCESS_LE);
|
||||
int granted = requested;
|
||||
struct smb_ace *ace;
|
||||
int i, found = 0;
|
||||
unsigned int access_bits = 0;
|
||||
unsigned int access_bits = 0, denied = 0;
|
||||
struct smb_ace *others_ace = NULL;
|
||||
struct posix_acl_entry *pa_entry;
|
||||
unsigned int sid_type = SIDOWNER;
|
||||
|
|
@ -1479,10 +1480,13 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
|
|||
goto err_out;
|
||||
}
|
||||
|
||||
if (*pdaccess & FILE_MAXIMAL_ACCESS_LE) {
|
||||
granted = READ_CONTROL | WRITE_DAC | FILE_READ_ATTRIBUTES |
|
||||
DELETE;
|
||||
if (!uid)
|
||||
sid_type = SIDUNIX_USER;
|
||||
id_to_sid(uid, sid_type, &sid);
|
||||
|
||||
if (*pdaccess & FILE_MAXIMAL_ACCESS_LE) {
|
||||
access_bits = READ_CONTROL | WRITE_DAC | FILE_READ_ATTRIBUTES |
|
||||
DELETE;
|
||||
ace = (struct smb_ace *)((char *)pdacl + sizeof(struct smb_acl));
|
||||
aces_size = acl_size - sizeof(struct smb_acl);
|
||||
for (i = 0; i < le16_to_cpu(pdacl->num_aces); i++) {
|
||||
|
|
@ -1495,15 +1499,41 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
|
|||
CIFS_SID_BASE_SIZE)
|
||||
break;
|
||||
aces_size -= ace_size;
|
||||
granted |= le32_to_cpu(ace->access_req);
|
||||
|
||||
if (ace->sid.num_subauth > SID_MAX_SUB_AUTHORITIES ||
|
||||
ace_size < offsetof(struct smb_ace, sid) +
|
||||
CIFS_SID_BASE_SIZE +
|
||||
sizeof(__le32) * ace->sid.num_subauth)
|
||||
break;
|
||||
|
||||
if (ace->flags & INHERIT_ONLY_ACE ||
|
||||
(compare_sids(&sid, &ace->sid) &&
|
||||
compare_sids(&sid_unix_NFS_mode, &ace->sid) &&
|
||||
compare_sids(&sid_everyone, &ace->sid) &&
|
||||
compare_sids(&sid_authusers, &ace->sid)))
|
||||
goto next_ace;
|
||||
|
||||
switch (ace->type) {
|
||||
case ACCESS_ALLOWED_ACE_TYPE:
|
||||
access_bits |= le32_to_cpu(ace->access_req);
|
||||
break;
|
||||
case ACCESS_DENIED_ACE_TYPE:
|
||||
case ACCESS_DENIED_CALLBACK_ACE_TYPE:
|
||||
denied |= ~access_bits &
|
||||
le32_to_cpu(ace->access_req);
|
||||
break;
|
||||
}
|
||||
next_ace:
|
||||
ace = (struct smb_ace *)((char *)ace + le16_to_cpu(ace->size));
|
||||
}
|
||||
access_bits &= ~denied;
|
||||
if ((raw_daccess & FILE_GENERIC_EXECUTE_LE) &&
|
||||
S_ISREG(d_inode(path->dentry)->i_mode) &&
|
||||
(access_bits & GENERIC_READ_FLAGS) == GENERIC_READ_FLAGS)
|
||||
access_bits |= FILE_EXECUTE;
|
||||
granted = requested | access_bits;
|
||||
}
|
||||
|
||||
if (!uid)
|
||||
sid_type = SIDUNIX_USER;
|
||||
id_to_sid(uid, sid_type, &sid);
|
||||
|
||||
ace = (struct smb_ace *)((char *)pdacl + sizeof(struct smb_acl));
|
||||
aces_size = acl_size - sizeof(struct smb_acl);
|
||||
for (i = 0; i < le16_to_cpu(pdacl->num_aces); i++) {
|
||||
|
|
@ -1527,25 +1557,16 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
|
|||
found = 1;
|
||||
break;
|
||||
}
|
||||
if (!compare_sids(&sid_everyone, &ace->sid))
|
||||
if (!compare_sids(&sid_everyone, &ace->sid) ||
|
||||
!compare_sids(&sid_authusers, &ace->sid))
|
||||
others_ace = ace;
|
||||
|
||||
ace = (struct smb_ace *)((char *)ace + le16_to_cpu(ace->size));
|
||||
}
|
||||
|
||||
if (*pdaccess & FILE_MAXIMAL_ACCESS_LE && found) {
|
||||
granted = READ_CONTROL | WRITE_DAC | FILE_READ_ATTRIBUTES |
|
||||
DELETE;
|
||||
|
||||
granted |= le32_to_cpu(ace->access_req);
|
||||
|
||||
if (!pdacl->num_aces)
|
||||
granted = GENERIC_ALL_FLAGS;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) {
|
||||
posix_acls = get_inode_acl(d_inode(path->dentry), ACL_TYPE_ACCESS);
|
||||
if (!IS_ERR_OR_NULL(posix_acls) && !found) {
|
||||
if (!IS_ERR_OR_NULL(posix_acls) && !found && !others_ace) {
|
||||
unsigned int id = -1;
|
||||
|
||||
pa_entry = posix_acls->a_entries;
|
||||
|
|
@ -1583,14 +1604,16 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
|
|||
}
|
||||
}
|
||||
|
||||
switch (ace->type) {
|
||||
case ACCESS_ALLOWED_ACE_TYPE:
|
||||
access_bits = le32_to_cpu(ace->access_req);
|
||||
break;
|
||||
case ACCESS_DENIED_ACE_TYPE:
|
||||
case ACCESS_DENIED_CALLBACK_ACE_TYPE:
|
||||
access_bits = le32_to_cpu(~ace->access_req);
|
||||
break;
|
||||
if (!(*pdaccess & FILE_MAXIMAL_ACCESS_LE)) {
|
||||
switch (ace->type) {
|
||||
case ACCESS_ALLOWED_ACE_TYPE:
|
||||
access_bits = le32_to_cpu(ace->access_req);
|
||||
break;
|
||||
case ACCESS_DENIED_ACE_TYPE:
|
||||
case ACCESS_DENIED_CALLBACK_ACE_TYPE:
|
||||
access_bits = le32_to_cpu(~ace->access_req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
check_access_bits:
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ bool smb_inherit_flags(int flags, bool is_dir);
|
|||
int smb_inherit_dacl(struct ksmbd_conn *conn, const struct path *path,
|
||||
unsigned int uid, unsigned int gid);
|
||||
int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
|
||||
__le32 *pdaccess, int uid);
|
||||
__le32 *pdaccess, __le32 raw_daccess, int uid);
|
||||
int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
|
||||
const struct path *path, struct smb_ntsd *pntsd, int ntsd_len,
|
||||
bool type_check, bool get_write);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user