]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_default: assert all passed in fsp's and names are non-stream type
authorRalph Boehme <slow@samba.org>
Wed, 27 Jul 2022 16:40:21 +0000 (18:40 +0200)
committerJule Anger <janger@samba.org>
Tue, 6 Sep 2022 06:32:13 +0000 (06:32 +0000)
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 <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Wed Aug 10 16:32:35 UTC 2022 on sn-devel-184

(backported from commit fc45fcfde51b0b0bdcd524c82a0f9eabf7273045)
[slow@samba.org: skip some hunks that are not applicable]

source3/modules/vfs_default.c

index 26595d368483f6c70d186449944764beeeb59c80..569d3c1fb507ad7ddbd3d50c3da0429308dc1435 100644 (file)
@@ -700,11 +700,7 @@ static int vfswrap_openat(vfs_handle_struct *handle,
 
        START_PROFILE(syscall_openat);
 
-       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;
@@ -729,7 +725,6 @@ static int vfswrap_openat(vfs_handle_struct *handle,
 
        fsp->fsp_flags.have_proc_fds = fsp->conn->have_proc_fds;
 
-out:
        END_PROFILE(syscall_openat);
        return result;
 }
@@ -1250,17 +1245,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;
 }
@@ -1272,14 +1264,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;
 }
@@ -1302,14 +1291,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;
 }
@@ -1407,6 +1393,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:
        {
@@ -1771,6 +1759,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) {
@@ -1927,6 +1917,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;
@@ -1939,6 +1931,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);
 }
 
@@ -2607,15 +2601,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;
 }
@@ -3100,6 +3091,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
@@ -3118,6 +3111,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);
@@ -3135,6 +3130,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,
@@ -3155,6 +3152,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),
@@ -3175,6 +3175,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,
@@ -3213,6 +3215,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);
        }
@@ -3288,6 +3292,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
@@ -3388,6 +3394,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);
@@ -3399,6 +3408,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;
@@ -3418,6 +3430,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);
 }
 
@@ -3426,12 +3440,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);
 }
 
@@ -3447,6 +3465,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);
        }
@@ -3517,6 +3537,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) {
@@ -3623,14 +3645,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 = state->smb_fname->fsp;
-
-       if (fsp->base_fsp != NULL) {
-               fsp = fsp->base_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));
@@ -3650,11 +3667,6 @@ static void vfswrap_getxattrat_do_async(void *private_data)
        struct timespec start_time;
        struct timespec end_time;
        int ret;
-       struct files_struct *fsp = state->smb_fname->fsp;
-
-       if (fsp->base_fsp != NULL) {
-               fsp = fsp->base_fsp;
-       }
 
        PROFILE_TIMESTAMP(&start_time);
        SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
@@ -3678,7 +3690,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));
@@ -3779,6 +3791,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);
        }
@@ -3805,6 +3819,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);
        }
@@ -3831,6 +3847,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);
        }