From patchwork Tue Oct 25 07:35:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018709 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 E3C37C38A2D for ; Tue, 25 Oct 2022 08:33:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMb-0005yR-7T; Tue, 25 Oct 2022 04:32:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onEUF-0001LJ-EF for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:42 -0400 Received: from mout.kundenserver.de ([212.227.126.133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onEU5-0003Iz-Nk for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:27 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MIdNt-1oqHHQ1zgT-00EeNr; Tue, 25 Oct 2022 09:36:09 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: WANG Xuerui , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jiaxun Yang , =?utf-8?q?Andreas_K_=2E_H=C3=BCttel?= , Joshua Kinard , Laurent Vivier Subject: [PULL 1/8] linux-user: Fix more MIPS n32 syscall ABI issues Date: Tue, 25 Oct 2022 09:35:59 +0200 Message-Id: <20221025073606.3114355-2-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:ZBnt8R6L1Wfxufun9nDQQ4XEeO8Ez4YxdCnokBX4O85Oor1csTB 1SxiIfNKfIzL6uiGywxsp5quhU/xALzOSVyFfvyWVEPJGzwsBFDhfJfUMYHuUvng8AZMhu2 hSkaNAx7Q+mOOXEHBoT5PETl1uRvAwjGiIZTlMeAac+f1E0ukHXX2srqoSzfr+4FCNsMYpT B+TS6p2RJYmbOsQt5PpXA== X-UI-Out-Filterresults: notjunk:1;V03:K0:Rah9ltQBPxU=:82cUdJRGwjFu/MP3fLRV9w JAsYUgtANG44FfAdf8CP4eBJ7MjZduYeXJAyIX8Dgpd+cKJr+CgijlYQrCKcc5rovOp078JJL 6EgXtCmVc8SHoyBzOxZ/PeFnAWzH+RwgG06os/91YWEXXxLEIbiQRRQBRKkI0rdLFMQIMgq74 fN3RvJGHxU7POk/E7MduMbFDE1NyLsOFGLjgMaYdx5Vgrcd/GQKBFn3beKXzSZ2dY7DXev9rr NkOw2zc0XwmvZLyPeW1bpSBQdi6S5LfC4gFZYTm0zuuDHlyKhr2wnrsMEi8ma7oG4T/1dnbr8 k75fTA6VJu7bZ8qiyic4aNdOkPwfQXAAypfyGz0TtndRzWHpMljNw3JDGRq26BAa7nvlzxl9K K6CEFshYzuZ8IgIivJ4dkIPFW/6ZPxcptdQKX8s85czaYxsDNv3yf+Qir6zwwWcKAdfRCXmnK MJve8TYPG2cWo2FsQZ/bYENqSJxZHJFOD62SBoGUXpW7dGr1NjdLbc1XwU5rDp1Dy3ZWzNrA9 e0406laxrsQyKzr67LPwWm4inRzoz4VYDm9/0V/neWw64wWkW4LHZd5MFJfCeJ6FOZsSMn/uM cp4t8ID0orM8Xnnflzjhp+VNS1GHu+PA3wKeNqQNaEDsS4+p2izErHZspcDaKZ8AFXNqf583y J7tvvUPGr4LjcWsBHzbXUeNbUdaBqEZBDDz9fc5XyA9berAPtWVr5Kt7FxKgp9Frwx5CDxIun TIgAD6PH5fI24LOb4vgvcaz3GwbTGKqWlFHtkoifO5QQa6DmlXoURpqUZ1XVmTj70a3kqSwCL 1XsIXlN Received-SPF: none client-ip=212.227.126.133; 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: WANG Xuerui In commit 80f0fe3a85 ("linux-user: Fix syscall parameter handling for MIPS n32") the ABI problem regarding offset64 on MIPS n32 was fixed, but still some cases remain where the n32 is incorrectly treated as any other 32-bit ABI that passes 64-bit arguments in pairs of GPRs. Fix by excluding TARGET_ABI_MIPSN32 from various TARGET_ABI_BITS == 32 checks. Closes: https://gitlab.com/qemu-project/qemu/-/issues/1238 Signed-off-by: WANG Xuerui Cc: Philippe Mathieu-Daudé Cc: Jiaxun Yang Cc: Andreas K. Hüttel Cc: Joshua Kinard Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Jiaxun Yang Tested-by: Jiaxun Yang Tested-by: Andreas K. Huettel Message-Id: <20221006085500.290341-1-xen0n@gentoo.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2e954d8dbd9e..8b2d39fe73b3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11793,7 +11793,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, return -host_to_target_errno(ret); #endif -#if TARGET_ABI_BITS == 32 +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) #ifdef TARGET_NR_fadvise64_64 case TARGET_NR_fadvise64_64: @@ -11920,7 +11920,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, return get_errno(sys_gettid()); #ifdef TARGET_NR_readahead case TARGET_NR_readahead: -#if TARGET_ABI_BITS == 32 +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) if (regpairs_aligned(cpu_env, num)) { arg2 = arg3; arg3 = arg4; @@ -12612,7 +12612,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #endif /* CONFIG_EVENTFD */ #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate) case TARGET_NR_fallocate: -#if TARGET_ABI_BITS == 32 +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4), target_offset64(arg5, arg6))); #else @@ -12623,7 +12623,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #if defined(CONFIG_SYNC_FILE_RANGE) #if defined(TARGET_NR_sync_file_range) case TARGET_NR_sync_file_range: -#if TARGET_ABI_BITS == 32 +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) #if defined(TARGET_MIPS) ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), target_offset64(arg5, arg6), arg7)); @@ -12645,7 +12645,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, case TARGET_NR_arm_sync_file_range: #endif /* This is like sync_file_range but the arguments are reordered */ -#if TARGET_ABI_BITS == 32 +#if TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), target_offset64(arg5, arg6), arg2)); #else From patchwork Tue Oct 25 07:36:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018705 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 CD865C04A95 for ; Tue, 25 Oct 2022 08:32:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMQ-0002wy-Fz; Tue, 25 Oct 2022 04:32:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETx-0001JF-SK for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:24 -0400 Received: from mout.kundenserver.de ([212.227.126.187]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETu-0003GT-0R for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:17 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MPowd-1oQSfi3qdf-00MrIH; Tue, 25 Oct 2022 09:36:10 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier , Helge Deller Subject: [PULL 2/8] linux-user: fix pidfd_send_signal() Date: Tue, 25 Oct 2022 09:36:00 +0200 Message-Id: <20221025073606.3114355-3-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:C0zMStXtK+BLeF6sFH/S8vlAV/96IZfZaA6uWRptajzRx1Gg5b6 fN/6oolABRr6lugUCVfu+vjO3doGtNrZAiPoqgfYdt61clcwA+t2V/x1+z4H+C+nZgtPpwg 8QQth32dL564vUQ/uSdn/lFBp2d/Hfu6/ICjYbfvVbmvUGneH9Zu0oA1qx6fQbEBlo0gMtJ nCd9UJq1slrS+NywqpG1g== X-UI-Out-Filterresults: notjunk:1;V03:K0:BD8KFicWM4Y=:WMuO1bbv2odndudheMnKUR bM2r9ODkkzGduF7EfChus2BAUMPCUgKoLEOtFBUoSia1VRLZ2GrY91AjJ6giTYuEZe6TMkzPr A/uM1y/+2UYvk7yg9xFuJjowG9rfEuFH5to8i7YnaE41kx/+X6PIvGIibkCwNl4SeqnyxdID8 jk0jlR1andAj2NwMHDdzOM9S7hQQyhFSsklIfOKxu/C4xTHuvIY81HaWMz3pTD++q5eXUlhtP aUiLgmFTQ1KsmIRudRKduuNLDoKadQxzDjWt2pACGUdjjRxk3jJ5xvYXHb0JauvLzrjuTNmz/ w06SNzM4F3YmdLTNYS3kfNpMhLY+hM9qO+mWlLb6xdcg/mJWfwdXw4i56MrDRpN2s7k5w1wjs CcEMm1ImUvRv0uPSfzHoYhMunNH3fdGCagZ+H0tLtz4YNaFnAnmKOLk2jZHWIkncIf7ZvQ34A BHjLSJDs0u/0MGUvVCUzSEEQVPsJf+nR+O07irWukICLnmqQliiighlMCjejlsY5IV/2YyRpz PS3UWHNPx45ReDnQy5c85QQ/+GCNGCkNqM5VRX/yEZDTF5rm6FoY9C2fZlFQ0+y5dyHU71oZA gbAKuRD1CIyK8YgcSUXJg3edd+hmqoU1gbx9cgTmrcvzm88W8GgItPwTZL62DV4BA4knKs/QT YTHZz4PoonIySXWpOgnJL8Rl5ePf46TgxivnktbGiGWSh9n+xaBAM2VZLZ2wQhhziYhHZXKx2 acgu3Jv6ORBcftxGnN8DsnYUcBMIAihCpbnPIctoZCoI3qGsFCr5/pweIlnLCJdzUgAj4XZds r2+Y5jD Received-SPF: none client-ip=212.227.126.187; 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org According to pidfd_send_signal(2), info argument can be a NULL pointer. Fix strace to correctly manage ending comma in parameters. Fixes: cc054c6f13 ("linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls") cc: Helge Deller Signed-off-by: Laurent Vivier Reviewed-by: Helge Deller Message-Id: <20221005163826.1455313-1-laurent@vivier.eu> Signed-off-by: Laurent Vivier --- linux-user/strace.c | 4 ++-- linux-user/syscall.c | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 37bc96df9bb6..86c081c83f74 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -3383,10 +3383,10 @@ print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name, unlock_user(p, arg2, 0); } else { - print_pointer(arg2, 1); + print_pointer(arg2, 0); } - print_raw_param("%u", arg3, 0); + print_raw_param("%u", arg3, 1); print_syscall_epilogue(name); } #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8b2d39fe73b3..ad06ec7bd54c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8679,16 +8679,21 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal) case TARGET_NR_pidfd_send_signal: { - siginfo_t uinfo; + siginfo_t uinfo, *puinfo; - p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1); - if (!p) { - return -TARGET_EFAULT; + if (arg3) { + p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1); + if (!p) { + return -TARGET_EFAULT; + } + target_to_host_siginfo(&uinfo, p); + unlock_user(p, arg3, 0); + puinfo = &uinfo; + } else { + puinfo = NULL; } - target_to_host_siginfo(&uinfo, p); - unlock_user(p, arg3, 0); ret = get_errno(pidfd_send_signal(arg1, target_to_host_signal(arg2), - &uinfo, arg4)); + puinfo, arg4)); } return ret; #endif From patchwork Tue Oct 25 07:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018707 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 8ACDCFA373E for ; Tue, 25 Oct 2022 08:33:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMP-0002d8-CB; Tue, 25 Oct 2022 04:32:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETx-0001JG-WC for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:27 -0400 Received: from mout.kundenserver.de ([212.227.126.133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETu-0003GM-Ie for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:15 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mw9Dg-1p3fN01ByO-00s5hu; Tue, 25 Oct 2022 09:36:10 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier Subject: [PULL 3/8] linux-user: handle /proc/self/exe with execve() syscall Date: Tue, 25 Oct 2022 09:36:01 +0200 Message-Id: <20221025073606.3114355-4-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:3StfFPlIReSm6A+oxQIyyz58djW7xGdZS0pdCg+AEOetKGflG9O ACY/haEe2aklj1phez5R8BcyChsd1bsbm/fNlD9Yit/AKKu+Ag0uzBArlXkQXwOLICu3BU+ e6d9xHshpItxcVsBlncf1BcinD7HSIWUKoOs8tnDFKiBgrqx76ODiRiG3fZi0fynvgcGomx yCz/+Ub9PTWFtLq3PSkoQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:enHGnr2kr1c=:PRM3nDTdbwjmu3ettL6/AM 3fwiMZWIv8mrM4RIaWoNKytbr41APacHGK8uXzbS0OT8dwMQ2rn1eFyH/eAcdllmWBqS3vqG/ qOP19JpvXqbtHEePy0TiLo9u8nvN8iLe1QxMkbn4+a8/RFyEmTN0XbMYF+zJPgy9GGwHU14+L KnOoGi1bC67eRSCdcaUsj+rEwV0k79TfvCNqkgAFQczIfHl59MSs/RAGngpxpVGvW+mHIy3HU H1S1r3PEaus2363rdIPHJUOtkecWVOSPnuVu18jCwUo3v/5l6G0AQppaQOEBtCdr9mzWT9vm+ haPMGVcNZremzmZYd9wFl/NQ7XwuIJdsxdlTE882HGVYcIiYUFF1T7Kbi2rekqsNhq8OohBJG 3iFjpKhA1yoTeG+dMReXIzuBsjA64r8wWUC3czEDLMdnd9Tniwtn84rcMH1wljyqeUFLGw5+w mZuEn3hVvR34e36BdJMn9TJBtsa8kqQApqW6ZOvz8NokmwGOyBUqvRb484dz6XZpZEr1WUGIl VLNcW/JrJgyrSXikEoQEKMZLjCjggrRl/xw9nY3TnQBLDf1X/hRRgHa5ywwR69fuaQXIdJZAb T97G/u7sFG5yYN91Pl2HnRppdnA7Jm4keuWd/kDGDlRwMo5B2CSUfv7iJQAMAMVufdrdLDRzh MPIIvjEZS5Q7Pzl+qJWruY/ONNzaabWq+rINNkMcg8aSyQ5wxku8UHkcVYCHOhX5aVvdL5CMi oVmSCwKVCUO5Dc4Ih473QL8nS8UMBhHPUFOX+OPgqMSdoSCRqFGyzGjpoxDRa/N3MJoXVCI5x 3rpvZOf Received-SPF: none client-ip=212.227.126.133; 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org If path is /proc/self/exe, use the executable path provided by exec_path. Don't use execfd as it is closed by loader_exec() and otherwise will survive to the exec() syscall and be usable child process. Signed-off-by: Laurent Vivier Message-Id: <20220927124357.688536-2-laurent@vivier.eu> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ad06ec7bd54c..a7a29091c91e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8860,7 +8860,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, * before the execve completes and makes it the other * program's problem. */ - ret = get_errno(safe_execve(p, argp, envp)); + if (is_proc_myself(p, "exe")) { + ret = get_errno(safe_execve(exec_path, argp, envp)); + } else { + ret = get_errno(safe_execve(p, argp, envp)); + } unlock_user(p, arg1, 0); goto execve_end; From patchwork Tue Oct 25 07:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018729 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 DA138C38A2D for ; Tue, 25 Oct 2022 08:41:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMO-0002Fb-6I; Tue, 25 Oct 2022 04:32:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETx-0001JE-Rr for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:24 -0400 Received: from mout.kundenserver.de ([212.227.126.133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETu-0003GN-K9 for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:17 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MmDZI-1pV7s22hX6-00iDpq; Tue, 25 Oct 2022 09:36:10 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier Subject: [PULL 4/8] linux-user: don't use AT_EXECFD in do_openat() Date: Tue, 25 Oct 2022 09:36:02 +0200 Message-Id: <20221025073606.3114355-5-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:FasWSiQEGXXU505rB4KLG475g78LV0gnuq3gpwDhTTprLBb9ANd VIhRJ8ZkrvIvarB1p6tqf7ivEVbT5R5ilGOxGHMAK9Mn7vH1e4CwwXZhgRCF8RBuHxs52Uf GpiFNXlFs9pkstRTPhAIjtDrQHiKGlF+orPOraxXllGdRAKFHsUdWbz54ssF+7ACq92yU1s 0Hm8dRqCgMlFr09X4EQBg== X-UI-Out-Filterresults: notjunk:1;V03:K0:5XZtzPtxoXs=:B0ZtI4BUR7AX3WU4PfaqVo IgLtx6JX6cwm6V+d03CT8OJMEMot127AN0W3Cx+swr9XZSEo/2wsvXOudafr/c/q4wawSEU5c VCSmyOEoOeuTFoH51MeaIZSUITCGqn/pBdemUQLsODoZy+rhyCCzyJAJxapr0baqGsnc5bGJB TvpFWySL9VWXDYwWFn8ciqNFJSC6h9q6XOyYPVTXfAsdIJcQIDV5jQBjGJ9ZoRtcXcnHdeBb+ 5+6OM2pBYNUxfEdw2XEtmhakeRg7r0e1bsuGbGp9FDsWE/gP+Pisg6Rn0xAnOeAjDE8CLrThv E1fkD8GySh3tVkRnV0MLOkAeMbg2wZCO06O4pePMvuzfzBVmwchuT2WIVTRV0U3ONNlfAFWSo rlzUJt060ci7WpGbZwdX+48DQnByfEmFWD4xcuI5OmyYBKK+kxfAkNQJEvCpRrGkQmbpn69Sb RH+drlsn4mlDVr0tiN4d3v5b07yukiDytdzLr+5oVyJrRAXTcpj5Nchdj0KwYUgTXEBGf3Xm0 mRMzCFr+7eOgTgKlzgYtkvlB2UYdV3p9jtBwbo5ETtciUqApqJPnL1yGwqKeWtINcACf813KY GcvvpMdy2JUlP0WjvUjRre7fj+xM+1wrcUgtS7eyYRem4vJhBVVIKQFYzt/2t+JC/UZqwB9ao nKrdakEaBtrpgHG8lFy5SG34615suwoYe7xl6dzmRRs5neFQsrwXENiMI7gb2J3z1JVO4aWGD fFHdcDqI/J5Tx/CXBgpK/0zqlZwRqCl5VJglbuTeMN5ak0lk+GjhxfrWwhvzyPFRJ1jd0uaeb 69WL8Ty Received-SPF: none client-ip=212.227.126.133; 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org AT_EXECFD gives access to the binary file even if it is not readable (only executable). Moreover it can be opened with flags and mode that are not the ones provided by do_openat() caller. And it is not available because loader_exec() has closed it. To avoid that, use only safe_openat() with the exec_path. Signed-off-by: Laurent Vivier Message-Id: <20220927124357.688536-3-laurent@vivier.eu> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a7a29091c91e..665db67c0598 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8251,8 +8251,7 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int }; if (is_proc_myself(pathname, "exe")) { - int execfd = qemu_getauxval(AT_EXECFD); - return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode); + return safe_openat(dirfd, exec_path, flags, mode); } for (fake_open = fakes; fake_open->filename; fake_open++) { From patchwork Tue Oct 25 07:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018750 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 038A2C38A2D for ; Tue, 25 Oct 2022 08:47:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMV-0004LD-9m; Tue, 25 Oct 2022 04:32:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onEU5-0001L5-3W for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:30 -0400 Received: from mout.kundenserver.de ([212.227.126.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETw-0003Gt-Or for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:24 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MLRDv-1oUsW00Gzz-00ITZZ; Tue, 25 Oct 2022 09:36:11 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Laurent Vivier Subject: [PULL 5/8] linux-user: add more compat ioctl definitions Date: Tue, 25 Oct 2022 09:36:03 +0200 Message-Id: <20221025073606.3114355-6-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:U03RBkbM0HhcdIqqQzHoBpd+sAwSy2RCFZT35yev4XV941zUn8i wNUGukZ2K7HLmmedZLeKu0gwaeI9wP1LO+YaC4JUGKvrkhRxZQQ4LDiryftyS7nd2GxQIH3 w/gc6RQzlmsC7rjAgIvX6hOOHryaDPu3cetcZ5oB0ZmHhPJpuxhVwYZWkNzZf+vESi1JoZi u4Irp+vc9ooBBFXQ54vSg== X-UI-Out-Filterresults: notjunk:1;V03:K0:gq0JphV1rOU=:hVi9N1fjUkSDaUYvUf1DaE aacyLBH7g80UJAg0OHoKrWBQu4Dpi+BR9iHcskq24Y5xBLx/x2x9DTXYLJYnEZeeHlbuo0wgz GiRBtb3EFk3VKjOOtvc4RTNjcDe98fR4Z8Yj0hKQUTg3NIs0r4O6XMSLFGMkhlM+V+lYmEnEb sXlHEqalodt0X97bBuCjUeH8I28N4I2g01F4Oba3CzzD3W+vOwjmyn3N2RQqzq3ZjeUiFTCm+ 9r4lTt2JTy4xTurAZN+kt2gI3USKH7TzofVbHWzUhgpkdjQBY92X9SwuaKkWCIIb3OHh83n+J KqMDsEn1sHiVbGoRGu6yhZXTb4LZMimw6rpvf0qTaEXTbpUteg3ETOMly+kGzMXIDY48B1sQM 64fBt8QnPJ/ceaACLMKFmVnHlUANPfgU30VdJx7i0p/Pbs8niQlk+uqrl44pz6WaMpclVYE5f N9CYNUKC/MIDAULrzZk2DuXYzT6+3kKZl+D7kX3nfEy6Nk0WCGX22g1jdD+gBjgglSYrTNfO3 cn1NUEeTO+ATJ3UYsA27qbHtCHBD3jbPqpf4PzcLNwaDe0aGuBcg0xAhWYGIORW6sdusLjR+s e4KDHdQT6Z9eGn04gLaQnxnL80A04xBVjyIUNYMKABLY4E9Clcdd7RQ15Kcu8TTGZn+/3D617 atPXfrswC5KgaA7Z5OqYG23PAMPeSRjpS3owK2DTC44+QCXKH6Wv4nXhrA94f3REaKEAM25Dh VvODytla/S1BYv1hDI0C173W0cWIK1/VY7q+eMqDNs96jy0OBnQpwWLfFXtnqebnoYpzyxalm hue2lVq Received-SPF: none client-ip=212.227.126.131; 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Daniel P. Berrangé GLibc changes prevent us from including linux/fs.h anymore, and we previously adjusted to this in commit 3cd3df2a9584e6f753bb62a0028bd67124ab5532 Author: Daniel P. Berrangé Date: Tue Aug 2 12:41:34 2022 -0400 linux-user: fix compat with glibc >= 2.36 sys/mount.h That change required adding compat ioctl definitions on the QEMU side for any ioctls that we would otherwise obtain from linux/fs.h. This commit adds more that were initially missed, due to their usage being conditionalized in QEMU. Signed-off-by: Daniel P. Berrangé Reviewed-by: Laurent Vivier Message-Id: <20221004093206.652431-2-berrange@redhat.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 665db67c0598..d499cac1d5d1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -111,6 +111,31 @@ #define FS_IOC32_SETFLAGS _IOW('f', 2, int) #define FS_IOC32_GETVERSION _IOR('v', 1, int) #define FS_IOC32_SETVERSION _IOW('v', 2, int) + +#define BLKGETSIZE64 _IOR(0x12,114,size_t) +#define BLKDISCARD _IO(0x12,119) +#define BLKIOMIN _IO(0x12,120) +#define BLKIOOPT _IO(0x12,121) +#define BLKALIGNOFF _IO(0x12,122) +#define BLKPBSZGET _IO(0x12,123) +#define BLKDISCARDZEROES _IO(0x12,124) +#define BLKSECDISCARD _IO(0x12,125) +#define BLKROTATIONAL _IO(0x12,126) +#define BLKZEROOUT _IO(0x12,127) + +#define FIBMAP _IO(0x00,1) +#define FIGETBSZ _IO(0x00,2) + +struct file_clone_range { + __s64 src_fd; + __u64 src_offset; + __u64 src_length; + __u64 dest_offset; +}; + +#define FICLONE _IOW(0x94, 9, int) +#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range) + #else #include #endif From patchwork Tue Oct 25 07:36:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018712 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 3A3C1C38A2D for ; Tue, 25 Oct 2022 08:35:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMS-0003bD-Qh; Tue, 25 Oct 2022 04:32:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETz-0001JO-5S for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:24 -0400 Received: from mout.kundenserver.de ([212.227.126.133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETw-0003Gx-PT for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:18 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MLAF0-1oV9dB2Cjy-00ICSO; Tue, 25 Oct 2022 09:36:11 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Laurent Vivier Subject: [PULL 6/8] linux-user: remove conditionals for many fs.h ioctls Date: Tue, 25 Oct 2022 09:36:04 +0200 Message-Id: <20221025073606.3114355-7-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:1p8GCLFQVIWBjHEWTGWIcGZOI9FslGEHLLfcknTtckVTz0uFXRw UM/7k4JNOwmCGqOSosnqbb/8BL91DEKV8xqSM8Z+069ckz4J57njjh+QluxG1APJ2/wtvnA Lnjzm5xFPpOjg5OKJzw6jNxt3tQfTGafDLPV3OzEnHTAdc1KD1XXsSL5Xv/x2ssUdQY1Nik 4NILndIkny0/HdGkcuNtA== X-UI-Out-Filterresults: notjunk:1;V03:K0:ykZfpIo+SZM=:CEqTtFuPbn8vlGBqttEwrc c94stDNC78GDvxgt0ZwARqV3NGKCZZgHeta/43RJjHvXIOteZVEFfLyj5gjd9C00G87rcTGb1 iGNAIRLU5WAjWYGAF8s8gjEfaWuGtNmjSuaBNM8ZYZxfwCusr73kg6ewK/rQo/LSYut2pg+A8 olOnw57q8SCH/u/qIgl42jeKBJ4jtYg8oMPUwbWQ30FMibuL3eq+67gxTzizzQe2NwiTq4TUE EcSrmsIy3/RGYbrJDRyvogeG6t+UkqoV+9BzsteIOWJJt5qPQjalcmHwmvOilhFk/rZNnQ0ZC 1hDxqvj6Ue47ZfXV30iwRgW1aTJ0y1xHrLrw0LgetVITGO9emKLJcxpC9auiI7/GaE6wleQ2z 9+3HG5Sn+JL9mtXYd9IqqEelLvKUur10W0yaHvDVoYyYoEoY+yJpDgnx+QCmcerLJzcEs+gUU eByNpbQGgH8y340H1gtCQNIS4bA4EJdV1q9abqlMCP/AeVieQ7zYNAlW1wazRV1D8AzLMZxAT RvcaBvuSbGk+IBNIRJMA1ARAb6/uZwZ7ily+3dmYgTLv3n814xCRS6VT5to0v38Dwo15b7Mkh 4gejpwDyrgHsvCbK6pxMu6/KHAiGLZa57Tdr7ncTA7nWUgqs33b4EVXGHuxw8tgfsGvKW4ItZ j69YF+c69EpgwhaO5t4Yr2+VnXXUE1yU50vO7fcCbEkbldYQGfDHptNNuILpUOnEmg0W4+3g2 vap3CCukkn5CYMlDx0tzdTjPVJaono206xoLOUg/y035Bp+pT/5tR3tyPQ/fVdls93qwa/ikw TPONPUc Received-SPF: none client-ip=212.227.126.133; 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Daniel P. Berrangé These ioctls have been defined in linux/fs.h for a long time * BLKGETSIZE64 - <2.6.12 (linux.git epoch) * BLKDISCARD - 2.6.28 (d30a2605be9d5132d95944916e8f578fcfe4f976) * BLKIOMIN - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7) * BLKIOOPT - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7) * BLKALIGNOFF - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7) * BLKPBSZGET - 2.6.32 (ac481c20ef8f6c6f2be75d581863f40c43874ef7) * BLKDISCARDZEROES - 2.6.32 (98262f2762f0067375f83824d81ea929e37e6bfe) * BLKSECDISCARD - 2.6.36 (8d57a98ccd0b4489003473979da8f5a1363ba7a3) * BLKROTATIONAL - 3.2 (ef00f59c95fe6e002e7c6e3663cdea65e253f4cc) * BLKZEROOUT - 3.6 (66ba32dc167202c3cf8c86806581a9393ec7f488) * FIBMAP - <2.6.12 (linux.git epoch) * FIGETBSZ - <2.6.12 (linux.git epoch) and when building with latest glibc, we'll see compat definitions in syscall.c anyway thanks to the previous patch. Thus we can assume they always exist and remove the conditional checks. Signed-off-by: Daniel P. Berrangé Reviewed-by: Laurent Vivier Message-Id: <20221004093206.652431-3-berrange@redhat.com> Signed-off-by: Laurent Vivier --- linux-user/ioctls.h | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index f182d40190ed..071f7ca25375 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -96,9 +96,7 @@ IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT)) IOCTL(BLKRRPART, 0, TYPE_NULL) IOCTL(BLKGETSIZE, IOC_R, MK_PTR(TYPE_ULONG)) -#ifdef BLKGETSIZE64 IOCTL(BLKGETSIZE64, IOC_R, MK_PTR(TYPE_ULONGLONG)) -#endif IOCTL(BLKFLSBUF, 0, TYPE_NULL) IOCTL(BLKRASET, 0, TYPE_INT) IOCTL(BLKRAGET, IOC_R, MK_PTR(TYPE_LONG)) @@ -107,33 +105,15 @@ IOCTL_SPECIAL(BLKPG, IOC_W, do_ioctl_blkpg, MK_PTR(MK_STRUCT(STRUCT_blkpg_ioctl_arg))) -#ifdef BLKDISCARD IOCTL(BLKDISCARD, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2))) -#endif -#ifdef BLKIOMIN IOCTL(BLKIOMIN, IOC_R, MK_PTR(TYPE_INT)) -#endif -#ifdef BLKIOOPT IOCTL(BLKIOOPT, IOC_R, MK_PTR(TYPE_INT)) -#endif -#ifdef BLKALIGNOFF IOCTL(BLKALIGNOFF, IOC_R, MK_PTR(TYPE_INT)) -#endif -#ifdef BLKPBSZGET IOCTL(BLKPBSZGET, IOC_R, MK_PTR(TYPE_INT)) -#endif -#ifdef BLKDISCARDZEROES IOCTL(BLKDISCARDZEROES, IOC_R, MK_PTR(TYPE_INT)) -#endif -#ifdef BLKSECDISCARD IOCTL(BLKSECDISCARD, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2))) -#endif -#ifdef BLKROTATIONAL IOCTL(BLKROTATIONAL, IOC_R, MK_PTR(TYPE_SHORT)) -#endif -#ifdef BLKZEROOUT IOCTL(BLKZEROOUT, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2))) -#endif IOCTL(FDMSGON, 0, TYPE_NULL) IOCTL(FDMSGOFF, 0, TYPE_NULL) @@ -149,17 +129,13 @@ IOCTL(FDTWADDLE, 0, TYPE_NULL) IOCTL(FDEJECT, 0, TYPE_NULL) -#ifdef FIBMAP IOCTL(FIBMAP, IOC_W | IOC_R, MK_PTR(TYPE_LONG)) -#endif #ifdef FICLONE IOCTL(FICLONE, IOC_W, TYPE_INT) IOCTL(FICLONERANGE, IOC_W, MK_PTR(MK_STRUCT(STRUCT_file_clone_range))) #endif -#ifdef FIGETBSZ IOCTL(FIGETBSZ, IOC_R, MK_PTR(TYPE_LONG)) -#endif #ifdef CONFIG_FIEMAP IOCTL_SPECIAL(FS_IOC_FIEMAP, IOC_W | IOC_R, do_ioctl_fs_ioc_fiemap, MK_PTR(MK_STRUCT(STRUCT_fiemap))) From patchwork Tue Oct 25 07:36:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018708 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 9406DC04A95 for ; Tue, 25 Oct 2022 08:33:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMW-0004iV-Rj; Tue, 25 Oct 2022 04:32:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onEU5-0001L6-8I for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:30 -0400 Received: from mout.kundenserver.de ([212.227.126.133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onEU3-0003Hj-Gc for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:25 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N32y5-1pEQrZ0Eub-013LBv; Tue, 25 Oct 2022 09:36:12 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: WANG Xuerui , =?utf-8?q?Andreas_K_=2E_H=C3=BCttel?= , Laurent Vivier Subject: [PULL 7/8] linux-user: Implement faccessat2 Date: Tue, 25 Oct 2022 09:36:05 +0200 Message-Id: <20221025073606.3114355-8-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:QDvODlbm5JC+HJJRhSY10kxwrSCubyBAMP2E/pFg0zBF3AUNykh usNXY1XRFw9C6M2TX8/AuAgRfSKNozmtEEEId7mAtdzATORQ5AOxg+EfWw1KE0zDjipswA9 4GokYy+tAix57UZdqrdCSL4Fh0O7yney707PCvRUOJbrBLHwqSxe93tAOc2a/B+UT1WtVJl am9QtJIsesLXDa9IJ//Rg== X-UI-Out-Filterresults: notjunk:1;V03:K0:XRgM17klfF4=:7DzSbKkIRtOfka6j6jabAt XFf05RGv2TSEx7xO/GrX8KaXfH8Q8np+tD4WD02xwRx5119AiwpxN8UwLqZJulJ+6+6fw9NwA U1Yq1RmLrGWihFmTkGvjFhYxFYlyLfeibYQF50lfslGsiVVyEkPowbF+RALoNxnAakMYL9p5k 6/3Su1edTl3bMknhUvXZqJrJahdI3Kx62kzjq7yW3IYKBhIH52q7pWA4Ao4+j5eseFfNUVitR zdPNMV4X6iPrFeikPcg6utrXQOd2MgcgnjtnrmI6KIdxyS9GeVfI7Mrq2jm2kCB5baPaAetGz gP1jXSaIK9f7PZVcZsMpdbrYEsbygtOvyqaQNIEYZYk8Qs1+flEzvOyYFUDHCqEtVw/4jKUyX JBYUWC7SND+pZNamTeKCeg5scXw4SosJvuKzOtq+NPM2FTPRwv+Bouo2t6j6sa83ZHVeX+kJ5 MwWrCVZxhL8OUD9RFxmFuBMeerEQZhZNe4NI9A7Nl6b4tdPvCSeNnlOag27KrmnhT1QZXA5C1 Bd6UziVFhUdFsfX2D/Jb33BBgAagmSqCmoTUqm15F5MXcBcbGZ8AEMXJG4HZJCJL78OaC5fSt 5qWufMt9NKskqsF3TyBmJrBL/vLj67AxUK58FGVP5kebfbVmrPsjoxL/kE/WQNmt6uIGS0fXf 42hRwhpU/lzr8l6Gr0msl5tDX0i1c9FpqdfbH31DFtb96iR9HEgoz+iO1Nn8z85VqJB6cxi4W G/U2mubxVxnrjzI5LNE9/s3H5iZbHHoj3Np3/0qyNVHW2src0PAf/hTujDZ2UwOkaqPdbDMf6 EsSKEum Received-SPF: none client-ip=212.227.126.133; 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: WANG Xuerui User space has been preferring this syscall for a while, due to its closer match with C semantics, and newer platforms such as LoongArch apparently have libc implementations that don't fallback to faccessat so normal access checks are failing without the emulation in place. Tested by successfully emerging several packages within a Gentoo loong stage3 chroot, emulated on amd64 with help of static qemu-loongarch64. Reported-by: Andreas K. Hüttel Signed-off-by: WANG Xuerui Message-Id: <20221009060813.2289077-1-xen0n@gentoo.org> [lv: removing defined(__NR_faccessat2) in syscall.c, adding defined(TARGET_NR_faccessat2) on print_faccessat()] Signed-off-by: Laurent Vivier --- linux-user/strace.c | 2 +- linux-user/strace.list | 3 +++ linux-user/syscall.c | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 86c081c83f74..9ae5a812cd71 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -1969,7 +1969,7 @@ print_execv(CPUArchState *cpu_env, const struct syscallname *name, } #endif -#ifdef TARGET_NR_faccessat +#if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2) static void print_faccessat(CPUArchState *cpu_env, const struct syscallname *name, abi_long arg0, abi_long arg1, abi_long arg2, diff --git a/linux-user/strace.list b/linux-user/strace.list index a87415bf3d50..3df2184580aa 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -178,6 +178,9 @@ #ifdef TARGET_NR_faccessat { TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL }, #endif +#ifdef TARGET_NR_faccessat2 +{ TARGET_NR_faccessat2, "faccessat2" , NULL, print_faccessat, NULL }, +#endif #ifdef TARGET_NR_fadvise64 { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL }, #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d499cac1d5d1..e985ad167f21 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9143,6 +9143,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, unlock_user(p, arg2, 0); return ret; #endif +#if defined(TARGET_NR_faccessat2) + case TARGET_NR_faccessat2: + if (!(p = lock_user_string(arg2))) { + return -TARGET_EFAULT; + } + ret = get_errno(faccessat(arg1, p, arg3, arg4)); + unlock_user(p, arg2, 0); + return ret; +#endif #ifdef TARGET_NR_nice /* not on alpha */ case TARGET_NR_nice: return get_errno(nice(arg1)); From patchwork Tue Oct 25 07:36:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13018711 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 DB1FCC38A2D for ; Tue, 25 Oct 2022 08:34:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFMY-0005C3-7W; Tue, 25 Oct 2022 04:32:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onEUD-0001MZ-NC for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:42 -0400 Received: from mout.kundenserver.de ([212.227.126.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onETw-0003Gs-Oc for qemu-devel@nongnu.org; Tue, 25 Oct 2022 03:36:33 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N3KkM-1pD31S2MRG-010IeO; Tue, 25 Oct 2022 09:36:12 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Helge Deller , Richard Henderson , Laurent Vivier Subject: [PULL 8/8] linux-user: Add guest memory layout to exception dump Date: Tue, 25 Oct 2022 09:36:06 +0200 Message-Id: <20221025073606.3114355-9-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221025073606.3114355-1-laurent@vivier.eu> References: <20221025073606.3114355-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:G9jKMuYoVWoWt2jJqSAba3APw0eXrshayjM7liBGYlBiviBAsGI iIFayHDaL0QZydRe+Apu0mApCHQ+FaLUEQ/JA2hC4am6ifU5TZAx9JBZO2eDdqT5uyty1Zn cxshEtw38hT/II6D1TFBkQ0m0lPaNj0T4cFWt6CMG+/7LF62jcT37SjmdItL4pKF9WJnZc2 jUM/hzkNXoS3p+3xR+HHg== X-UI-Out-Filterresults: notjunk:1;V03:K0:RoO/3xaegsE=:He8PWj8xmEHc7qp8b2Qmt2 fznUKl4DtxyHd+lbh+VtFUXLz+5Ym1X6xOdUn0VtlQKjCHI0Of7d9madRKP8ceHCe4IkcUgg2 Qy4Ma+/rfJmzvNNPA6KgFlYTEnUoKNFvXfAVjRbq9O32VFpEuZoh67N3NSqKtisO6mFmLC/L9 owJnFLqIrVbF1HokKwKFLS1RwTg7uJLmqQI9bRqDkMJfhkAsfrIKx3DScZt+S2R73tmv5wwoL rgOBjslhwcoxREC8Zn7/Q9dZWsUCyZtnNuJagb7O6xg5wb/cm2Gk67KsSDN11O2jLvjAhuNuw n2s1ShkDLArHj9eZtYel0+6LQhabAsyZDPjotbdrr6sDJwVfCn1Y+4Ry31Jvyn0bqFbSvUp1A /ufKBrGYa86Jjs/FkCx55rUjEOMgXlU0KKQsEH3PvzziiQn+K14PAAIwD8+rhmPoyUQRa2kdF PKs4iifidVdUUO2m26ZhJF3lkE8z9mrg3moH6cjPlTZPQ7an+151eldQMWcsY74cbYQ1MesER mJfGgIK0rPhXysRZm2TT+fHKaxc5qvv0VzkEs2t+eRT1KtsF4uMQ551/CBofby1OSKDT2y2mF Hzj5eBvtznPbjPnVnb03TDwCArp6RHto3JnxU13LBFPxGGPGP4JI4+i6UEu1T3RbQs8tpW1cG jMJPEnL4XRcdWGxUyQxDJV0bNn0JCppr+k1b//UqRyiVcPfMh+F4PpKnbsOUCpUHF8O3BzmJc //3eqxP4UE0iKsvoLM+btY+w9qVKGzuywAUa+9lgSzfpISvrE/VF1WZYqTPJOzX/QSlrYk01E zAYELWA Received-SPF: none client-ip=212.227.126.131; 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, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Helge Deller When the emulation stops with a hard exception it's very useful for debugging purposes to dump the current guest memory layout (for an example see /proc/self/maps) beside the CPU registers. The open_self_maps() function provides such a memory dump, but since it's located in the syscall.c file, various changes (add #includes, make this function externally visible, ...) are needed to be able to call it from the existing EXCP_DUMP() macro. This patch takes another approach by re-defining EXCP_DUMP() to call target_exception_dump(), which is in syscall.c, consolidates the log print functions and allows to add the call to dump the memory layout. Beside a reduced code footprint, this approach keeps the changes across the various callers minimal, and keeps EXCP_DUMP() highlighted as important macro/function. Signed-off-by: Helge Deller Reviewed-by: Richard Henderson Message-Id: [lv: remove pc declaration and setting] Signed-off-by: Laurent Vivier --- linux-user/cpu_loop-common.h | 15 +++------------ linux-user/i386/cpu_loop.c | 6 ++---- linux-user/syscall.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/linux-user/cpu_loop-common.h b/linux-user/cpu_loop-common.h index 36ff5b14f2a7..e644d2ef9096 100644 --- a/linux-user/cpu_loop-common.h +++ b/linux-user/cpu_loop-common.h @@ -23,18 +23,9 @@ #include "exec/log.h" #include "special-errno.h" -#define EXCP_DUMP(env, fmt, ...) \ -do { \ - CPUState *cs = env_cpu(env); \ - fprintf(stderr, fmt , ## __VA_ARGS__); \ - fprintf(stderr, "Failing executable: %s\n", exec_path); \ - cpu_dump_state(cs, stderr, 0); \ - if (qemu_log_separate()) { \ - qemu_log(fmt, ## __VA_ARGS__); \ - qemu_log("Failing executable: %s\n", exec_path); \ - log_cpu_state(cs, 0); \ - } \ -} while (0) +void target_exception_dump(CPUArchState *env, const char *fmt, int code); +#define EXCP_DUMP(env, fmt, code) \ + target_exception_dump(env, fmt, code) void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs); #endif diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 42837399bcae..865413c08f07 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -201,7 +201,6 @@ void cpu_loop(CPUX86State *env) { CPUState *cs = env_cpu(env); int trapnr; - abi_ulong pc; abi_ulong ret; for(;;) { @@ -307,9 +306,8 @@ void cpu_loop(CPUX86State *env) cpu_exec_step_atomic(cs); break; default: - pc = env->segs[R_CS].base + env->eip; - EXCP_DUMP(env, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n", - (long)pc, trapnr); + EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", + trapnr); abort(); } process_pending_signals(env); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e985ad167f21..8402c1399d3c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -183,6 +183,7 @@ struct file_clone_range { #include "qapi/error.h" #include "fd-trans.h" #include "tcg/tcg.h" +#include "cpu_loop-common.h" #ifndef CLONE_IO #define CLONE_IO 0x80000000 /* Clone io context */ @@ -8169,6 +8170,33 @@ static int is_proc_myself(const char *filename, const char *entry) return 0; } +static void excp_dump_file(FILE *logfile, CPUArchState *env, + const char *fmt, int code) +{ + if (logfile) { + CPUState *cs = env_cpu(env); + + fprintf(logfile, fmt, code); + fprintf(logfile, "Failing executable: %s\n", exec_path); + cpu_dump_state(cs, logfile, 0); + open_self_maps(env, fileno(logfile)); + } +} + +void target_exception_dump(CPUArchState *env, const char *fmt, int code) +{ + /* dump to console */ + excp_dump_file(stderr, env, fmt, code); + + /* dump to log file */ + if (qemu_log_separate()) { + FILE *logfile = qemu_log_trylock(); + + excp_dump_file(logfile, env, fmt, code); + qemu_log_unlock(logfile); + } +} + #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) static int is_proc(const char *filename, const char *entry)