From patchwork Tue May 16 12:48:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243109 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 48AF7C77B7A for ; Tue, 16 May 2023 12:49:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6S-0004cR-Jl; Tue, 16 May 2023 08:48: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 1pyu6J-0004Pu-Tk for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:23 -0400 Received: from mout.kundenserver.de ([212.227.126.135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyu6H-00065o-Nm for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:23 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MPrXf-1pkn673dqt-00MvUp; Tue, 16 May 2023 14:48:13 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Afonso Bordado , Palmer Dabbelt , Laurent Vivier , Alistair Francis , LIU Zhiwei Subject: [PULL 1/9] linux-user: Emulate /proc/cpuinfo output for riscv Date: Tue, 16 May 2023 14:48:02 +0200 Message-Id: <20230516124810.90494-2-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:MVwrVJoTIufoNfQ2wu4yFIGDEfeKlQ+Yc2ks7MW7Uo/yfd0xQda 5USZSqzFyxRvr66z3B7Y7YQ+4HAgV5lQ2jEqOzawryWFqtgEQ5wmR2TQDouIkA6Q29RLS7J d9ovCtI52D+JummLM9GSH8e1x0FSA0NhMKzrbYlfi1PLFoduzyg9z0JDK2eYANP5dPvUb9F 4pnUsCW0LICf9aDXcL4Jg== UI-OutboundReport: notjunk:1;M01:P0:SdlzxfD7JhY=;mwDASfxZJ/xwuF6E7Prbupqsk3n jR/0xd6HKiPZLhKi6Vo0bSoAs2Ob0jnAdeEZr1AYKinEeCi2dZpl0YZd7yTnRgI9Mvc2C7lDX a5xjpcytg97ltDjsvTpeUl9evCL5+qC7Iq+7KlIzl73dPxhrYalSX/qAo5lTgD9ru9bhRk67Y eLReXRCTNrZVQGuKxRpSZoTD4nOKL9yN3R/VuGiHQ4ksbd/Sw/DNSIbC/UwYhkDoTwLLcNqSN yciA1aDKEpbB+nkmnWVN6Sv8GRBLy8BXWNkfFvrEDP0kSrfKxzPDNIz7P7Y6g5aCRe9tepTS7 LouzTkBlGAd1kJ7Bjcg9iMrKudH5D6e2SK7AtyOvf1r1Ur/NmYV/verzFul4hvv8T157N+wcj yclQ9feIGOZC1vjUHJm9QEThKwsurSwPPfrcLhuRiF26g0/gntjn2D/iDe+FrFUaiUALvKcSd bwpzm0EYOH16qtBlHBnwgF6+LmQFONs0AoCkp0Oz5D0zRzWu2b2awr6LL6z1GCATgfdQbEeLE AFSWPEpByxU4f2CXV0p6W5pS4/OR+1vgy1pOaRBIiPWhmGedjuvbQkp39qtSxFJu0x6+toJW8 5J7LVoeCyavBP2pF8cdoWoYxpHBxuUEopCGR9WUwvYWrXxabL3u++kj9d3e+R2BvStD2CSseQ 8AJwrQFtJ+5yRnOxpfIhXReH7AlSnNetip8rTwIo+w== Received-SPF: none client-ip=212.227.126.135; 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Afonso Bordado RISC-V does not expose all extensions via hwcaps, thus some userspace applications may want to query these via /proc/cpuinfo. Currently when querying this file the host's file is shown instead which is slightly confusing. Emulate a basic /proc/cpuinfo file with mmu info and an ISA string. Signed-off-by: Afonso Bordado Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt Reviewed-by: Laurent Vivier Reviewed-by: Alistair Francis Reviewed-by: LIU Zhiwei Message-Id: <167873059442.9885.15152085316575248452-0@git.sr.ht> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 34 +++++++++++++++++++++++++++++-- tests/tcg/riscv64/Makefile.target | 1 + tests/tcg/riscv64/cpuinfo.c | 31 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/riscv64/cpuinfo.c diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 69f740ff98c8..085ce530213e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8231,7 +8231,8 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code) } #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ - defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) + defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) || \ + defined(TARGET_RISCV) static int is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) == 0; @@ -8309,6 +8310,35 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd) } #endif +#if defined(TARGET_RISCV) +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int i; + int num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + RISCVCPU *cpu = env_archcpu(cpu_env); + const RISCVCPUConfig *cfg = riscv_cpu_cfg((CPURISCVState *) cpu_env); + char *isa_string = riscv_isa_string(cpu); + const char *mmu; + + if (cfg->mmu) { + mmu = (cpu_env->xl == MXL_RV32) ? "sv32" : "sv48"; + } else { + mmu = "none"; + } + + for (i = 0; i < num_cpus; i++) { + dprintf(fd, "processor\t: %d\n", i); + dprintf(fd, "hart\t\t: %d\n", i); + dprintf(fd, "isa\t\t: %s\n", isa_string); + dprintf(fd, "mmu\t\t: %s\n", mmu); + dprintf(fd, "uarch\t\t: qemu\n\n"); + } + + g_free(isa_string); + return 0; +} +#endif + #if defined(TARGET_M68K) static int open_hardware(CPUArchState *cpu_env, int fd) { @@ -8333,7 +8363,7 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN { "/proc/net/route", open_net_route, is_proc }, #endif -#if defined(TARGET_SPARC) || defined(TARGET_HPPA) +#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined(TARGET_RISCV) { "/proc/cpuinfo", open_cpuinfo, is_proc }, #endif #if defined(TARGET_M68K) diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target index 9973ba3b5f8c..2da65dccaf6a 100644 --- a/tests/tcg/riscv64/Makefile.target +++ b/tests/tcg/riscv64/Makefile.target @@ -4,6 +4,7 @@ VPATH += $(SRC_PATH)/tests/tcg/riscv64 TESTS += test-div TESTS += noexec +TESTS += cpuinfo # Disable compressed instructions for test-noc TESTS += test-noc diff --git a/tests/tcg/riscv64/cpuinfo.c b/tests/tcg/riscv64/cpuinfo.c new file mode 100644 index 000000000000..5c2b79022e9c --- /dev/null +++ b/tests/tcg/riscv64/cpuinfo.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#define BUFFER_SIZE 1024 + +int main(void) +{ + char buffer[BUFFER_SIZE]; + FILE *fp = fopen("/proc/cpuinfo", "r"); + assert(fp != NULL); + + while (fgets(buffer, BUFFER_SIZE, fp) != NULL) { + if (strstr(buffer, "processor") != NULL) { + assert(strstr(buffer, "processor\t: ") == buffer); + } else if (strstr(buffer, "hart") != NULL) { + assert(strstr(buffer, "hart\t\t: ") == buffer); + } else if (strstr(buffer, "isa") != NULL) { + assert(strcmp(buffer, "isa\t\t: rv64imafdc_zicsr_zifencei\n") == 0); + } else if (strstr(buffer, "mmu") != NULL) { + assert(strcmp(buffer, "mmu\t\t: sv48\n") == 0); + } else if (strstr(buffer, "uarch") != NULL) { + assert(strcmp(buffer, "uarch\t\t: qemu\n") == 0); + break; + } + } + + fclose(fp); + return 0; +} From patchwork Tue May 16 12:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243113 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 09892C77B75 for ; Tue, 16 May 2023 12:49:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6J-0004N2-Nb; Tue, 16 May 2023 08:48:23 -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 1pyu6G-0004Jy-Iv for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:20 -0400 Received: from mout.kundenserver.de ([212.227.126.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyu6C-00062x-Q0 for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:20 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MNOZO-1pnG4N1dus-00OrR4; Tue, 16 May 2023 14:48:13 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , =?utf-8?q?Philippe_?= =?utf-8?q?Mathieu-Daud=C3=A9?= , Laurent Vivier Subject: [PULL 2/9] linux-user: report ENOTTY for unknown ioctls Date: Tue, 16 May 2023 14:48:03 +0200 Message-Id: <20230516124810.90494-3-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:GPXyhX+uYm5k/ooyin6TkqR/fz5Fjrc2hhq+xNjzUXatTLXI2EL FiwX9IipQB4sg1XvDBm8AD7uZsGmMkKci+4z1pIo6Y39oMQDr26hA+FAoNfMHshQbEl/EA5 IoE3WOQCiSuBs6JYnWddx8Ba09ts2R8Xa98tR9hO/8wVC1Gap9wuLY1XZQG9sNep32qUi/H 9JrSA/TiGXskfRKC3Fv8w== UI-OutboundReport: notjunk:1;M01:P0:tgSIl66WzM4=;5Th2TV7V614P7+dYtt4i8W3a4QE j5/xgU71N5MKCRb7Dqte0oXuMoD43DEAHVVaOChuqZ6Cf66UKbKB4J/jN7QRlqz9ls3lVIJpB rAGs58JuWikFgKMJa/okoYrxgwU3z1OCTLJodKDuXB9ygPkCZKbqCDYXCRq1pT8anrqKOTW9i xQvr7Z+K7HkycCfgkc/ix6X5VweVdiDmvieF4F+8/iGwboJVvUiuBLSx3LdkeKg/dMF6a+Q7m iSN4OrlySTAF9PMuB8mdHJFH9NwdUD1hiti4uDJYz6fPDx0mDnUjK1es3mhJeOC5W0SaDJA7Z /DoVAfsAZVi2LuAvCDf9mfv9TvpZC1RdBUa3nW9U8ow2/K1Mo1WfdNXLBobTjQDrP8X5c2iae RbGIXYWZvuw3u0ZFAt7tbpOHDgVIW3Xg/Fmz8+JKOind5CA8VLpfjO1lsFURtipn+bLHKzsMT FpIl9MIazrORjI3VxRSk6uRMVu9aJN1o0gMzzuBybHjl9tK/drf5/kT3Vlhkm/K3lGa8FOQYM UbM6BylS160Y9I+AaS+tC3HoKzloremjUtGLI1skkqy2QkrmpEDgvm52fXpsWHS4TjIo32ye7 D3FHopoz8hDNHtsxlVZZtXzh7dsL1IcrFCy1YbvDtjA7GIWTzgvzcwGjK4pRJa6/GGUpPOWVR qYcvATN1I5/EJqy6/mXbL/k6JVFHNiHvPOhEeHRO1w== Received-SPF: none client-ip=212.227.126.130; 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Weißschuh The correct error number for unknown ioctls is ENOTTY. ENOSYS would mean that the ioctl() syscall itself is not implemented, which is very improbable and unexpected for userspace. ENOTTY means "Inappropriate ioctl for device". This is what the kernel returns on unknown ioctls, what qemu is trying to express and what userspace is prepared to handle. Signed-off-by: Thomas Weißschuh Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230426070659.80649-1-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 085ce530213e..954ed14df4c0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5747,7 +5747,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) if (ie->target_cmd == 0) { qemu_log_mask( LOG_UNIMP, "Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); - return -TARGET_ENOSYS; + return -TARGET_ENOTTY; } if (ie->target_cmd == cmd) break; @@ -5759,7 +5759,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) } else if (!ie->host_cmd) { /* Some architectures define BSD ioctls in their headers that are not implemented in Linux. */ - return -TARGET_ENOSYS; + return -TARGET_ENOTTY; } switch(arg_type[0]) { @@ -5817,7 +5817,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) qemu_log_mask(LOG_UNIMP, "Unsupported ioctl type: cmd=0x%04lx type=%d\n", (long)cmd, arg_type[0]); - ret = -TARGET_ENOSYS; + ret = -TARGET_ENOTTY; break; } return ret; From patchwork Tue May 16 12:48:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243110 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 EDA80C7EE25 for ; Tue, 16 May 2023 12:49:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6H-0004Kp-VY; Tue, 16 May 2023 08:48:21 -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 1pyu6G-0004J7-5n for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:20 -0400 Received: from mout.kundenserver.de ([212.227.126.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyu6C-000637-Sk for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:19 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N79Ey-1qFPpB3OBA-017W6u; Tue, 16 May 2023 14:48:13 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 3/9] linux-user: Add move_mount() syscall Date: Tue, 16 May 2023 14:48:04 +0200 Message-Id: <20230516124810.90494-4-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:NYdTDmcMxR00TOQabDtINyPvPAp04l/8GQs9/OP9Cc30x0ZJsqg 9ysaoFeHikz55sEUSYKcBN1DCOHXPWans/s+41Q9QnmZb5Fom+CcRG5xKMeE0H/Fd+8ItEY MHYnx354Fq45DFtSQV/QvUG5UdTMUaC7hZaOuJ7qkCU8AX2ox54J6npZOaf4ed4hmu2QmLZ YNV38SaiZQ4BfImef5Asg== UI-OutboundReport: notjunk:1;M01:P0:ZmfdnubxP9k=;GNZOM4TNpp9pOcUKERTDSzd5nn4 Pwq03I6a/D1DWiff1ORjewaNss1WoaEfTdn4wNb450hq1LweycJFUEv0dzyX0HBZwJ5KocRSF Hnov8wc1paPJHBc/ypOqD/q4pPSo/M+6yccYKKJiISuq5h89xDyhn59nQEYi/jzyW83dq4sxx AC8HpQt0vQHtCt3xqdmRz+ix3WmZE0MQO6Nuy1HOYjcHOveaV0iyks+tGnHqN8zGrpF2/3od0 QmFipgucweIWg6aPPd6pDKOzdn8c93+CzLwcGRPDlxq6kQRc5w6c0I1UQ8tCFSqdtlCfbI6im H+FXfhPOyHSfolH1JKSEdWa51xj1m6yTs0/yk1se0Lfly4YwoRnBccQi/PNjNHNcGxghq+631 Q2/kvUeD01egsb2YKRtZ6/odzlWvFAukB8GuFiNrOG0qri/56d8+w7TbC/EuWv2s/KYFmcDOH 1yOMUK5pIe8syjeVoP6u0ELzpdqj1hmJMaAf+zUlQm2GKE1Br3LFi5snRPjksYvFqzoYv9fBE LZZa5hr3gY0d0vs2Ntt6P5K3mwy6WALSJxevVdGcdB7I8amOj+yPhrUvUUJ9GALEWAh4MZkwU ScZbk8X49f0+ZB2mDneEzMbHA0aUQBDfHKR4SM5swT6alm+iCGjHFHyRsfE5AT6yLC78URfh1 0ko+B9Nph2EIIRwpmllypMBZEfBhi7O3h/Z5ge7BPg== Received-SPF: none client-ip=212.227.126.130; 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Weißschuh Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier [lv: define syscall] Message-Id: <20230424153429.276788-1-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 954ed14df4c0..9a99e4557367 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8776,6 +8776,12 @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) _syscall2(int, pivot_root, const char *, new_root, const char *, put_old) #endif +#if defined(TARGET_NR_move_mount) && defined(__NR_move_mount) +#define __NR_sys_move_mount __NR_move_mount +_syscall5(int, sys_move_mount, int, __from_dfd, const char *, __from_pathname, + int, __to_dfd, const char *, __to_pathname, unsigned int, flag) +#endif + /* This is an internal helper for do_syscall so that it is easier * to have a single return point, so that actions, such as logging * of syscall results, can be performed. @@ -9169,6 +9175,33 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, unlock_user(p, arg1, 0); return ret; #endif +#if defined(TARGET_NR_move_mount) && defined(__NR_move_mount) + case TARGET_NR_move_mount: + { + void *p2, *p4; + + if (!arg2 || !arg4) { + return -TARGET_EFAULT; + } + + p2 = lock_user_string(arg2); + if (!p2) { + return -TARGET_EFAULT; + } + + p4 = lock_user_string(arg4); + if (!p4) { + unlock_user(p2, arg2, 0); + return -TARGET_EFAULT; + } + ret = get_errno(sys_move_mount(arg1, p2, arg3, p4, arg5)); + + unlock_user(p2, arg2, 0); + unlock_user(p4, arg4, 0); + + return ret; + } +#endif #ifdef TARGET_NR_stime /* not on alpha */ case TARGET_NR_stime: { From patchwork Tue May 16 12:48:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243105 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 9E87EC77B7A for ; Tue, 16 May 2023 12:48:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6J-0004Lp-0k; Tue, 16 May 2023 08:48:23 -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 1pyu6G-0004J6-5H for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:20 -0400 Received: from mout.kundenserver.de ([212.227.126.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyu6C-000639-To for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:19 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N4vFE-1q8qFO0tT2-010vTY; Tue, 16 May 2023 14:48:14 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 4/9] linux-user: Add open_tree() syscall Date: Tue, 16 May 2023 14:48:05 +0200 Message-Id: <20230516124810.90494-5-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:yrFHViysuoukes5YHDi9LbE5vvNH/XF2b4wFuDLm4mhSoNfn4Tv Lf7DV8hj387zyIvHx80Dfb1p8oWSHQvPIKQR5/85NtgVoJogRoIOXTrE7ZeNp+k6jr1KqYF xdIOio5r+337OqpjFEJtWJg4K/oU75T6uMaSqGTIb4RHsboUwBPteM1bBSdB6w0RC7xrK11 GK59nKvU9mz1kLXlYgUVA== UI-OutboundReport: notjunk:1;M01:P0:ZTPCWqekgTg=;QDk23tZart92XMSC5XdNe5bXo64 c82vCopVxUy7VJlb6Cop+s9PRB3RvVNcRABUiSBCSggwy8iQmqIGQdhbjP3v35Dw6xtImy7D/ BEJ5ft5sq1Fu3EdN+59KWXgR/ES71uPpaQbEIrH5whYFbMTl4vX60R6dSDHPJbWNxLhI4Y4nq xhptFFEvyUDtSTl3QcceSWZNOSLdMgBuDKcKffcdogVCSOPxonTHlig1oMz06iimQE8elP5Xs VfFeD5aRodDdFMNWaqy6ajgccYnBHjb4dQOklzC8zK65J6zCCfuEAqh6YJ0tUVO2CIWGNhM23 63J9F74VzKJmpfeamGz4lWbH+OfGcYc63xFvdf2wV4fa4q6MVxSqWC81hq23e9OUxDENroVkA nQf+7yUXRR+RLB7D0g9QR8ofeK5T38Ufojb6zqLQs8yOTk39dU5tlOTOjdu7kCOki9k1aMjLE ed17ZzSBnGvgmIRN3LU+KT1/iJs9DEKvXhyNqLjMF11Xa/bgnYgbaFAwUVvEcJgKB4qGTyrA7 JvZ51zI0Wj+U9mp2C+9Gc8Yr1YNYCWKp/8G15ZKDlaEwA6c4OSwaOOUohYA4Zvjh+rIUweYwA GaTKch6o2c5GQY75DZjJKKeMqXQSdRt21w1lJEy+A53FA9G9PAX7y4LR6ZPSEf3QvsNhtxGfq ERCV8z8nWkbE+z6PZL2ICKdqda5K4QbFw5wh/HOvfg== Received-SPF: none client-ip=212.227.126.130; 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Weißschuh Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier Message-Id: <20230424153429.276788-2-thomas@t-8ch.de> [lv: move declaration at the beginning of the block, define syscall] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9a99e4557367..00a779797efb 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8776,6 +8776,12 @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) _syscall2(int, pivot_root, const char *, new_root, const char *, put_old) #endif +#if defined(TARGET_NR_open_tree) && defined(__NR_open_tree) +#define __NR_sys_open_tree __NR_open_tree +_syscall3(int, sys_open_tree, int, __dfd, const char *, __filename, + unsigned int, __flags) +#endif + #if defined(TARGET_NR_move_mount) && defined(__NR_move_mount) #define __NR_sys_move_mount __NR_move_mount _syscall5(int, sys_move_mount, int, __from_dfd, const char *, __from_pathname, @@ -9202,6 +9208,33 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, return ret; } #endif +#if defined(TARGET_NR_open_tree) && defined(__NR_open_tree) + case TARGET_NR_open_tree: + { + void *p2; + int host_flags; + + if (!arg2) { + return -TARGET_EFAULT; + } + + p2 = lock_user_string(arg2); + if (!p2) { + return -TARGET_EFAULT; + } + + host_flags = arg3 & ~TARGET_O_CLOEXEC; + if (arg3 & TARGET_O_CLOEXEC) { + host_flags |= O_CLOEXEC; + } + + ret = get_errno(sys_open_tree(arg1, p2, host_flags)); + + unlock_user(p2, arg2, 0); + + return ret; + } +#endif #ifdef TARGET_NR_stime /* not on alpha */ case TARGET_NR_stime: { From patchwork Tue May 16 12:48:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243112 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 E961DC77B7A for ; Tue, 16 May 2023 12:49:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6K-0004TR-S8; Tue, 16 May 2023 08:48:24 -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 1pyu6I-0004LJ-CC for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:22 -0400 Received: from mout.kundenserver.de ([212.227.126.135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyu6G-00063u-GB for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:22 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mdf3x-1qXxjb342D-00ZfC5; Tue, 16 May 2023 14:48:14 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Thomas Huth , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Laurent Vivier Subject: [PULL 5/9] linux-user/main: Use list_cpus() instead of cpu_list() Date: Tue, 16 May 2023 14:48:06 +0200 Message-Id: <20230516124810.90494-6-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:oPBDiUyh/dXjYMGyATPj7Fk/g2VeGSfktkQFIloMdH8Po+PViqf OCM0rm89dM62xlvlx+C3t1Rajy+bFq+NgMEjjyWbRE8AryFHh/01A1K6KZkNjn3gtiVybFb th34r1tlLo/LD0R+xuvZEebyyQ1q6WOpjd9q8MPUVIGSb6OIt5jkAtUajWHl2+sQIaQRUHm 7Jzea8f82xu6Gu/8luzgg== UI-OutboundReport: notjunk:1;M01:P0:R69Mj1iWK90=;rJwe7ScUWbmHlnOE22aX50oKi3c k+8AIFvBLXh+XqxGTtiHSmeWZtLYduNdYfsR+pGtw3jvwkQSe5FYR3hiXcRXIPC+odTYVJ61+ BVVXPROMzBNX1PQ99ihv0lWxCtdchaqm6OQgBZe3kcXsdFlzGDdbwx/7EeMztTWKaMEvgXXAN GeNKrsq7S7/QQlCNy1eRUZ3Cz3i1JsiE5yhI3/qwmK21bM6sQ0KRPfKZLR7x4jNEyp5n73NPp 0/LbRTvIHezXL7FcrTohKlIkmMm8I4BfU6Ebjkzmi5eo5KcOCSj3Mw4KWIq4n4sL/Zv4RQDgZ ru0SYwSxu8xCNa9JNI02mLJ8/MetvX5Qd18ZegUsPpQhZV+xC+lvFequnsBxeofSPOtaNkYNL MnEo22GtADB52ktTfC73B9VkoIWbz7YQYP5VdrJhsI4io27Pj5vOMlLpPua5EGP6eQ/GbgFJo q8cCGFTXtQBRZuVUT/kvFfJBrm+QU9k8Gslo0xmOYaSrLo+HLmeOlexb2Ain8lmQw8rZ/0/y9 ZYIqJy6XfgT4AoMK6vEiWJC6VdKEgBMedNPtuArSPWN+wPDhEY6Kgt84Lf1lViLzdhnc10fx6 E35scS1sOwRuBHei5dZ9h3c/zdElBl5b+w3vQb+zLONvxM+MBa/yuxjRPk6mMwlnp1y1+aMqb l9Idej3AR/pFToM89AM7vC9Zo1/ZUvuzKmCR+yWs8A== Received-SPF: none client-ip=212.227.126.135; 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Huth This way we can get rid of the if'deffery and the XXX comment here (it's repeated in the list_cpus() function anyway). Signed-off-by: Thomas Huth Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230424122126.236586-1-thuth@redhat.com> Signed-off-by: Laurent Vivier --- linux-user/main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index fe03293516a5..aece4d9e9119 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -359,10 +359,7 @@ static void handle_arg_cpu(const char *arg) { cpu_model = strdup(arg); if (cpu_model == NULL || is_help_option(cpu_model)) { - /* XXX: implement xxx_cpu_list for targets that still miss it */ -#if defined(cpu_list) - cpu_list(); -#endif + list_cpus(); exit(EXIT_FAILURE); } } From patchwork Tue May 16 12:48:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243114 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 E62FBC77B7A for ; Tue, 16 May 2023 12:49:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6I-0004Lg-NP; Tue, 16 May 2023 08:48:22 -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 1pyu6G-0004JC-8L for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:20 -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 1pyu6D-00063E-I7 for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:19 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MNfgZ-1pmyxA0eRn-00P8Pz; Tue, 16 May 2023 14:48:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 6/9] linux-user: Add new flag VERIFY_NONE Date: Tue, 16 May 2023 14:48:07 +0200 Message-Id: <20230516124810.90494-7-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:SPkbVstJZDvesHceEMJLQg5s0j3O+V3rLtfzIVRJPPVrVScuQ5y hCTIDAbz0ThjSvN9fen8ku6BR/qyeiqjVmvKY1/srczw9T3GFYgjAwFn/8XjJNupIuOFAUx iO6hrLkoiHw4Okp4x33WShG2FMsMs3Bc+PPf3JCopXsAjkAHJNTYyay1B5xpHJ6MxNSeYLM KqmcvN+gBIp7mHBVJCw7A== UI-OutboundReport: notjunk:1;M01:P0:Hntt3cMpydw=;jtiyvER8NGXjqQ3PiWCQ9zEFRQH kPm5Cs1bI+NqErn4jG+AfWAQaWVROwsQIOGDpsykWjWrhJ5aviByRZP49v408aPsw9XEsXcrD miJeIYnc3MTsY9URXTA/U3GYnqCKY6phR9/8lHlstOavrbAONPHnlf97rZAuavvL1TDjEM7u/ rd2Hyg9g2o9o87V1fpszrQGi55k+NNbRVd3Ptc6KQ0KdnNZTuP6+R9GHArV2f61dOz5AjpFMM sVcOfNzFVZx15cDz//BzXrSrs3mIKvDNhddnh9mapP/1pGOagueAazWmsEH/4yKRj/GLqDzVh arbKWs9AzD2vyoF8BaGAK22AqwtZIFSD03xpWrncNfXqwJIcKX6zT2iASAMi5D7wVH/BibFGo 2zJloLf251eo4KHf1L4SkM9U7mx8wTfqmOfqVylbTYyFVMvXoQFS6I728BKjNVcWl77c97WsB kM85jdPf1jz1u90/q/54Zu81ReEQWHDa1tpR0MXID2ZAamAQl37iOzn7TzbQI62xFLeaLh6Ws 9kTy0AC4DSD0l/QPgZkO030hJED8ZByQnzsUfrGER76B4CBWnlTFj96kRY+5vSzDn9SvD4cbV //2lPytGh4IJUx7YeRlcR8NtyYXJRUgJIpQvcx7xaZ6c/k7+6tgp5Yt0R/ONixS5T2PtOp5BU x6Otg0wSCF6Vl8C1scb1FDE2KywHjdB0onNw9k7ShQ== 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, 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Weißschuh This can be used to validate that an address range is mapped but without being readable or writable. It will be used by an updated implementation of mincore(). Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier Message-Id: <20230422100314.1650-2-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/qemu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index e2e93fbd1d5d..92f9f5af41c7 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -168,6 +168,7 @@ abi_long do_brk(abi_ulong new_brk); /* user access */ +#define VERIFY_NONE 0 #define VERIFY_READ PAGE_READ #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) From patchwork Tue May 16 12:48:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243115 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 5EB67C77B7A for ; Tue, 16 May 2023 12:50:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6K-0004Sx-MO; Tue, 16 May 2023 08:48:24 -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 1pyu6G-0004KK-SS for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:20 -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 1pyu6E-00063X-7t for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:20 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MRVy9-1pmRn02J4X-00NTzh; Tue, 16 May 2023 14:48:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 7/9] linux-user: Don't require PROT_READ for mincore Date: Tue, 16 May 2023 14:48:08 +0200 Message-Id: <20230516124810.90494-8-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:a0zkQxmXJBtx1G5t1mQ3oRg22b9CQ4/yxg0gcRFZzW4B5IEiZkr D2r1viVyfNtiA7jI0xrFdlzG8qyXBcn2H+co7mQV28TUdgEOv9q5lA8RFtApmLPOGlTS6wb GhFQx8Qlxni8BB27TJ2NdCvycHSRHffLu1WtddEh/3a+AYZTUnFpDPcWm1XaSK0z3S+Hyiy 1OG3cMso0rsjDehmoO+GQ== UI-OutboundReport: notjunk:1;M01:P0:A7uomkmtvSA=;dvxBXvojbEZY7GoroeXvRZBXROD mLXsOOxk8y4/i+vkirpLl5TJG8rEjg4qDad8zxwhoZ3rk+bVBdFE2m3kG3aaBCbs3wK5ymwQ/ HJmExzHu8Y2yQ6v52YyDYGAzcclutNFiNrq2yY8c+0IjB7Wqo+HFRJeUyvISi5KN2UnP3vKQ7 x/rcaRHaS5Ntqi5O8n/sTOYnu5JjVdnr8YtmB2e9M049sIzIuD5C0jdPGqDMXowzFVBoZomnS Ogof+3nAGe+g0lFnJLJAvE+PxsIYH9i5sD0JtaUqC9HgdURD439vCGlcWQI5JlJ+1jiNZ8kDs nW9q1db+aHFz0KCYMDVt4jXhCXXpco4JjlMZtoLmzVIGve1Tij2kn/DrmmSUc/8jiSP0FsCaE /xaoQ6B2D0iW2v0dw/RjZCOBQbnnqwYwk3gIiKaAcgCKz51u1xGWdgf3E+DcLaaV8ooFZQi3s lxoIAZMevCUo27wpnv9tXKDOEP3E0/FW0lB3g8QluAhFWmVoiBKTbbqFAuJ5q3c/uB18GsufK s9FUZoSUFBzrMMrpJhngZcrIY0OkKsabjw6swTn6ahuqjAM0SjZyk5LFyjqIsBGHbrFyxbz2d a75FunZrHXKq1XNqKp3YKx4992b1Y2TtBi+AL/3WNAqbfwD2tl80KH3pi5YKIrvAdR5DrxZTV iSve0acLr1MTej0oXKDGnHnPJehVdQqSqQeW42d1wA== 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, 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Thomas Weißschuh The kernel does not require PROT_READ for addresses passed to mincore. For example the fincore(1) tool from util-linux uses PROT_NONE and currently does not work under qemu-user. Example (with fincore(1) from util-linux 2.38): $ fincore /proc/self/exe RES PAGES SIZE FILE 24K 6 22.1K /proc/self/exe $ qemu-x86_64 /usr/bin/fincore /proc/self/exe fincore: failed to do mincore: /proc/self/exe: Cannot allocate memory With this patch: $ ./build/qemu-x86_64 /usr/bin/fincore /proc/self/exe RES PAGES SIZE FILE 24K 6 22.1K /proc/self/exe Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier Message-Id: <20230422100314.1650-3-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 00a779797efb..6655982821ba 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11993,7 +11993,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #ifdef TARGET_NR_mincore case TARGET_NR_mincore: { - void *a = lock_user(VERIFY_READ, arg1, arg2, 0); + void *a = lock_user(VERIFY_NONE, arg1, arg2, 0); if (!a) { return -TARGET_ENOMEM; } From patchwork Tue May 16 12:48:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243107 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 ACBF2C77B75 for ; Tue, 16 May 2023 12:49:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6K-0004T8-Nh; Tue, 16 May 2023 08:48:24 -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 1pyu6J-0004M0-AY for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:23 -0400 Received: from mout.kundenserver.de ([212.227.126.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyu6H-00065g-Jq for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:23 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MjgfT-1qQlg30Bxr-00lBVT; Tue, 16 May 2023 14:48:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Daniil Kovalev , Jiaxun Yang , Laurent Vivier Subject: [PULL 8/9] linux-user: Fix mips fp64 executables loading Date: Tue, 16 May 2023 14:48:09 +0200 Message-Id: <20230516124810.90494-9-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:AYTWf1Mam0ZVYtNa5m1XT7zLsRBfphs3HPQ/TrTWuJmO8PDzCb2 VL+deoivVtOubs+lBBFpOtiYZU6QbsROkK5UWfH/SsNny0+8KvNUhQ1ex1UFuqqNq8sLgPK 38BqVHPC7ArLYYMBlMY9Q15T6K9CjUMuPubJYkougIOawZw00QQ+dgWde8kA+4OE2WvyMBd PTir/OfwJt7e4Xvs60mYw== UI-OutboundReport: notjunk:1;M01:P0:3v2DLZyhhTg=;+8CoK5DTa67TNVOGd+smONANjP9 7BiKXwhxdkE8Xlt68JAcPLq2YUpXNhnP4QVWQ2sDHEwW0BLJhmAzD4JBHclaKqmFOae3hm2ex Wp67A6dnrzQTUmimGk+EQo3ObWWxEzxzrSXqtyeuFGrqwlngyQddESJ18OlTWyAKlhHdyud0i Wi0O9/ncKGAA17kGsv8ejZFTAqZTl0pcQP1WVHXjWmPlpfc5ttS9dOSWiA6j8leMhVRtDMsOo 7peZZM+2ISFT6tFuCUMIEZvqjhBJNNAx31XeeDOTEl81hQABs5gzmVqBrUx0SzfFUNSXBbHWm gsTbF43hc5pF4APOk4znrJVhF6oQhh2gcvGlpBHAnvV55WJOYHDMXhJJVKvJLOo3FLFrVaiPZ MnO7qahoTIT5g4yX7ViKq2lbEkyALBCrAMOqUjpOQJez/hQ8r5lKNl8JhJaiSjMBPo6qbREFB JAR/dB20lOJmFXxKlhoAhvT4OWGOrrvk2iY59AxxkTwgSg1HiZV+n8+FcAgJ24yuMPHscd1ro RNkcw+IqQIqP6lbmx648ofjsE1fXKTRULLxTzSeLW5vvHzzrJ0NJqk4HABzq7hA4GeKaEuVjt WdGGeHS2oQz9kHlkholPY9pTUktSbCUIHgM9SHfmHlgo4lHVlulgwx8k901jjxMF62n+/4QmN A8v2KWY9DE3Af79waKKIq96FcZI9kNFoHOLw5lK34g== Received-SPF: none client-ip=212.227.126.130; 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Daniil Kovalev If a program requires fr1, we should set the FR bit of CP0 control status register and add F64 hardware flag. The corresponding `else if` branch statement is copied from the linux kernel sources (see `arch_check_elf` function in linux/arch/mips/kernel/elf.c). Signed-off-by: Daniil Kovalev Reviewed-by: Jiaxun Yang Message-Id: <20230404052153.16617-1-dkovalev@compiler-toolchain-for.me> Signed-off-by: Laurent Vivier --- linux-user/mips/cpu_loop.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c index d5c1c7941d34..8735e58bada0 100644 --- a/linux-user/mips/cpu_loop.c +++ b/linux-user/mips/cpu_loop.c @@ -290,7 +290,10 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) env->CP0_Status |= (1 << CP0St_FR); env->hflags |= MIPS_HFLAG_F64; } - } else if (!prog_req.fre && !prog_req.frdefault && + } else if (prog_req.fr1) { + env->CP0_Status |= (1 << CP0St_FR); + env->hflags |= MIPS_HFLAG_F64; + } else if (!prog_req.fre && !prog_req.frdefault && !prog_req.fr1 && !prog_req.single && !prog_req.soft) { fprintf(stderr, "qemu: Can't find a matching FPU mode\n"); exit(1); From patchwork Tue May 16 12:48:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13243106 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 53CFEC77B7A for ; Tue, 16 May 2023 12:48:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyu6P-0004Wv-Bl; Tue, 16 May 2023 08:48:29 -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 1pyu6I-0004Lf-LX for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:22 -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 1pyu6G-000642-Em for qemu-devel@nongnu.org; Tue, 16 May 2023 08:48:22 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MgRYd-1qf5Xb45i3-00huFz; Tue, 16 May 2023 14:48:17 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Michael Tokarev , Laurent Vivier Subject: [PULL 9/9] linux-user: fix getgroups/setgroups allocations Date: Tue, 16 May 2023 14:48:10 +0200 Message-Id: <20230516124810.90494-10-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516124810.90494-1-laurent@vivier.eu> References: <20230516124810.90494-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:5Zygrv6rWhCg3J2U14YDD8h7qAnZsq0QyWLefgd8vzJ9Pg5Cqjr cLcwqSkD7pvLaowpGP+wgGyfZp4V+hr35NLtZrdIcem7FAl7WwgQFou5mrHMrO/yaWHCiTs OOH1OyXBJ2U546p8zd4Xp3Q8cNvgK432/ORMcDJ8LzmrukI1DZU7ygpJryJN27e3QHPR8oW KIJunab3+SOLiIxNMSOsQ== UI-OutboundReport: notjunk:1;M01:P0:aptMhHn8iaw=;jsQr4PghBL9U1S6kkpFcmqv6DW8 auljEynbUBdZubX1ksPLtw2pZbWzCp20j4tzvkt8Z02UnqS3hzziHSd5Fu8ctTrCrZjcOZ7pw cgXY6rviJMZlC4z12/RxeoFaDFrMr8Y9FZfj2TQbAq9KzlhVWdoJlt5bemEXAUtKyRK5mjNoL OcykNTk8ScBx3GEhRATeHRqK3H9MJ8kHh3wSBNytCTcGZXhBXuA/lw3g0XeV0PeF1Tqv7SFea KCeePa0rZCIE8NKoqgSMr6EO8gIrAWWrUtJEkdZMVYsHpDd25RHUWUmftRK5NjnuBB1OR6fDJ rdq6pIVxHTjQdjp9AyZwJ+hB5x/p6Q+kWtTFoO+FIuaNQmUhkKwzlzzA21/P+95DOrlafiYNv LHkXGi0kUKPlbdEs7QTSJGIjvCQDtQIbOfzcgA8W4gzHBUG4/20XjqU0jv7suNMmJx3r6uj0o 1joQDkEVxlebjEZziCn8cVQDgDYA/XQh87cZBw/oyUv/QvKO/SlXM3qeN2lQ3MjN0KZSBWsAM wOizdn+U3rnMEWMYJOFI+wG3KXgNcOZJKZUS0jPiqSLVCmb0O3XCSFXgmKnLUZdDI216MQV55 3EjYNWC9bALvwIYmOA8+iIhN6MpNib8Pgx44E5lUCYGacjFnfge6Fmq/2sGnVX9VSDOvVkMSj IaSCP1s8lYG00Uv7uEZ80r+zKFjX9cD74pP0nFu8nw== 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, 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Michael Tokarev linux-user getgroups(), setgroups(), getgroups32() and setgroups32() used alloca() to allocate grouplist arrays, with unchecked gidsetsize coming from the "guest". With NGROUPS_MAX being 65536 (linux, and it is common for an application to allocate NGROUPS_MAX for getgroups()), this means a typical allocation is half the megabyte on the stack. Which just overflows stack, which leads to immediate SIGSEGV in actual system getgroups() implementation. An example of such issue is aptitude, eg https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=811087#72 Cap gidsetsize to NGROUPS_MAX (return EINVAL if it is larger than that), and use heap allocation for grouplist instead of alloca(). While at it, fix coding style and make all 4 implementations identical. Try to not impose random limits - for example, allow gidsetsize to be negative for getgroups() - just do not allocate negative-sized grouplist in this case but still do actual getgroups() call. But do not allow negative gidsetsize for setgroups() since its argument is unsigned. Capping by NGROUPS_MAX seems a bit arbitrary, - we can do more, it is not an error if set size will be NGROUPS_MAX+1. But we should not allow integer overflow for the array being allocated. Maybe it is enough to just call g_try_new() and return ENOMEM if it fails. Maybe there's also no need to convert setgroups() since this one is usually smaller and known beforehand (KERN_NGROUPS_MAX is actually 63, - this is apparently a kernel-imposed limit for runtime group set). The patch fixes aptitude segfault mentioned above. Signed-off-by: Michael Tokarev Message-Id: <20230409105327.1273372-1-mjt@msgid.tls.msk.ru> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 99 ++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 31 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 6655982821ba..89b58b386b17 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11571,39 +11571,58 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; target_id *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = NULL; int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); + if (gidsetsize > NGROUPS_MAX) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + } ret = get_errno(getgroups(gidsetsize, grouplist)); - if (gidsetsize == 0) - return ret; - if (!is_error(ret)) { - target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0); - if (!target_grouplist) + if (!is_error(ret) && gidsetsize > 0) { + target_grouplist = lock_user(VERIFY_WRITE, arg2, + gidsetsize * sizeof(target_id), 0); + if (!target_grouplist) { return -TARGET_EFAULT; - for(i = 0;i < ret; i++) + } + for (i = 0; i < ret; i++) { target_grouplist[i] = tswapid(high2lowgid(grouplist[i])); - unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id)); + } + unlock_user(target_grouplist, arg2, + gidsetsize * sizeof(target_id)); } + return ret; } - return ret; case TARGET_NR_setgroups: { int gidsetsize = arg1; target_id *target_grouplist; - gid_t *grouplist = NULL; + g_autofree gid_t *grouplist = NULL; int i; - if (gidsetsize) { - grouplist = alloca(gidsetsize * sizeof(gid_t)); - target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1); + + if (gidsetsize > NGROUPS_MAX || gidsetsize < 0) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + target_grouplist = lock_user(VERIFY_READ, arg2, + gidsetsize * sizeof(target_id), 1); if (!target_grouplist) { return -TARGET_EFAULT; } for (i = 0; i < gidsetsize; i++) { grouplist[i] = low2highgid(tswapid(target_grouplist[i])); } - unlock_user(target_grouplist, arg2, 0); + unlock_user(target_grouplist, arg2, + gidsetsize * sizeof(target_id)); } return get_errno(setgroups(gidsetsize, grouplist)); } @@ -11888,41 +11907,59 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; uint32_t *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = NULL; int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); + if (gidsetsize > NGROUPS_MAX) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + } ret = get_errno(getgroups(gidsetsize, grouplist)); - if (gidsetsize == 0) - return ret; - if (!is_error(ret)) { - target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0); + if (!is_error(ret) && gidsetsize > 0) { + target_grouplist = lock_user(VERIFY_WRITE, arg2, + gidsetsize * 4, 0); if (!target_grouplist) { return -TARGET_EFAULT; } - for(i = 0;i < ret; i++) + for (i = 0; i < ret; i++) { target_grouplist[i] = tswap32(grouplist[i]); + } unlock_user(target_grouplist, arg2, gidsetsize * 4); } + return ret; } - return ret; #endif #ifdef TARGET_NR_setgroups32 case TARGET_NR_setgroups32: { int gidsetsize = arg1; uint32_t *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = NULL; int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); - target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1); - if (!target_grouplist) { - return -TARGET_EFAULT; + if (gidsetsize > NGROUPS_MAX || gidsetsize < 0) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + target_grouplist = lock_user(VERIFY_READ, arg2, + gidsetsize * 4, 1); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i = 0; i < gidsetsize; i++) { + grouplist[i] = tswap32(target_grouplist[i]); + } + unlock_user(target_grouplist, arg2, 0); } - for(i = 0;i < gidsetsize; i++) - grouplist[i] = tswap32(target_grouplist[i]); - unlock_user(target_grouplist, arg2, 0); return get_errno(setgroups(gidsetsize, grouplist)); } #endif