From patchwork Wed Aug 3 14:56:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 12935595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02F25C19F28 for ; Wed, 3 Aug 2022 14:57:47 +0000 (UTC) Received: from localhost ([::1]:55546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJFog-0004RZ-2z for qemu-devel@archiver.kernel.org; Wed, 03 Aug 2022 10:57:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnJ-0001iz-MP for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:21 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:53027) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnH-0005qt-R7 for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:21 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N1feo-1nHPlv32nQ-011waR; Wed, 03 Aug 2022 16:56:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier , Peter Maydell , Richard Henderson Subject: [PULL 1/3] linux-user/flatload.c: Fix setting of image_info::end_code Date: Wed, 3 Aug 2022 16:56:11 +0200 Message-Id: <20220803145613.428167-2-laurent@vivier.eu> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220803145613.428167-1-laurent@vivier.eu> References: <20220803145613.428167-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Lr7n808hpcUaD00oh3QJaa0FHLrEXBFu0/qYupJX/lfoENFSvsG FW1lGgVsNtKs94qQcsef596rHW0tldUQU30gMTpS9qxtmyEaLrIiAsAkk1sR5XKLGMePLP1 MzWq+Svd23P7Dn61JthcPMxSf0RK35MbNomZJQ0bKYtHVY1fxNUphilHAhjwVqEDS7licPu qFq997PMeuQbnrqZHCzfg== X-UI-Out-Filterresults: notjunk:1;V03:K0:99P32HVzIpU=:dTTA2QnvRzKMiJap/8bxX2 YzUxrO93D2S6b/r61jSh5qj/AhNkyEQpbmxPGQMe2TwrKegPFwIDcqx72JwA/fvyEEvv3LK3j LViSjZ2IcJd5071rbO+vVzEohscEUm+5sWWmX1Iry/t5LtlWokj4X0K0a6cX53uE5I3WMttPX MkmfcbR58Sw1m5LRtlKWhC+UOtFNRo9cQr32j/eB//zUBULnqExCuBfa/1KvEur7xq6IgkgdN r8q2gx7ZKh3ALBIZDGqzhjD1FIySxgregcGrV7NXi/D9q/9lWdrHuK0clPf2S5MYPEXk2X2Wx DnKYQMKZfi8/Y602DzGzdYA2gMsgRP3kyegM1WsOdKYPmyaBsYi222rvvVZDmbblgh8Y8ATtk GoCqxgMaxPN06STgAAs1TeQ8Nw3B0lgxooPEP+07fD9E4H1wvxaqebbHTjJiR8g6xfL8Nnt95 rfAT4UjG7sPDhkhmFYb+gQmhJu8/0HtGPATOC1XIY5QRwG+efpN/vhOO5r4UNt+kyB7YmLMok V6xT4T6GosY5RY5WsF+CXUzvxiO8fhPQ0gjD9EXCRKqy9KpeBogrDXnXldtk986iKdBj/gCmw yw+e7kwZXORC0zMXtJ+trup0Fm9PQYvn1Y1daEB5zvNWoydBUUTbRE6M6WrtnXWndrHIiQ6sw CiG3Jpt2coqP6J7gkUviYhALJPXCfBmt9Fj3PB0irX6qjok4WpA61ZFfKJgD/w5eiZ0BmqE9B N60ntL5lsB3GYyUdvz55wSgmvgmKZs/aJRHQ+Q== Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell The flatload loader sets the end_code field in the image_info struct incorrectly, due to a typo. This is a very long-standing bug (dating all the way back to when the bFLT loader was added in 2006), but has gone unnoticed because (a) most people don't use bFLT binaries (b) we don't actually do anything with the end_code field, except print it in debugging traces and pass it to TCG plugins Fix the typo. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1119 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20220728151406.2262862-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/flatload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/flatload.c b/linux-user/flatload.c index e4c2f89a2267..e99570ca182b 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -808,7 +808,7 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) /* Stash our initial stack pointer into the mm structure */ info->start_code = libinfo[0].start_code; - info->end_code = libinfo[0].start_code = libinfo[0].text_len; + info->end_code = libinfo[0].start_code + libinfo[0].text_len; info->start_data = libinfo[0].start_data; info->end_data = libinfo[0].end_data; info->start_brk = libinfo[0].start_brk; From patchwork Wed Aug 3 14:56:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 12935596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 51A24C19F28 for ; Wed, 3 Aug 2022 14:58:03 +0000 (UTC) Received: from localhost ([::1]:56422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJFow-00052B-Cz for qemu-devel@archiver.kernel.org; Wed, 03 Aug 2022 10:58:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnK-0001mI-Kp for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:22 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:55943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnI-0005rG-4Q for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:22 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MqJuP-1nfIXr0yJf-00nRiC; Wed, 03 Aug 2022 16:56:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier , Ilya Leoshkevich Subject: [PULL 2/3] linux-user: Do not treat madvise()'s advice as a bitmask Date: Wed, 3 Aug 2022 16:56:12 +0200 Message-Id: <20220803145613.428167-3-laurent@vivier.eu> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220803145613.428167-1-laurent@vivier.eu> References: <20220803145613.428167-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:VAMSWNedp86XWGTl7VQ8rF3Lak6ecAkA2lUMsKaCDVzlqnLwnBB +8L/hUzpQTFf8iP4/eCTCOxgGJg+gtcOemME5pvoJMWymmJhDnF09hQ+qbyoUT4azE4j2ZW vUAbDb2FjLwxISQfoa9CpLe+BzR8CbLG32sN+eVQEmc5Y0nXgW1Jx/cBUkV1to5l79wgS2D 7UgK9bmQeotV4cLXbDpQg== X-UI-Out-Filterresults: notjunk:1;V03:K0:o82l1oBSZzo=:PCtL2rj7fNud0oT8PfbDPP aP/Lyge1Pc3nWcWcics0OgAedC1jDrJaT3IQO1m/SkfUVuS9MVh+p6K7DHQdMeUPMIGSohXPy NiQjHMCVrsFuGXPU6YKkBcQADV6HnRlrGAOjccFwCJYkm76pjGCm6LiHXtLQ9UWwrftg0JJEi THmP/9GK9tTcokvcjORVRGztEbsAoXmb4rhYZw82j/TeVFXvBdDWLNR9UXEmEIYOCC4rh1Ljw Qw/J5ooBE9r6IYxyL2kzAhfRw8POGHVzerp9HMfpkCkNhhIdSauleAJWXnCghvgvfOCMhWXAR yCQUGvIc1jPGOY99P87XC1TBnVKH5H1zGiTFZgxPSkONGYq9EJUU9kNWpFrjIknzCRjTTZCes le/1ZMlUaYf7XA4viyM6w5ERGkO71Ho06yZVTzJU5nrLolIIbkWePzmhCJo6Py09om7YIwRSC AVA9nHf6hxL5y+hJAzdCisxNHLg+YjGO/WcaOV2nYKZHHlvMWNOSbaFASlca7bhDUANxUEXFQ Wc82JZvnlldTnBkr1o85BDsuWv94QUs+3nbt6k3kDIgQt15g+WNCgkjosCpIMh0ZGnHNwmSQW RAFjnxOURnz7WKREuvglspKCq99fgnMJuslpzDbtTn6zxkok8C3qW9EWqR2w5/FfSkpv5u8bO o5Bo5cqAhoVgMFOWFvlUgTmSoR9MjYlFN+ojo/PlcHDb11SS6L6e1MSWNHaE43HF22TTtIE6t ihN/jbJAvdVwzP1aFcBYfip7zg8s6apf5mhCRw== Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Ilya Leoshkevich Advice is enum, not flags. Doing (advice & MADV_DONTNEED) also matches e.g. MADV_MERGEABLE. Signed-off-by: Ilya Leoshkevich Reviewed-by: Laurent Vivier Message-Id: <20220725134100.128035-1-iii@linux.ibm.com> Fixes: 892a4f6a750a ("linux-user: Add partial support for MADV_DONTNEED") Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 4e7a6be6ee19..edceaca4a8e1 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -891,7 +891,7 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) * anonymous mappings. In this case passthrough is safe, so do it. */ mmap_lock(); - if ((advice & MADV_DONTNEED) && + if (advice == MADV_DONTNEED && can_passthrough_madv_dontneed(start, end)) { ret = get_errno(madvise(g2h_untagged(start), len, MADV_DONTNEED)); } From patchwork Wed Aug 3 14:56:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 12935599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0386C19F28 for ; Wed, 3 Aug 2022 15:01:01 +0000 (UTC) Received: from localhost ([::1]:36490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJFro-0002A2-Rn for qemu-devel@archiver.kernel.org; Wed, 03 Aug 2022 11:01:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnK-0001n0-RR for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:22 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:37489) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnI-0005r9-Lx for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:22 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MFK8N-1oCyPB33gP-00Flqs; Wed, 03 Aug 2022 16:56:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier , =?utf-8?q?Rainer_M=C3=BCller?= , Richard Henderson Subject: [PULL 3/3] linux-user: Use memfd for open syscall emulation Date: Wed, 3 Aug 2022 16:56:13 +0200 Message-Id: <20220803145613.428167-4-laurent@vivier.eu> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220803145613.428167-1-laurent@vivier.eu> References: <20220803145613.428167-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:1XaqOx/Ra5846rlYKRVPZ3XCIYSDhdEz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helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Rainer Müller For certain paths in /proc, the open syscall is intercepted and the returned file descriptor points to a temporary file with emulated contents. If TMPDIR is not accessible or writable for the current user (for example in a read-only mounted chroot or container) tools such as ps from procps may fail unexpectedly. Trying to read one of these paths such as /proc/self/stat would return an error such as ENOENT or EROFS. To relax the requirement on a writable TMPDIR, use memfd_create() instead to create an anonymous file and return its file descriptor. Signed-off-by: Rainer Müller Reviewed-by: Richard Henderson Message-Id: <20220729154951.76268-1-raimue@codingfarm.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b27a6552aa34..ef53feb5ab45 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8260,16 +8260,22 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int char filename[PATH_MAX]; int fd, r; - /* create temporary file to map stat to */ - tmpdir = getenv("TMPDIR"); - if (!tmpdir) - tmpdir = "/tmp"; - snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir); - fd = mkstemp(filename); + fd = memfd_create("qemu-open", 0); if (fd < 0) { - return fd; + if (errno != ENOSYS) { + return fd; + } + /* create temporary file to map stat to */ + tmpdir = getenv("TMPDIR"); + if (!tmpdir) + tmpdir = "/tmp"; + snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir); + fd = mkstemp(filename); + if (fd < 0) { + return fd; + } + unlink(filename); } - unlink(filename); if ((r = fake_open->fill(cpu_env, fd))) { int e = errno;