]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: only copy to userspace on success in listmount()
authorChristian Brauner <brauner@kernel.org>
Thu, 4 Jul 2024 15:00:19 +0000 (17:00 +0200)
committerChristian Brauner <brauner@kernel.org>
Thu, 4 Jul 2024 15:00:19 +0000 (17:00 +0200)
Avoid copying when we failed to, or didn't have any mounts to list.

Fixes: cb54ef4f050e ("fs: don't copy to userspace under namespace semaphore") # mainline only
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/namespace.c

index c53a0ee748c6faea48754b9198ac95ee2ebf0e0e..f44e5448c8a0d696907cc7c943685852e3a0970f 100644 (file)
@@ -5401,6 +5401,8 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
        scoped_guard(rwsem_read, &namespace_sem)
                ret = do_listmount(ns, kreq.mnt_id, kreq.param, kmnt_ids,
                                   nr_mnt_ids, (flags & LISTMOUNT_REVERSE));
+       if (ret <= 0)
+               return ret;
 
        if (copy_to_user(mnt_ids, kmnt_ids, ret * sizeof(*mnt_ids)))
                return -EFAULT;