]> git.proxmox.com Git - mirror_qemu.git/commitdiff
linux-user: NETLINK_LIST_MEMBERSHIPS: Allow bad ptr if its length is 0
authorFrédéric Fortier <frf@ghgsat.com>
Sun, 28 Mar 2021 18:01:35 +0000 (14:01 -0400)
committerLaurent Vivier <laurent@vivier.eu>
Mon, 29 Mar 2021 19:56:18 +0000 (21:56 +0200)
getsockopt(fd, SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, *optval, *optlen)
syscall allows optval to be NULL/invalid if optlen points to a size of
zero. This allows userspace to query the length of the array they should
use to get the full membership list before allocating memory for said
list, then re-calling getsockopt with proper optval/optlen arguments.

Notable users of this pattern include systemd-networkd, which in the
(albeit old) version 237 tested, cannot start without this fix.

Signed-off-by: Frédéric Fortier <frf@ghgsat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20210328180135.88449-1-frf@ghgsat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
linux-user/syscall.c

index 294779c86f4de9ffa04dbff9038e018471014b3f..95d79ddc437a6741586071af532fcdbdc64a71d6 100644 (file)
@@ -3025,7 +3025,7 @@ get_timeout:
                 return -TARGET_EINVAL;
             }
             results = lock_user(VERIFY_WRITE, optval_addr, len, 1);
-            if (!results) {
+            if (!results && len > 0) {
                 return -TARGET_EFAULT;
             }
             lv = len;