diff --git a/fs/smb/server/mgmt/user_session.c b/fs/smb/server/mgmt/user_session.c index 3f75049be878..15662fd745ab 100644 --- a/fs/smb/server/mgmt/user_session.c +++ b/fs/smb/server/mgmt/user_session.c @@ -85,6 +85,8 @@ static const char *session_state_string(struct ksmbd_session *session) static const char *session_user_name(struct ksmbd_session *session) { + if (!session->user) + return "(Unauthenticated)"; if (user_guest(session->user)) return "(Guest)"; else if (ksmbd_anonymous_user(session->user)) @@ -94,6 +96,8 @@ static const char *session_user_name(struct ksmbd_session *session) static const char *session_account_type(struct ksmbd_session *session) { + if (!session->user) + return "unauthenticated"; if (user_guest(session->user)) return "guest"; if (ksmbd_anonymous_user(session->user)) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index be226664b8af..b084cca8813c 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -3454,6 +3454,11 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len, if (!eabuf->EaNameLength) goto next; + if (eabuf->name[eabuf->EaNameLength]) { + rc = -EBADMSG; + break; + } + ksmbd_debug(SMB, "name : <%s>, name_len : %u, value_len : %u, next : %u\n", eabuf->name, eabuf->EaNameLength, @@ -3566,7 +3571,8 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, if (fp->cdoption == FILE_OPEN_LE) { if (!strcmp(stream_name, "AFP_AfpInfo") && test_share_config_flag(fp->tcon->share_conf, - KSMBD_SHARE_FLAG_TIME_MACHINE)) { + KSMBD_SHARE_FLAG_TIME_MACHINE) && + test_tree_conn_flag(fp->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { /* * Synthesize an empty AFP_AfpInfo xattr on first access. * type=0/creator=0 tells macOS to use the file extension @@ -3593,6 +3599,9 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, return -EBADF; } + if (!test_tree_conn_flag(fp->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) + return -EACCES; + rc = ksmbd_vfs_setxattr(idmap, path, xattr_stream_name, NULL, 0, 0, false); if (rc < 0) pr_err("Failed to store XATTR stream name :%d\n", rc); @@ -4526,7 +4535,7 @@ int smb2_open(struct ksmbd_work *work) file_info = FILE_OPENED; rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat); if (rc) - goto err_out2; + goto err_out1; goto reconnected_fp; } @@ -4556,7 +4565,7 @@ int smb2_open(struct ksmbd_work *work) rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat); if (rc) - goto err_out2; + goto err_out1; goto reconnected_fp; } @@ -4606,6 +4615,14 @@ int smb2_open(struct ksmbd_work *work) goto err_out2; } } + + /* MS-FSA 2.1.5.1: delete-on-close requires DELETE access */ + if (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE && + !(smb_map_generic_desired_access(req->DesiredAccess) & + FILE_DELETE_LE)) { + rc = -EINVAL; + goto err_out2; + } } if (le32_to_cpu(req->CreateDisposition) > @@ -4875,6 +4892,13 @@ resolve_path: maximal_access = daccess; } + /* MAXIMUM_ALLOWED may not have granted the requested DELETE */ + if (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE && + !(daccess & FILE_DELETE_LE)) { + rc = -EACCES; + goto err_out; + } + open_flags = smb2_create_open_flags(file_present, daccess, req->CreateDisposition, &may_flags, @@ -5606,6 +5630,8 @@ err_out2: if (rc) { if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EBADMSG) + rsp->hdr.Status = STATUS_EA_LIST_INCONSISTENT; else if (rc == -EOPNOTSUPP) rsp->hdr.Status = STATUS_NOT_SUPPORTED; else if ((rc == -EACCES || rc == -ESTALE || rc == -EXDEV) && @@ -9304,6 +9330,8 @@ err_out: } else if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EBADMSG) + rsp->hdr.Status = STATUS_EA_LIST_INCONSISTENT; else if (rc == -EMSGSIZE) rsp->hdr.Status = STATUS_INFO_LENGTH_MISMATCH; else if (rc == -ENOSPC || rc == -EFBIG) diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c index 664f01263611..ab76c5c9e0ea 100644 --- a/fs/smb/server/smbacl.c +++ b/fs/smb/server/smbacl.c @@ -1477,6 +1477,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, int i, found = 0; unsigned int access_bits = 0, denied = 0; struct smb_ace *others_ace = NULL; + bool or_ace = false; struct posix_acl_entry *pa_entry; unsigned int sid_type = SIDOWNER; unsigned short ace_size; @@ -1509,6 +1510,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, is_owner = uid == from_kuid(&init_user_ns, vfsuid_into_kuid(vfsuid)); if (!pdacl->num_aces) { + unsigned int allowed = 0; + /* * An empty (present, zero-ACE) DACL grants no access to * anyone except the object owner's implicit READ_CONTROL @@ -1517,9 +1520,14 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, * not let trailing bytes after a zero-ACE DACL become an * implicit grant. */ - if (!is_owner || - (*pdaccess & ~(FILE_READ_CONTROL_LE | FILE_WRITE_DAC_LE))) + if (is_owner) + allowed = READ_CONTROL | WRITE_DAC; + if (*pdaccess & FILE_MAXIMAL_ACCESS_LE) + requested |= allowed; + if (!allowed || requested & ~allowed) rc = -EACCES; + else + *pdaccess = cpu_to_le32(requested); goto err_out; } @@ -1604,6 +1612,9 @@ next_ace: found = 1; break; } + if (!compare_sids(&sid_owner_rights, &ace->sid) && + !(ace->flags & INHERIT_ONLY_ACE)) + or_ace = true; if (!compare_sids(&sid_everyone, &ace->sid) || !compare_sids(&sid_authusers, &ace->sid)) others_ace = ace; @@ -1625,7 +1636,10 @@ next_ace: else continue; - if (id == uid) { + /* A group entry grants only to the group's members */ + if (id == uid && + (pa_entry->e_tag == ACL_USER || + in_group_p(make_kgid(&init_user_ns, id)))) { mode_to_access_flags(pa_entry->e_perm, 0777, &access_bits); @@ -1645,8 +1659,23 @@ next_ace: if (others_ace) { ace = others_ace; } else { - ksmbd_debug(SMB, "Can't find corresponding sid\n"); - rc = -EACCES; + unsigned int allowed = 0; + + /* + * No ACE names the owner, who may still read and + * change the DACL unless OWNER RIGHTS applies + * (MS-DTYP 2.5.3.2). + */ + if (is_owner && !or_ace) + allowed = READ_CONTROL | WRITE_DAC; + if (*pdaccess & FILE_MAXIMAL_ACCESS_LE) + requested |= allowed; + if (!allowed || requested & ~allowed) { + ksmbd_debug(SMB, "Can't find corresponding sid\n"); + rc = -EACCES; + goto err_out; + } + *pdaccess = cpu_to_le32(requested); goto err_out; } } @@ -1672,8 +1701,8 @@ check_access_bits: } if (granted & ~access_bits) { - ksmbd_debug(SMB, "Access denied with winACL, granted : %x, access_req : %x\n", - granted, le32_to_cpu(ace->access_req)); + ksmbd_debug(SMB, "Access denied with winACL, requested : %x, allowed : %x\n", + granted, access_bits); rc = -EACCES; goto err_out; }