vfs_io_uring: make use of sys_valid_io_range() in vfs_io_uring_pread_send()
authorStefan Metzmacher <metze@samba.org>
Fri, 8 May 2020 11:17:05 +0000 (13:17 +0200)
committerKarolin Seeger <kseeger@samba.org>
Thu, 14 May 2020 07:25:45 +0000 (07:25 +0000)
This makes the follow up commits easier as we don't have to care
about overflows.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14361

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 5005ae3fb24018e370ae60cc23c5e9cfe8357bc9)

source3/modules/vfs_io_uring.c

index 0f560c95b67de236d2d501fb171b1e1842ad017c..c7565b8c39debb3241663e775a68a30721ce0050 100644 (file)
@@ -25,6 +25,7 @@
 #include "smbd/smbd.h"
 #include "smbd/globals.h"
 #include "lib/util/tevent_unix.h"
+#include "lib/util/sys_rw.h"
 #include "smbprofile.h"
 #include <liburing.h>
 
@@ -313,6 +314,7 @@ static struct tevent_req *vfs_io_uring_pread_send(struct vfs_handle_struct *hand
        struct tevent_req *req = NULL;
        struct vfs_io_uring_pread_state *state = NULL;
        struct vfs_io_uring_config *config = NULL;
+       bool ok;
 
        SMB_VFS_HANDLE_GET_DATA(handle, config,
                                struct vfs_io_uring_config,
@@ -331,6 +333,12 @@ static struct tevent_req *vfs_io_uring_pread_send(struct vfs_handle_struct *hand
                                     state->ur.profile_bytes, n);
        SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->ur.profile_bytes);
 
+       ok = sys_valid_io_range(offset, n);
+       if (!ok) {
+               tevent_req_error(req, EINVAL);
+               return tevent_req_post(req, ev);
+       }
+
        state->iov.iov_base = (void *)data;
        state->iov.iov_len = n;
        io_uring_prep_readv(&state->ur.sqe,