From patchwork Sun Jul 15 19:52:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 944088 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41THNY2HCbz9rxs for ; Mon, 16 Jul 2018 05:56:13 +1000 (AEST) Received: from localhost ([::1]:47358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen7r-00050v-2n for incoming@patchwork.ozlabs.org; Sun, 15 Jul 2018 15:56:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen52-00036k-41 for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fen4y-00066F-VU for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:16 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:36381) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fen4y-00065X-KW for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:12 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MVd8x-1fYWMm3GYR-00Z2FK; Sun, 15 Jul 2018 21:53:00 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Sun, 15 Jul 2018 21:52:39 +0200 Message-Id: <20180715195242.6645-2-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180715195242.6645-1-laurent@vivier.eu> References: <20180715195242.6645-1-laurent@vivier.eu> X-Provags-ID: V03:K1:SX81x/Z6MKcKUbipraNNeG8LnOQpbfUcj2KczBxUCDIEBX0Gryc ZsAM+T8nnECUypgWbjTmlkO0w56PSFZ5WoWtRUmhHhDIKkaKOx0Z/UwEu0URXXVArSoULsU cPqCnWoQ7HUB1/kjQ1+6vvhkKXO9T/a+xDnIwjAs8CQ5u8dRJIo1WNlAembddNJ7XT5p2ml yPcRR2PX+Xm7yVNd91LGA== X-UI-Out-Filterresults: notjunk:1; V01:K0:bEm/s5qkgr8=:nSZ8gWuFFKYVz37AiwHYzf VGeEUTf5UsGEXrSxdsT/lOR7ebIr9MoLNaV6xzaG0H7RNY6poqIn4OIT5VoP6s/V3JLpq6ObH iafddU9N4w56eF/fUSGNnH7SUSO2ckR4JR7g3KLa86fNmQOmHyLM1AqvZWE3drUzzxVu3r6Ea IUEj3jXWQj3OoJViHgugwFwa/KT2BBQrVoOwWYCRKfsxe2U8uXtXhC7GrHJo34ANUjg2sNdTJ y0HH0RucEq4vnq2IlbBGn5YM01K7Wr9+6+PH5mR/h6sY5gCXFfQEUWwhvlFfNYt1qMwdH4cDo 2kPNeens3IOdA/nLFilruCwu98A15Z8q4T39jxurwVYLbLrrh7j0CobXhVCkiD5mw0980CxKG VQNdu6hfl4nQta+I1OtLiC7LioE0bhQcSLGs6wYhOP4c/aZwhwUXvZrGS8xM+Zt9uHelFJVtx g4l1lGM22dDMySSO5heB9q97+aYdkJ/bwRBc3LGAEPPFXuCqdy8dNRvfqVgXSEcSQOhGvBBci dihZScrc+gYeE6wn23LqgubOgoUNxK2SIOCRxOKDmGf8Ha7QZq5ZEyr4QUlV4O2O8LyvLcSxD uxVKiZgSxqVQAfqQxwLm9EuyHd5Zso9XbIeWE+bjmQXFP81wYWiW+mVwTyG3d7NI0N+IhgK3S LVKWnpXomApHDwOl+Socjsg+wA4+/i+W28166zSez5jE44CqEuMKGpYtPrX2bLa2nMoU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.24 Subject: [Qemu-devel] [PULL 1/4] linux-user: ppc64: use the correct values for F_*LK64s X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Shivaprasad G Bhat , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Shivaprasad G Bhat Qemu includes the glibc headers for the host defines and target headers are part of the qemu source themselves. The glibc has the F_GETLK64, F_SETLK64 and F_SETLKW64 defined to 12, 13 and 14 for all archs in sysdeps/unix/sysv/linux/bits/fcntl-linux.h. The linux kernel generic definition for F_*LK is 5, 6 & 7 and F_*LK64* is 12,13, and 14 as seen in include/uapi/asm-generic/fcntl.h. On 64bit machine, by default the kernel assumes all F_*LK to 64bit calls and doesnt support use of F_*LK64* as can be seen in include/linux/fcntl.h in linux source. On x86_64 host, the values for F_*LK64* are set to 5, 6 and 7 explicitly in /usr/include/x86_64-linux-gnu/bits/fcntl.h by the glibc. Whereas, a PPC64 host doesn't have such a definition in /usr/include/powerpc64le-linux-gnu/bits/fcntl.h by the glibc. So, the sources on PPC64 host sees the default value of F_*LK64* as 12, 13 & 14(fcntl-linux.h). Since the 64bit kernel doesnt support 12, 13 & 14; the glibc fcntl syscall implementation(__libc_fcntl*(), __fcntl64_nocancel) does the F_*LK64* value convertion back to F_*LK* values on PPC64 as seen in sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h with FCNTL_ADJUST_CMD() macro. Whereas on x86_64 host the values for F_*LK64* are set to 5, 6 and 7 and no adjustments are needed. Since qemu doesnt use the glibc fcntl, but makes the safe_syscall* on its own, the PPC64 qemu is calling the syscall with 12, 13, and 14(without adjustment) and they all fail. The fcntl calls to F_GETLK/F_SETLK|W all fail by all pplications run on PPC64 host user emulation. The fix here could be to see why on PPC64 the glibc is still keeping F_*LK64* different from F_*LK and why adjusting them to 5, 6 and 7 before the syscall for PPC only. See if we can make the /usr/include/powerpc64le-linux-gnu/bits/fcntl.h to have the values 5, 6 & 7 just like x86_64 and remove the adjustment code in glibc. That way, qemu sources see the kernel supported values in glibc headers. OR On PPC64 host, qemu sources see both F_*LK & F_*LK64* as same and set to 12, 13 and 14 because __USE_FILE_OFFSET64 is defined in qemu sources(also refer sysdeps/unix/sysv/linux/bits/fcntl-linux.h). Do the value adjustment just like it is done by glibc source by using F_GETLK value of 5. That way, we make the syscalls with the actual supported values in Qemu. The patch is taking this approach. Signed-off-by: Shivaprasad G Bhat Reviewed-by: David Gibson Reviewed-by: Laurent Vivier Message-Id: <153148521235.87746.14142430397318741182.stgit@lep8c.aus.stglabs.ibm.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 126 +++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 46 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e4b1b7d7da..b8b7bced9f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6545,63 +6545,97 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, /* warning : doesn't handle linux specific flags... */ static int target_to_host_fcntl_cmd(int cmd) { + int ret; + switch(cmd) { - case TARGET_F_DUPFD: - case TARGET_F_GETFD: - case TARGET_F_SETFD: - case TARGET_F_GETFL: - case TARGET_F_SETFL: - return cmd; - case TARGET_F_GETLK: - return F_GETLK64; - case TARGET_F_SETLK: - return F_SETLK64; - case TARGET_F_SETLKW: - return F_SETLKW64; - case TARGET_F_GETOWN: - return F_GETOWN; - case TARGET_F_SETOWN: - return F_SETOWN; - case TARGET_F_GETSIG: - return F_GETSIG; - case TARGET_F_SETSIG: - return F_SETSIG; + case TARGET_F_DUPFD: + case TARGET_F_GETFD: + case TARGET_F_SETFD: + case TARGET_F_GETFL: + case TARGET_F_SETFL: + ret = cmd; + break; + case TARGET_F_GETLK: + ret = F_GETLK64; + break; + case TARGET_F_SETLK: + ret = F_SETLK64; + break; + case TARGET_F_SETLKW: + ret = F_SETLKW64; + break; + case TARGET_F_GETOWN: + ret = F_GETOWN; + break; + case TARGET_F_SETOWN: + ret = F_SETOWN; + break; + case TARGET_F_GETSIG: + ret = F_GETSIG; + break; + case TARGET_F_SETSIG: + ret = F_SETSIG; + break; #if TARGET_ABI_BITS == 32 - case TARGET_F_GETLK64: - return F_GETLK64; - case TARGET_F_SETLK64: - return F_SETLK64; - case TARGET_F_SETLKW64: - return F_SETLKW64; -#endif - case TARGET_F_SETLEASE: - return F_SETLEASE; - case TARGET_F_GETLEASE: - return F_GETLEASE; + case TARGET_F_GETLK64: + ret = F_GETLK64; + break; + case TARGET_F_SETLK64: + ret = F_SETLK64; + break; + case TARGET_F_SETLKW64: + ret = F_SETLKW64; + break; +#endif + case TARGET_F_SETLEASE: + ret = F_SETLEASE; + break; + case TARGET_F_GETLEASE: + ret = F_GETLEASE; + break; #ifdef F_DUPFD_CLOEXEC - case TARGET_F_DUPFD_CLOEXEC: - return F_DUPFD_CLOEXEC; + case TARGET_F_DUPFD_CLOEXEC: + ret = F_DUPFD_CLOEXEC; + break; #endif - case TARGET_F_NOTIFY: - return F_NOTIFY; + case TARGET_F_NOTIFY: + ret = F_NOTIFY; + break; #ifdef F_GETOWN_EX - case TARGET_F_GETOWN_EX: - return F_GETOWN_EX; + case TARGET_F_GETOWN_EX: + ret = F_GETOWN_EX; + break; #endif #ifdef F_SETOWN_EX - case TARGET_F_SETOWN_EX: - return F_SETOWN_EX; + case TARGET_F_SETOWN_EX: + ret = F_SETOWN_EX; + break; #endif #ifdef F_SETPIPE_SZ - case TARGET_F_SETPIPE_SZ: - return F_SETPIPE_SZ; - case TARGET_F_GETPIPE_SZ: - return F_GETPIPE_SZ; + case TARGET_F_SETPIPE_SZ: + ret = F_SETPIPE_SZ; + break; + case TARGET_F_GETPIPE_SZ: + ret = F_GETPIPE_SZ; + break; #endif - default: - return -TARGET_EINVAL; + default: + ret = -TARGET_EINVAL; + break; } - return -TARGET_EINVAL; + +#if defined(__powerpc64__) + /* On PPC64, glibc headers has the F_*LK* defined to 12, 13 and 14 and + * is not supported by kernel. The glibc fcntl call actually adjusts + * them to 5, 6 and 7 before making the syscall(). Since we make the + * syscall directly, adjust to what is supported by the kernel. + */ + if (ret >= F_GETLK64 && ret <= F_SETLKW64) { + ret -= F_GETLK64 - 5; + } +#endif + + return ret; } #define FLOCK_TRANSTBL \ From patchwork Sun Jul 15 19:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 944089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41THQB33Dmz9rxs for ; Mon, 16 Jul 2018 05:57:38 +1000 (AEST) Received: from localhost ([::1]:47362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen9E-0005bR-44 for incoming@patchwork.ozlabs.org; Sun, 15 Jul 2018 15:57:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen51-00036h-Q7 for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fen4x-000650-32 for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:15 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:59213) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fen4w-00062n-O7 for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:10 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.183]) with ESMTPSA (Nemesis) id 0M731J-1g1Ymf3JVV-00wmPE; Sun, 15 Jul 2018 21:53:01 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Sun, 15 Jul 2018 21:52:41 +0200 Message-Id: <20180715195242.6645-4-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180715195242.6645-1-laurent@vivier.eu> References: <20180715195242.6645-1-laurent@vivier.eu> X-Provags-ID: V03:K1:OYiNsALAZo76ku2sF18Wp63CqbZgf16v9MY4H6fzlcxkjQ01rp+ 12v+CNPjfNJ0itXfW36uCeGVX6GltRppd2F+zcKrw4dlHdcNX4EjBgNEqLZ+dpk5FJglGa6 fc0HvzQjtXpZq3+Ib+S1ibx9q+usGFbx3whgPzBLcL4dkbrd8sv8Gj2o8Les4D92FB4oziw WtsXh/KV2IpdSRw7meb9w== X-UI-Out-Filterresults: notjunk:1; V01:K0:kz4Cb0ZAJPE=:IBPd7JNPVfmudnAWcYn1zT da5ORIUpjW2xKm7jngTntPP6JNQShvxh403hJOrlFJ7OUA3IaC4+iTX0psi7SrVpI7ntrjBAj dp57nXaNRsBMZhBfQyc/lYRG3BX2sr/o1uwYysr9Dy0uzvKngiUgfnjf9ltJLladNUQrqEZNm l2ovrZQ1TJjfy4WfbpgBl5X4l+FjyUIFaljT9g2kUoOFqcOUbtWKDVjFDeRhz+syVbZ0VG97G J4Kpke91evxNWqDeT0MYlIrjgUw5IgqbGvZeiSUMXbyasaw1MuK7YFHqfUTUSwKAo41BId+5i hc7uP8lM6spQxkehgmCuCx92U4gvsHQYBVX8YO9ALTgMkPjLvXq1ArVh/c7FBQ/OlfhnKQcrJ Far62+M0Sepun//2Dlc8aXwNTFET0RvE7opsRUmOvj2a4q6Oq/oXzuoMCR6uSLs8+GvXRl5n+ t0EwS8kxWZ/LgCkpufQE40m/6Uif/5hw4rKc7IYqDW2Mq40jgEodLRg7VZOxOigWXmOqqYFD0 IkXkxj2AItaiP3+fJK5HnVtYcJyijtZv2vjWEBYsNQ+ln1mNvL+U/YLHT9hV7KRyEXY1pXyDS DnOi/iZ2VxN/j0IXQ0Y9q6dj9ojQgh6dnz5LN7VM+igKqUZZXE/fTNSDLPkB96zVIucx70Nix 4HRD37ejyvVziBbf4GuWPPcSvdLu+6o5X9ZSQHS+0Cx5dMt+AiUOFAc0n3OvDDXdSxfM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PULL 3/4] linux-user: fix mmap_find_vma_reserved() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The value given by mmap_find_vma_reserved() is used with mmap(), so it is needed to be aligned with the host page size. Since commit 18e80c55bb, reserved_va is only aligned to TARGET_PAGE_SIZE, and it works well if this size is greater or equal to the host page size. But ppc64 hosts have 64kB page size and when we start a 4kiB page size guest (like i386), it fails when it tries to mmap the stack: mmap stack: Invalid argument Fixes: 18e80c55bb (linux-user: Tidy and enforce reserved_va initialization) Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Message-Id: <20180714193553.30846-1-laurent@vivier.eu> --- linux-user/main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 52b5a618fe..ea00dd9057 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -78,14 +78,7 @@ int have_guest_base; # endif #endif -/* That said, reserving *too* much vm space via mmap can run into problems - with rlimits, oom due to page table creation, etc. We will still try it, - if directed by the command-line option, but not by default. */ -#if HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32 -unsigned long reserved_va = MAX_RESERVED_VA; -#else unsigned long reserved_va; -#endif static void usage(int exitcode); @@ -672,6 +665,18 @@ int main(int argc, char **argv, char **envp) /* init tcg before creating CPUs and to get qemu_host_page_size */ tcg_exec_init(0); + /* Reserving *too* much vm space via mmap can run into problems + with rlimits, oom due to page table creation, etc. We will still try it, + if directed by the command-line option, but not by default. */ + if (HOST_LONG_BITS == 64 && + TARGET_VIRT_ADDR_SPACE_BITS <= 32 && + reserved_va == 0) { + /* reserved_va must be aligned with the host page size + * as it is used with mmap() + */ + reserved_va = MAX_RESERVED_VA & qemu_host_page_mask; + } + cpu = cpu_create(cpu_type); env = cpu->env_ptr; cpu_reset(cpu); From patchwork Sun Jul 15 19:52:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 944087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41THL11fwrz9rxs for ; Mon, 16 Jul 2018 05:54:01 +1000 (AEST) Received: from localhost ([::1]:47347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen5i-0003BZ-TM for incoming@patchwork.ozlabs.org; Sun, 15 Jul 2018 15:53:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fen51-00036i-Ra for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fen4x-00065L-JO for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:15 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:36661) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fen4x-00064A-9P for qemu-devel@nongnu.org; Sun, 15 Jul 2018 15:53:11 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MINbz-1fcrvm1FOB-0049SA; Sun, 15 Jul 2018 21:53:01 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Sun, 15 Jul 2018 21:52:42 +0200 Message-Id: <20180715195242.6645-5-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180715195242.6645-1-laurent@vivier.eu> References: <20180715195242.6645-1-laurent@vivier.eu> X-Provags-ID: V03:K1:mRtQ4FSKbGuzETnSFwJMabO6mO46G2Oe78+V1BjR8iD0uC/TEoJ nbVviH8yMvjXUA7u6UzO9+627Q73a3u4eQIaCDI4+Gn3UZYWLsIwNX0IdqOIKQ2ZFYukk4q SRYl3BaMM0VbJcmfJ3RZU8UQlzanljL/Ef9LST84tAxjpj1vRUvskGjG1Quyb09mHofrZvZ i+Cu06l/nwjLDDx8r4j8g== X-UI-Out-Filterresults: notjunk:1; V01:K0:olN/kE4Z0C0=:brtERRWp8WpGG9helwoutV B2YdKFehIu+6pzYQJoWE6y6923/o6m7aY0VxCs/qkZmIUSwDzzedlEeRUbCx85n3766/WBkCH v/UEFLabuVxYuRA9e1ryWY4nqj92Wliutiwrtp64zbDqaxkC0t9DPu+GiH+H/Bi2JqnPDEzH3 vTGc1Y0b/iit48PD+eYUSR392jhmHQWXJ60NbHBGUH7nWccJcSjnF+YnRctDZ266HGIlnCsQX 8SVKavUq0aoXXTB/u5h6QR2s+IG9pQB0dtztn7ea1z4f20+2LDSqyE7sSTKKTsCVXHA2w3rlS MBRm0SFykMgFJIJo5CBkp+fUNna77KNjrS2X4qNLF7BIr7NEeQRbMcq81kyy2K+g4HCc1PmKl QGLhCK1PbNH9mTJMXbgBd5yS7nakxA0neJiTXLtnkrto6RAgSF5DymsyTKFlrxW6bARFRoSkS aAHOfR/opQ22jgP0ac+rfSPzL+4/QwDE/AyDYKsXhVlVRG4/HIb/i4yap1dWOd97fSt2r1M02 XHnCY8wiCdjKfyrPBDvS3C4oiXB4sXPmdXIRk6boWD8unkXlwSQiJ6X4qsNWz0Vz5C33E2qc0 rN/kzL9uRBj9aYKhyN+d7z5Iq7f8s4TQjOLkYtThA3j2xQUA6FbWX+y/QvUfi9dISfd59M8Bq bigZAsYGbMC23IEhaYTy3Hykwifr/HlsxIdPWbTgWKbRHv77Ru0A9OqdSuE2FAt6LEdM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PULL 4/4] Zero out the host's `msg_control` buffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , Jonas Schievink Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jonas Schievink If this is not done, qemu would drop any control message after the first one. This is because glibc's `CMSG_NXTHDR` macro accesses the uninitialized cmsghdr's length field in order to find out if the message fits into the `msg_control` buffer, wrongly assuming that it doesn't because the length field contains garbage. Accessing the length field is fine for completed messages we receive from the kernel, but is - as far as I know - not needed since the kernel won't return such an invalid cmsghdr in the first place. This is tracked as this glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13500 It's probably also a good idea to bail with an error if `CMSG_NXTHDR` returns NULL but `TARGET_CMSG_NXTHDR` doesn't (ie. we still expect cmsgs). Signed-off-by: Jonas Schievink Reviewed-by: Laurent Vivier Message-Id: <20180711221244.31869-1-jonasschievink@gmail.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index aa4f3eb1c8..3df3bdffb2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3843,6 +3843,8 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, } msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); msg.msg_control = alloca(msg.msg_controllen); + memset(msg.msg_control, 0, msg.msg_controllen); + msg.msg_flags = tswap32(msgp->msg_flags); count = tswapal(msgp->msg_iovlen);