From 0d0eff660583c7ec1675323a43c181205ea9b2ae Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Wed, 27 Jul 2022 18:40:21 +0200 Subject: vfs_default: assert all passed in fsp's and names are non-stream type Enforce fsp is a non-stream one in as many VFS operations as possible in vfs_default. We really need an assert here instead of returning an error, as otherwise he can have very hard to diagnose bugs. 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 Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Wed Aug 10 16:32:35 UTC 2022 on sn-devel-184 (cherry picked from commit fc45fcfde51b0b0bdcd524c82a0f9eabf7273045) --- source3/modules/vfs_default.c | 92 +++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 5d8ee98e2ca..48ff174ebbe 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -728,11 +728,7 @@ static int vfswrap_openat(vfs_handle_struct *handle, goto out; } - if (is_named_stream(smb_fname)) { - errno = ENOENT; - result = -1; - goto out; - } + SMB_ASSERT(!is_named_stream(smb_fname)); #ifdef O_PATH have_opath = true; @@ -1327,17 +1323,14 @@ static int vfswrap_renameat(vfs_handle_struct *handle, START_PROFILE(syscall_renameat); - if (is_named_stream(smb_fname_src) || is_named_stream(smb_fname_dst)) { - errno = ENOENT; - goto out; - } + SMB_ASSERT(!is_named_stream(smb_fname_src)); + SMB_ASSERT(!is_named_stream(smb_fname_dst)); result = renameat(fsp_get_pathref_fd(srcfsp), smb_fname_src->base_name, fsp_get_pathref_fd(dstfsp), smb_fname_dst->base_name); - out: END_PROFILE(syscall_renameat); return result; } @@ -1349,14 +1342,11 @@ static int vfswrap_stat(vfs_handle_struct *handle, START_PROFILE(syscall_stat); - if (is_named_stream(smb_fname)) { - errno = ENOENT; - goto out; - } + SMB_ASSERT(!is_named_stream(smb_fname)); result = sys_stat(smb_fname->base_name, &smb_fname->st, lp_fake_directory_create_times(SNUM(handle->conn))); - out: + END_PROFILE(syscall_stat); return result; } @@ -1379,14 +1369,11 @@ static int vfswrap_lstat(vfs_handle_struct *handle, START_PROFILE(syscall_lstat); - if (is_named_stream(smb_fname)) { - errno = ENOENT; - goto out; - } + SMB_ASSERT(!is_named_stream(smb_fname)); result = sys_lstat(smb_fname->base_name, &smb_fname->st, lp_fake_directory_create_times(SNUM(handle->conn))); - out: + END_PROFILE(syscall_lstat); return result; } @@ -1402,10 +1389,7 @@ static int vfswrap_fstatat( START_PROFILE(syscall_fstatat); - if (is_named_stream(smb_fname)) { - errno = ENOENT; - goto out; - } + SMB_ASSERT(!is_named_stream(smb_fname)); result = sys_fstatat( fsp_get_pathref_fd(dirfsp), @@ -1413,7 +1397,7 @@ static int vfswrap_fstatat( sbuf, flags, lp_fake_directory_create_times(SNUM(handle->conn))); - out: + END_PROFILE(syscall_fstatat); return result; } @@ -1510,6 +1494,8 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle, char **out_data = (char **)_out_data; NTSTATUS status; + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + switch (function) { case FSCTL_SET_SPARSE: { @@ -1874,6 +1860,8 @@ static struct tevent_req *vfswrap_get_dos_attributes_send( struct tevent_req *subreq = NULL; struct vfswrap_get_dos_attributes_state *state = NULL; + SMB_ASSERT(!is_named_stream(smb_fname)); + req = tevent_req_create(mem_ctx, &state, struct vfswrap_get_dos_attributes_state); if (req == NULL) { @@ -2030,6 +2018,8 @@ static NTSTATUS vfswrap_fget_dos_attributes(struct vfs_handle_struct *handle, { bool offline; + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + offline = vfswrap_is_offline(handle->conn, fsp->fsp_name); if (offline) { *dosmode |= FILE_ATTRIBUTE_OFFLINE; @@ -2042,6 +2032,8 @@ static NTSTATUS vfswrap_fset_dos_attributes(struct vfs_handle_struct *handle, struct files_struct *fsp, uint32_t dosmode) { + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + return set_ea_dos_attribute(handle->conn, fsp->fsp_name, dosmode); } @@ -2718,15 +2710,12 @@ static int vfswrap_unlinkat(vfs_handle_struct *handle, START_PROFILE(syscall_unlinkat); - if (is_named_stream(smb_fname)) { - errno = ENOENT; - goto out; - } + SMB_ASSERT(!is_named_stream(smb_fname)); + result = unlinkat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, flags); - out: END_PROFILE(syscall_unlinkat); return result; } @@ -3211,6 +3200,8 @@ static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp, START_PROFILE(syscall_linux_setlease); + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + #ifdef HAVE_KERNEL_OPLOCKS_LINUX result = linux_setlease(fsp_get_io_fd(fsp), leasetype); #else @@ -3229,6 +3220,8 @@ static int vfswrap_symlinkat(vfs_handle_struct *handle, START_PROFILE(syscall_symlinkat); + SMB_ASSERT(!is_named_stream(new_smb_fname)); + result = symlinkat(link_target->base_name, fsp_get_pathref_fd(dirfsp), new_smb_fname->base_name); @@ -3246,6 +3239,8 @@ static int vfswrap_readlinkat(vfs_handle_struct *handle, START_PROFILE(syscall_readlinkat); + SMB_ASSERT(!is_named_stream(smb_fname)); + result = readlinkat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, buf, @@ -3266,6 +3261,9 @@ static int vfswrap_linkat(vfs_handle_struct *handle, START_PROFILE(syscall_linkat); + SMB_ASSERT(!is_named_stream(old_smb_fname)); + SMB_ASSERT(!is_named_stream(new_smb_fname)); + result = linkat(fsp_get_pathref_fd(srcfsp), old_smb_fname->base_name, fsp_get_pathref_fd(dstfsp), @@ -3286,6 +3284,8 @@ static int vfswrap_mknodat(vfs_handle_struct *handle, START_PROFILE(syscall_mknodat); + SMB_ASSERT(!is_named_stream(smb_fname)); + result = sys_mknodat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, mode, @@ -3324,6 +3324,8 @@ static int vfswrap_fchflags(vfs_handle_struct *handle, #ifdef HAVE_FCHFLAGS int fd = fsp_get_pathref_fd(fsp); + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + if (!fsp->fsp_flags.is_pathref) { return fchflags(fd, flags); } @@ -3395,6 +3397,8 @@ static NTSTATUS vfswrap_fstreaminfo(vfs_handle_struct *handle, struct stream_struct *streams = *pstreams; NTSTATUS status; + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + if (fsp->fsp_flags.is_directory) { /* * No default streams on directories @@ -3495,6 +3499,9 @@ static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle, NTSTATUS result; START_PROFILE(fget_nt_acl); + + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + result = posix_fget_nt_acl(fsp, security_info, mem_ctx, ppdesc); END_PROFILE(fget_nt_acl); @@ -3506,6 +3513,9 @@ static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp NTSTATUS result; START_PROFILE(fset_nt_acl); + + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + result = set_nt_acl(fsp, security_info_sent, psd); END_PROFILE(fset_nt_acl); return result; @@ -3525,6 +3535,8 @@ static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle, SMB_ACL_TYPE_T type, TALLOC_CTX *mem_ctx) { + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + return sys_acl_get_fd(handle, fsp, type, mem_ctx); } @@ -3533,12 +3545,16 @@ static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle, SMB_ACL_TYPE_T type, SMB_ACL_T theacl) { + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + return sys_acl_set_fd(handle, fsp, type, theacl); } static int vfswrap_sys_acl_delete_def_fd(vfs_handle_struct *handle, files_struct *fsp) { + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + return sys_acl_delete_def_fd(handle, fsp); } @@ -3554,6 +3570,8 @@ static ssize_t vfswrap_fgetxattr(struct vfs_handle_struct *handle, { int fd = fsp_get_pathref_fd(fsp); + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + if (!fsp->fsp_flags.is_pathref) { return fgetxattr(fd, name, value, size); } @@ -3624,6 +3642,8 @@ static struct tevent_req *vfswrap_getxattrat_send( bool have_per_thread_creds = false; bool do_async = false; + SMB_ASSERT(!is_named_stream(smb_fname)); + req = tevent_req_create(mem_ctx, &state, struct vfswrap_getxattrat_state); if (req == NULL) { @@ -3730,10 +3750,9 @@ static void vfswrap_getxattrat_do_sync(struct tevent_req *req) { struct vfswrap_getxattrat_state *state = tevent_req_data( req, struct vfswrap_getxattrat_state); - struct files_struct *fsp = metadata_fsp(state->smb_fname->fsp); state->xattr_size = vfswrap_fgetxattr(state->handle, - fsp, + state->smb_fname->fsp, state->xattr_name, state->xattr_value, talloc_array_length(state->xattr_value)); @@ -3753,7 +3772,6 @@ static void vfswrap_getxattrat_do_async(void *private_data) struct timespec start_time; struct timespec end_time; int ret; - struct files_struct *fsp = metadata_fsp(state->smb_fname->fsp); PROFILE_TIMESTAMP(&start_time); SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes); @@ -3777,7 +3795,7 @@ static void vfswrap_getxattrat_do_async(void *private_data) } state->xattr_size = vfswrap_fgetxattr(state->handle, - fsp, + state->smb_fname->fsp, state->xattr_name, state->xattr_value, talloc_array_length(state->xattr_value)); @@ -3878,6 +3896,8 @@ static ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files { int fd = fsp_get_pathref_fd(fsp); + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + if (!fsp->fsp_flags.is_pathref) { return flistxattr(fd, list, size); } @@ -3904,6 +3924,8 @@ static int vfswrap_fremovexattr(struct vfs_handle_struct *handle, struct files_s { int fd = fsp_get_pathref_fd(fsp); + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + if (!fsp->fsp_flags.is_pathref) { return fremovexattr(fd, name); } @@ -3930,6 +3952,8 @@ static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_stru { int fd = fsp_get_pathref_fd(fsp); + SMB_ASSERT(!fsp_is_alternate_stream(fsp)); + if (!fsp->fsp_flags.is_pathref) { return fsetxattr(fd, name, value, size, flags); } -- cgit v1.2.1