Blame SOURCES/kvm-virtiofsd-check-input-buffer-size-in-fuse_lowlevel.c.patch

22c213
From d6a0067e6c08523a8f605f775be980eaf0a23690 Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:01:23 +0100
22c213
Subject: [PATCH 052/116] virtiofsd: check input buffer size in fuse_lowlevel.c
22c213
 ops
22c213
MIME-Version: 1.0
22c213
Content-Type: text/plain; charset=UTF-8
22c213
Content-Transfer-Encoding: 8bit
22c213
22c213
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Message-id: <20200127190227.40942-49-dgilbert@redhat.com>
22c213
Patchwork-id: 93503
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 048/112] virtiofsd: check input buffer size in fuse_lowlevel.c ops
22c213
Bugzilla: 1694164
22c213
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
22c213
22c213
From: Stefan Hajnoczi <stefanha@redhat.com>
22c213
22c213
Each FUSE operation involves parsing the input buffer.  Currently the
22c213
code assumes the input buffer is large enough for the expected
22c213
arguments.  This patch uses fuse_mbuf_iter to check the size.
22c213
22c213
Most operations are simple to convert.  Some are more complicated due to
22c213
variable-length inputs or different sizes depending on the protocol
22c213
version.
22c213
22c213
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
Reviewed-by: Sergio Lopez <slp@redhat.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit 70995754416eb4491c31607fe380a83cfd25a087)
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 tools/virtiofsd/fuse_lowlevel.c | 581 +++++++++++++++++++++++++++++++---------
22c213
 1 file changed, 456 insertions(+), 125 deletions(-)
22c213
22c213
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
22c213
index 611e8b0..02e1d83 100644
22c213
--- a/tools/virtiofsd/fuse_lowlevel.c
22c213
+++ b/tools/virtiofsd/fuse_lowlevel.c
22c213
@@ -19,6 +19,7 @@
22c213
 #include <assert.h>
22c213
 #include <errno.h>
22c213
 #include <limits.h>
22c213
+#include <stdbool.h>
22c213
 #include <stddef.h>
22c213
 #include <stdio.h>
22c213
 #include <stdlib.h>
22c213
@@ -27,7 +28,6 @@
22c213
 #include <unistd.h>
22c213
 
22c213
 
22c213
-#define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
22c213
 #define OFFSET_MAX 0x7fffffffffffffffLL
22c213
 
22c213
 struct fuse_pollhandle {
22c213
@@ -706,9 +706,14 @@ int fuse_reply_lseek(fuse_req_t req, off_t off)
22c213
     return send_reply_ok(req, &arg, sizeof(arg));
22c213
 }
22c213
 
22c213
-static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_lookup(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    char *name = (char *)inarg;
22c213
+    const char *name = fuse_mbuf_iter_advance_str(iter);
22c213
+    if (!name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.lookup) {
22c213
         req->se->op.lookup(req, nodeid, name);
22c213
@@ -717,9 +722,16 @@ static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_forget(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_forget(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_forget_in *arg = (struct fuse_forget_in *)inarg;
22c213
+    struct fuse_forget_in *arg;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.forget) {
22c213
         req->se->op.forget(req, nodeid, arg->nlookup);
22c213
@@ -729,20 +741,48 @@ static void do_forget(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
 }
22c213
 
22c213
 static void do_batch_forget(fuse_req_t req, fuse_ino_t nodeid,
22c213
-                            const void *inarg)
22c213
+                            struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_batch_forget_in *arg = (void *)inarg;
22c213
-    struct fuse_forget_one *param = (void *)PARAM(arg);
22c213
-    unsigned int i;
22c213
+    struct fuse_batch_forget_in *arg;
22c213
+    struct fuse_forget_data *forgets;
22c213
+    size_t scount;
22c213
 
22c213
     (void)nodeid;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_none(req);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    /*
22c213
+     * Prevent integer overflow.  The compiler emits the following warning
22c213
+     * unless we use the scount local variable:
22c213
+     *
22c213
+     * error: comparison is always false due to limited range of data type
22c213
+     * [-Werror=type-limits]
22c213
+     *
22c213
+     * This may be true on 64-bit hosts but we need this check for 32-bit
22c213
+     * hosts.
22c213
+     */
22c213
+    scount = arg->count;
22c213
+    if (scount > SIZE_MAX / sizeof(forgets[0])) {
22c213
+        fuse_reply_none(req);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    forgets = fuse_mbuf_iter_advance(iter, arg->count * sizeof(forgets[0]));
22c213
+    if (!forgets) {
22c213
+        fuse_reply_none(req);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     if (req->se->op.forget_multi) {
22c213
-        req->se->op.forget_multi(req, arg->count,
22c213
-                                 (struct fuse_forget_data *)param);
22c213
+        req->se->op.forget_multi(req, arg->count, forgets);
22c213
     } else if (req->se->op.forget) {
22c213
+        unsigned int i;
22c213
+
22c213
         for (i = 0; i < arg->count; i++) {
22c213
-            struct fuse_forget_one *forget = &param[i];
22c213
             struct fuse_req *dummy_req;
22c213
 
22c213
             dummy_req = fuse_ll_alloc_req(req->se);
22c213
@@ -754,7 +794,7 @@ static void do_batch_forget(fuse_req_t req, fuse_ino_t nodeid,
22c213
             dummy_req->ctx = req->ctx;
22c213
             dummy_req->ch = NULL;
22c213
 
22c213
-            req->se->op.forget(dummy_req, forget->nodeid, forget->nlookup);
22c213
+            req->se->op.forget(dummy_req, forgets[i].ino, forgets[i].nlookup);
22c213
         }
22c213
         fuse_reply_none(req);
22c213
     } else {
22c213
@@ -762,12 +802,19 @@ static void do_batch_forget(fuse_req_t req, fuse_ino_t nodeid,
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_getattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_getattr(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
     struct fuse_file_info *fip = NULL;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
-    struct fuse_getattr_in *arg = (struct fuse_getattr_in *)inarg;
22c213
+    struct fuse_getattr_in *arg;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (arg->getattr_flags & FUSE_GETATTR_FH) {
22c213
         memset(&fi, 0, sizeof(fi));
22c213
@@ -782,14 +829,21 @@ static void do_getattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_setattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_setattr(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_setattr_in *arg = (struct fuse_setattr_in *)inarg;
22c213
-
22c213
     if (req->se->op.setattr) {
22c213
+        struct fuse_setattr_in *arg;
22c213
         struct fuse_file_info *fi = NULL;
22c213
         struct fuse_file_info fi_store;
22c213
         struct stat stbuf;
22c213
+
22c213
+        arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+        if (!arg) {
22c213
+            fuse_reply_err(req, EINVAL);
22c213
+            return;
22c213
+        }
22c213
+
22c213
         memset(&stbuf, 0, sizeof(stbuf));
22c213
         convert_attr(arg, &stbuf);
22c213
         if (arg->valid & FATTR_FH) {
22c213
@@ -810,9 +864,16 @@ static void do_setattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_access(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_access(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_access_in *arg = (struct fuse_access_in *)inarg;
22c213
+    struct fuse_access_in *arg;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.access) {
22c213
         req->se->op.access(req, nodeid, arg->mask);
22c213
@@ -821,9 +882,10 @@ static void do_access(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_readlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_readlink(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                        struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    (void)inarg;
22c213
+    (void)iter;
22c213
 
22c213
     if (req->se->op.readlink) {
22c213
         req->se->op.readlink(req, nodeid);
22c213
@@ -832,10 +894,18 @@ static void do_readlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_mknod(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_mknod(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_mknod_in *arg = (struct fuse_mknod_in *)inarg;
22c213
-    char *name = PARAM(arg);
22c213
+    struct fuse_mknod_in *arg;
22c213
+    const char *name;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    name = fuse_mbuf_iter_advance_str(iter);
22c213
+    if (!arg || !name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     req->ctx.umask = arg->umask;
22c213
 
22c213
@@ -846,22 +916,37 @@ static void do_mknod(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_mkdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_mkdir(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_mkdir_in *arg = (struct fuse_mkdir_in *)inarg;
22c213
+    struct fuse_mkdir_in *arg;
22c213
+    const char *name;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    name = fuse_mbuf_iter_advance_str(iter);
22c213
+    if (!arg || !name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     req->ctx.umask = arg->umask;
22c213
 
22c213
     if (req->se->op.mkdir) {
22c213
-        req->se->op.mkdir(req, nodeid, PARAM(arg), arg->mode);
22c213
+        req->se->op.mkdir(req, nodeid, name, arg->mode);
22c213
     } else {
22c213
         fuse_reply_err(req, ENOSYS);
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_unlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_unlink(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    char *name = (char *)inarg;
22c213
+    const char *name = fuse_mbuf_iter_advance_str(iter);
22c213
+
22c213
+    if (!name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.unlink) {
22c213
         req->se->op.unlink(req, nodeid, name);
22c213
@@ -870,9 +955,15 @@ static void do_unlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    char *name = (char *)inarg;
22c213
+    const char *name = fuse_mbuf_iter_advance_str(iter);
22c213
+
22c213
+    if (!name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.rmdir) {
22c213
         req->se->op.rmdir(req, nodeid, name);
22c213
@@ -881,10 +972,16 @@ static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_symlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_symlink(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    char *name = (char *)inarg;
22c213
-    char *linkname = ((char *)inarg) + strlen((char *)inarg) + 1;
22c213
+    const char *name = fuse_mbuf_iter_advance_str(iter);
22c213
+    const char *linkname = fuse_mbuf_iter_advance_str(iter);
22c213
+
22c213
+    if (!name || !linkname) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.symlink) {
22c213
         req->se->op.symlink(req, linkname, nodeid, name);
22c213
@@ -893,11 +990,20 @@ static void do_symlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_rename(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_rename(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_rename_in *arg = (struct fuse_rename_in *)inarg;
22c213
-    char *oldname = PARAM(arg);
22c213
-    char *newname = oldname + strlen(oldname) + 1;
22c213
+    struct fuse_rename_in *arg;
22c213
+    const char *oldname;
22c213
+    const char *newname;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    oldname = fuse_mbuf_iter_advance_str(iter);
22c213
+    newname = fuse_mbuf_iter_advance_str(iter);
22c213
+    if (!arg || !oldname || !newname) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.rename) {
22c213
         req->se->op.rename(req, nodeid, oldname, arg->newdir, newname, 0);
22c213
@@ -906,11 +1012,20 @@ static void do_rename(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_rename2(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_rename2(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_rename2_in *arg = (struct fuse_rename2_in *)inarg;
22c213
-    char *oldname = PARAM(arg);
22c213
-    char *newname = oldname + strlen(oldname) + 1;
22c213
+    struct fuse_rename2_in *arg;
22c213
+    const char *oldname;
22c213
+    const char *newname;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    oldname = fuse_mbuf_iter_advance_str(iter);
22c213
+    newname = fuse_mbuf_iter_advance_str(iter);
22c213
+    if (!arg || !oldname || !newname) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.rename) {
22c213
         req->se->op.rename(req, nodeid, oldname, arg->newdir, newname,
22c213
@@ -920,24 +1035,38 @@ static void do_rename2(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_link(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_link(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                    struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_link_in *arg = (struct fuse_link_in *)inarg;
22c213
+    struct fuse_link_in *arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    const char *name = fuse_mbuf_iter_advance_str(iter);
22c213
+
22c213
+    if (!arg || !name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.link) {
22c213
-        req->se->op.link(req, arg->oldnodeid, nodeid, PARAM(arg));
22c213
+        req->se->op.link(req, arg->oldnodeid, nodeid, name);
22c213
     } else {
22c213
         fuse_reply_err(req, ENOSYS);
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_create(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_create(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_create_in *arg = (struct fuse_create_in *)inarg;
22c213
-
22c213
     if (req->se->op.create) {
22c213
+        struct fuse_create_in *arg;
22c213
         struct fuse_file_info fi;
22c213
-        char *name = PARAM(arg);
22c213
+        const char *name;
22c213
+
22c213
+        arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+        name = fuse_mbuf_iter_advance_str(iter);
22c213
+        if (!arg || !name) {
22c213
+            fuse_reply_err(req, EINVAL);
22c213
+            return;
22c213
+        }
22c213
 
22c213
         memset(&fi, 0, sizeof(fi));
22c213
         fi.flags = arg->flags;
22c213
@@ -950,11 +1079,18 @@ static void do_create(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_open(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_open(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                    struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_open_in *arg = (struct fuse_open_in *)inarg;
22c213
+    struct fuse_open_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.flags = arg->flags;
22c213
 
22c213
@@ -965,13 +1101,15 @@ static void do_open(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_read(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_read(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                    struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_read_in *arg = (struct fuse_read_in *)inarg;
22c213
-
22c213
     if (req->se->op.read) {
22c213
+        struct fuse_read_in *arg;
22c213
         struct fuse_file_info fi;
22c213
 
22c213
+        arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+
22c213
         memset(&fi, 0, sizeof(fi));
22c213
         fi.fh = arg->fh;
22c213
         fi.lock_owner = arg->lock_owner;
22c213
@@ -982,11 +1120,24 @@ static void do_read(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_write(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_write_in *arg = (struct fuse_write_in *)inarg;
22c213
+    struct fuse_write_in *arg;
22c213
     struct fuse_file_info fi;
22c213
-    char *param;
22c213
+    const char *param;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    param = fuse_mbuf_iter_advance(iter, arg->size);
22c213
+    if (!param) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
@@ -994,7 +1145,6 @@ static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
 
22c213
     fi.lock_owner = arg->lock_owner;
22c213
     fi.flags = arg->flags;
22c213
-    param = PARAM(arg);
22c213
 
22c213
     if (req->se->op.write) {
22c213
         req->se->op.write(req, nodeid, param, arg->size, arg->offset, &fi);
22c213
@@ -1052,11 +1202,18 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid,
22c213
     se->op.write_buf(req, nodeid, pbufv, arg->offset, &fi);
22c213
 }
22c213
 
22c213
-static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_flush(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_flush_in *arg = (struct fuse_flush_in *)inarg;
22c213
+    struct fuse_flush_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
     fi.flush = 1;
22c213
@@ -1069,19 +1226,26 @@ static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_release(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_release(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_release_in *arg = (struct fuse_release_in *)inarg;
22c213
+    struct fuse_release_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.flags = arg->flags;
22c213
     fi.fh = arg->fh;
22c213
     fi.flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0;
22c213
     fi.lock_owner = arg->lock_owner;
22c213
+
22c213
     if (arg->release_flags & FUSE_RELEASE_FLOCK_UNLOCK) {
22c213
         fi.flock_release = 1;
22c213
-        fi.lock_owner = arg->lock_owner;
22c213
     }
22c213
 
22c213
     if (req->se->op.release) {
22c213
@@ -1091,11 +1255,19 @@ static void do_release(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_fsync(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_fsync_in *arg = (struct fuse_fsync_in *)inarg;
22c213
+    struct fuse_fsync_in *arg;
22c213
     struct fuse_file_info fi;
22c213
-    int datasync = arg->fsync_flags & 1;
22c213
+    int datasync;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+    datasync = arg->fsync_flags & 1;
22c213
 
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
@@ -1111,11 +1283,18 @@ static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_opendir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_opendir(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_open_in *arg = (struct fuse_open_in *)inarg;
22c213
+    struct fuse_open_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.flags = arg->flags;
22c213
 
22c213
@@ -1126,11 +1305,18 @@ static void do_opendir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_readdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_readdir(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_read_in *arg = (struct fuse_read_in *)inarg;
22c213
+    struct fuse_read_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
 
22c213
@@ -1141,11 +1327,18 @@ static void do_readdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_readdirplus(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_readdirplus(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                           struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_read_in *arg = (struct fuse_read_in *)inarg;
22c213
+    struct fuse_read_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
 
22c213
@@ -1156,11 +1349,18 @@ static void do_readdirplus(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                          struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_release_in *arg = (struct fuse_release_in *)inarg;
22c213
+    struct fuse_release_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.flags = arg->flags;
22c213
     fi.fh = arg->fh;
22c213
@@ -1172,11 +1372,19 @@ static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                        struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_fsync_in *arg = (struct fuse_fsync_in *)inarg;
22c213
+    struct fuse_fsync_in *arg;
22c213
     struct fuse_file_info fi;
22c213
-    int datasync = arg->fsync_flags & 1;
22c213
+    int datasync;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+    datasync = arg->fsync_flags & 1;
22c213
 
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
@@ -1188,10 +1396,11 @@ static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_statfs(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_statfs(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
     (void)nodeid;
22c213
-    (void)inarg;
22c213
+    (void)iter;
22c213
 
22c213
     if (req->se->op.statfs) {
22c213
         req->se->op.statfs(req, nodeid);
22c213
@@ -1204,11 +1413,25 @@ static void do_statfs(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                        struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_setxattr_in *arg = (struct fuse_setxattr_in *)inarg;
22c213
-    char *name = PARAM(arg);
22c213
-    char *value = name + strlen(name) + 1;
22c213
+    struct fuse_setxattr_in *arg;
22c213
+    const char *name;
22c213
+    const char *value;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    name = fuse_mbuf_iter_advance_str(iter);
22c213
+    if (!arg || !name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    value = fuse_mbuf_iter_advance(iter, arg->size);
22c213
+    if (!value) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.setxattr) {
22c213
         req->se->op.setxattr(req, nodeid, name, value, arg->size, arg->flags);
22c213
@@ -1217,20 +1440,36 @@ static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_getxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_getxattr(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                        struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *)inarg;
22c213
+    struct fuse_getxattr_in *arg;
22c213
+    const char *name;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    name = fuse_mbuf_iter_advance_str(iter);
22c213
+    if (!arg || !name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.getxattr) {
22c213
-        req->se->op.getxattr(req, nodeid, PARAM(arg), arg->size);
22c213
+        req->se->op.getxattr(req, nodeid, name, arg->size);
22c213
     } else {
22c213
         fuse_reply_err(req, ENOSYS);
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                         struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *)inarg;
22c213
+    struct fuse_getxattr_in *arg;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.listxattr) {
22c213
         req->se->op.listxattr(req, nodeid, arg->size);
22c213
@@ -1239,9 +1478,15 @@ static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_removexattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_removexattr(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                           struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    char *name = (char *)inarg;
22c213
+    const char *name = fuse_mbuf_iter_advance_str(iter);
22c213
+
22c213
+    if (!name) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.removexattr) {
22c213
         req->se->op.removexattr(req, nodeid, name);
22c213
@@ -1265,12 +1510,19 @@ static void convert_fuse_file_lock(struct fuse_file_lock *fl,
22c213
     flock->l_pid = fl->pid;
22c213
 }
22c213
 
22c213
-static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_getlk(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_lk_in *arg = (struct fuse_lk_in *)inarg;
22c213
+    struct fuse_lk_in *arg;
22c213
     struct fuse_file_info fi;
22c213
     struct flock flock;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
     fi.lock_owner = arg->owner;
22c213
@@ -1284,12 +1536,18 @@ static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
 }
22c213
 
22c213
 static void do_setlk_common(fuse_req_t req, fuse_ino_t nodeid,
22c213
-                            const void *inarg, int sleep)
22c213
+                            struct fuse_mbuf_iter *iter, int sleep)
22c213
 {
22c213
-    struct fuse_lk_in *arg = (struct fuse_lk_in *)inarg;
22c213
+    struct fuse_lk_in *arg;
22c213
     struct fuse_file_info fi;
22c213
     struct flock flock;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
     fi.lock_owner = arg->owner;
22c213
@@ -1327,14 +1585,16 @@ static void do_setlk_common(fuse_req_t req, fuse_ino_t nodeid,
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_setlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_setlk(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    do_setlk_common(req, nodeid, inarg, 0);
22c213
+    do_setlk_common(req, nodeid, iter, 0);
22c213
 }
22c213
 
22c213
-static void do_setlkw(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_setlkw(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                      struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    do_setlk_common(req, nodeid, inarg, 1);
22c213
+    do_setlk_common(req, nodeid, iter, 1);
22c213
 }
22c213
 
22c213
 static int find_interrupted(struct fuse_session *se, struct fuse_req *req)
22c213
@@ -1379,12 +1639,20 @@ static int find_interrupted(struct fuse_session *se, struct fuse_req *req)
22c213
     return 0;
22c213
 }
22c213
 
22c213
-static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                         struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_interrupt_in *arg = (struct fuse_interrupt_in *)inarg;
22c213
+    struct fuse_interrupt_in *arg;
22c213
     struct fuse_session *se = req->se;
22c213
 
22c213
     (void)nodeid;
22c213
+
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     if (se->debug) {
22c213
         fuse_log(FUSE_LOG_DEBUG, "INTERRUPT: %llu\n",
22c213
                  (unsigned long long)arg->unique);
22c213
@@ -1425,9 +1693,15 @@ static struct fuse_req *check_interrupt(struct fuse_session *se,
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_bmap(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_bmap(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                    struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_bmap_in *arg = (struct fuse_bmap_in *)inarg;
22c213
+    struct fuse_bmap_in *arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
 
22c213
     if (req->se->op.bmap) {
22c213
         req->se->op.bmap(req, nodeid, arg->blocksize, arg->block);
22c213
@@ -1436,18 +1710,34 @@ static void do_bmap(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_ioctl_in *arg = (struct fuse_ioctl_in *)inarg;
22c213
-    unsigned int flags = arg->flags;
22c213
-    void *in_buf = arg->in_size ? PARAM(arg) : NULL;
22c213
+    struct fuse_ioctl_in *arg;
22c213
+    unsigned int flags;
22c213
+    void *in_buf = NULL;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    flags = arg->flags;
22c213
     if (flags & FUSE_IOCTL_DIR && !(req->se->conn.want & FUSE_CAP_IOCTL_DIR)) {
22c213
         fuse_reply_err(req, ENOTTY);
22c213
         return;
22c213
     }
22c213
 
22c213
+    if (arg->in_size) {
22c213
+        in_buf = fuse_mbuf_iter_advance(iter, arg->in_size);
22c213
+        if (!in_buf) {
22c213
+            fuse_reply_err(req, EINVAL);
22c213
+            return;
22c213
+        }
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
 
22c213
@@ -1468,11 +1758,18 @@ void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
22c213
     free(ph);
22c213
 }
22c213
 
22c213
-static void do_poll(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_poll(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                    struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_poll_in *arg = (struct fuse_poll_in *)inarg;
22c213
+    struct fuse_poll_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
     fi.poll_events = arg->events;
22c213
@@ -1496,11 +1793,18 @@ static void do_poll(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_fallocate(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_fallocate(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                         struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_fallocate_in *arg = (struct fuse_fallocate_in *)inarg;
22c213
+    struct fuse_fallocate_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
 
22c213
@@ -1513,12 +1817,17 @@ static void do_fallocate(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
 }
22c213
 
22c213
 static void do_copy_file_range(fuse_req_t req, fuse_ino_t nodeid_in,
22c213
-                               const void *inarg)
22c213
+                               struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_copy_file_range_in *arg =
22c213
-        (struct fuse_copy_file_range_in *)inarg;
22c213
+    struct fuse_copy_file_range_in *arg;
22c213
     struct fuse_file_info fi_in, fi_out;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
     memset(&fi_in, 0, sizeof(fi_in));
22c213
     fi_in.fh = arg->fh_in;
22c213
 
22c213
@@ -1535,11 +1844,17 @@ static void do_copy_file_range(fuse_req_t req, fuse_ino_t nodeid_in,
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_lseek(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_lseek(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                     struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_lseek_in *arg = (struct fuse_lseek_in *)inarg;
22c213
+    struct fuse_lseek_in *arg;
22c213
     struct fuse_file_info fi;
22c213
 
22c213
+    arg = fuse_mbuf_iter_advance(iter, sizeof(*arg));
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
     memset(&fi, 0, sizeof(fi));
22c213
     fi.fh = arg->fh;
22c213
 
22c213
@@ -1550,15 +1865,33 @@ static void do_lseek(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     }
22c213
 }
22c213
 
22c213
-static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_init(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                    struct fuse_mbuf_iter *iter)
22c213
 {
22c213
-    struct fuse_init_in *arg = (struct fuse_init_in *)inarg;
22c213
+    size_t compat_size = offsetof(struct fuse_init_in, max_readahead);
22c213
+    struct fuse_init_in *arg;
22c213
     struct fuse_init_out outarg;
22c213
     struct fuse_session *se = req->se;
22c213
     size_t bufsize = se->bufsize;
22c213
     size_t outargsize = sizeof(outarg);
22c213
 
22c213
     (void)nodeid;
22c213
+
22c213
+    /* First consume the old fields... */
22c213
+    arg = fuse_mbuf_iter_advance(iter, compat_size);
22c213
+    if (!arg) {
22c213
+        fuse_reply_err(req, EINVAL);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    /* ...and now consume the new fields. */
22c213
+    if (arg->major == 7 && arg->minor >= 6) {
22c213
+        if (!fuse_mbuf_iter_advance(iter, sizeof(*arg) - compat_size)) {
22c213
+            fuse_reply_err(req, EINVAL);
22c213
+            return;
22c213
+        }
22c213
+    }
22c213
+
22c213
     if (se->debug) {
22c213
         fuse_log(FUSE_LOG_DEBUG, "INIT: %u.%u\n", arg->major, arg->minor);
22c213
         if (arg->major == 7 && arg->minor >= 6) {
22c213
@@ -1791,12 +2124,13 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
     send_reply_ok(req, &outarg, outargsize);
22c213
 }
22c213
 
22c213
-static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
+static void do_destroy(fuse_req_t req, fuse_ino_t nodeid,
22c213
+                       struct fuse_mbuf_iter *iter)
22c213
 {
22c213
     struct fuse_session *se = req->se;
22c213
 
22c213
     (void)nodeid;
22c213
-    (void)inarg;
22c213
+    (void)iter;
22c213
 
22c213
     se->got_destroy = 1;
22c213
     if (se->op.destroy) {
22c213
@@ -1976,7 +2310,7 @@ int fuse_req_interrupted(fuse_req_t req)
22c213
 }
22c213
 
22c213
 static struct {
22c213
-    void (*func)(fuse_req_t, fuse_ino_t, const void *);
22c213
+    void (*func)(fuse_req_t, fuse_ino_t, struct fuse_mbuf_iter *);
22c213
     const char *name;
22c213
 } fuse_ll_ops[] = {
22c213
     [FUSE_LOOKUP] = { do_lookup, "LOOKUP" },
22c213
@@ -2060,7 +2394,6 @@ void fuse_session_process_buf_int(struct fuse_session *se,
22c213
     const struct fuse_buf *buf = bufv->buf;
22c213
     struct fuse_mbuf_iter iter = FUSE_MBUF_ITER_INIT(buf);
22c213
     struct fuse_in_header *in;
22c213
-    const void *inarg;
22c213
     struct fuse_req *req;
22c213
     int err;
22c213
 
22c213
@@ -2138,13 +2471,11 @@ void fuse_session_process_buf_int(struct fuse_session *se,
22c213
         }
22c213
     }
22c213
 
22c213
-    inarg = (void *)&in[1];
22c213
     if (in->opcode == FUSE_WRITE && se->op.write_buf) {
22c213
         do_write_buf(req, in->nodeid, &iter, bufv);
22c213
     } else {
22c213
-        fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
22c213
+        fuse_ll_ops[in->opcode].func(req, in->nodeid, &iter);
22c213
     }
22c213
-
22c213
     return;
22c213
 
22c213
 reply_err:
22c213
-- 
22c213
1.8.3.1
22c213