From: Ralph Boehme Date: Wed, 27 Jul 2022 13:58:37 +0000 (+0200) Subject: smbd: skip access checks for stat-opens on streams in open_file() X-Git-Tag: talloc-2.4.0~1480 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f0299abf1b28a14518328710d9f84bef17fd2ecf;p=thirdparty%2Fsamba.git smbd: skip access checks for stat-opens on streams in open_file() For streams, access is already checked in create_file_unixpath() by check_base_file_access(). We already skip the access check in this function when doing an IO open of a file, see above in open_file(), also skip it for "stat opens". BUG: https://bugzilla.samba.org/show_bug.cgi?id=15126 MR: https://gitlab.com/samba-team/samba/-/merge_requests/2643 Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 42e0955f937..6d3dee9ce18 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1611,29 +1611,36 @@ static NTSTATUS open_file(struct smb_request *req, } } - status = smbd_check_access_rights_fsp(dirfsp, - fsp, - false, - access_mask); - - if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) && - posix_open && - S_ISLNK(smb_fname->st.st_ex_mode)) { - /* This is a POSIX stat open for delete - * or rename on a symlink that points - * nowhere. Allow. */ - DEBUG(10,("open_file: allowing POSIX " - "open on bad symlink %s\n", - smb_fname_str_dbg(smb_fname))); - status = NT_STATUS_OK; - } + /* + * Access to streams is checked by checking the basefile and + * that has alreay been checked by check_base_file_access() + * in create_file_unixpath(). + */ + if (!fsp_is_alternate_stream(fsp)) { + status = smbd_check_access_rights_fsp(dirfsp, + fsp, + false, + access_mask); + + if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) && + posix_open && + S_ISLNK(smb_fname->st.st_ex_mode)) { + /* This is a POSIX stat open for delete + * or rename on a symlink that points + * nowhere. Allow. */ + DEBUG(10,("open_file: allowing POSIX " + "open on bad symlink %s\n", + smb_fname_str_dbg(smb_fname))); + status = NT_STATUS_OK; + } - if (!NT_STATUS_IS_OK(status)) { - DBG_DEBUG("smbd_check_access_rights_fsp on file " - "%s returned %s\n", - fsp_str_dbg(fsp), - nt_errstr(status)); - return status; + if (!NT_STATUS_IS_OK(status)) { + DBG_DEBUG("smbd_check_access_rights_fsp on file " + "%s returned %s\n", + fsp_str_dbg(fsp), + nt_errstr(status)); + return status; + } } }