From patchwork Mon May 15 08:31:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13240952 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 69361C7EE22 for ; Mon, 15 May 2023 08:33:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTcK-0003js-Mf; Mon, 15 May 2023 04:31: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 1pyTc8-0003i7-So for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:28 -0400 Received: from mout.kundenserver.de ([217.72.192.74]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc6-00026I-KU for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:28 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M89TB-1q3AZT1nt5-005E0P; Mon, 15 May 2023 10:31:16 +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: Mon, 15 May 2023 10:31:05 +0200 Message-Id: <20230515083113.107056-2-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:sU3SOdmH/sdx4ey19Ro9tVNQl5EVwbPcfPyqyj3fcDDqQlQgg1W l1hukMIPgsIJ9OHQVD42CCYEMUkjVCNZFemiPkPKtwCunIEVVtoYcDbBWYZmy4b2+S9Jtq5 OFa78mnQ1sD0mM3ABjRrD0k16eQwVlKDC/mwVmvknvQ48LKIS3XGzaRQNPreUp7UoZUJtPb tcK5ph1Dl+TxPgKbN6Feg== UI-OutboundReport: notjunk:1;M01:P0:NhJkQ1Qlk7g=;rWNYR1yNGid9WIw32rpUbLI70T5 o5OP25PyNBmlbnnEIG9qY4fFlew1tdMVHuI9t9JM0WXWNxGnpj41shz7iZPvic/tgGY3Am05n LNc68yuMunmUUZzV9aRm2zjLgOwSB7fpA3//KFeoBhg0m4f0RWniltSajwa40V0Qbq9Qqu23K IN3tp2d/qRxSNW3DQ6wA1xV5N0YVsXNLMA36KdDb/Mqm5sXCPGsLn2otC5FP4+3G2wHnmX+5R tvVtu3hwkRzMhUtVMIfButK6IDIOBW2aCCQ4+3l8Tfztx4Flk+F5Fe7BaODF9RRYwMyER9Dn3 YsKM/NQun89WUiMp/3xA8pso4LnHIEbeRP8VIZe88y2moreg0QxNPjgi8EadMDrQrUmgDgJab 8ukuwpiXY0bAIqnsvl/93HRTDlX9OcJpNXkMdxlqdKj4Syx/I1CCmcKAAvNSqbEJ9YBzVI3jv nqtkLNFL5g7E15bIqx3sonxbhh3eIDs6R0Kl9l4wngW7hKwHKWgogVdgZnCwQ2A4sgvEtmvQ4 suHdbp4MXo3STKRgjfbQTuxkg2ehTo/vFdKLxSnIFkSTQ4AmEStt5ZX7rWSj9eR4lbg+Qsd0h 0X5qSbv3WEjjvmfiSGc4EhDhl1SiqQseISWdUfbrbbQlJ4L320hZG/T6hwYlgtmaNKE9TW28b p5f8SN88Ub1gdSAVwblv7P/ZgBpFRJHrjXBF6x1Y1Q== Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-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 | 30 +++++++++++++++++++++++++++ 3 files changed, 63 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..296abd0a8cf9 --- /dev/null +++ b/tests/tcg/riscv64/cpuinfo.c @@ -0,0 +1,30 @@ +#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); + } + } + + fclose(fp); + return 0; +} From patchwork Mon May 15 08:31: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: 13240945 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 6BA44C77B7D for ; Mon, 15 May 2023 08:32:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTc9-0003hl-14; Mon, 15 May 2023 04:31: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 1pyTc2-0003go-Lo for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:22 -0400 Received: from mout.kundenserver.de ([212.227.17.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc0-00022P-Ud for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:22 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MZl1l-1pdlP01VCR-00WpZ7; Mon, 15 May 2023 10:31:17 +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: Mon, 15 May 2023 10:31:06 +0200 Message-Id: <20230515083113.107056-3-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:LtgmVMo/BSUpEoACASLJAFnPCT6PkCC/8v4YG7dtY2VesgjS59Z kekhZm5/2JNCQlKi5xyYS6xkvbfLHJCN4tydwf1NQ51L4QOrT8P11VvYjv79894IYdeb7YS 1rUlsQdBpKvSlbyWBT3ZC8KHhxoLolMWd9MW1otIilOz3e/C137LY4x+2u/HzyZTzgPtIBp xTg6jEmbtX2BFz6cjmTlQ== UI-OutboundReport: notjunk:1;M01:P0:PuFugyMtHtc=;4tApUvxHICnmRBAuQlkAOHbbdHo EBtXwguu1Y+4vzxO5HbLojnujwN7iWNnFLf5NOkaADIhRqLdIDRESJOZODcVbTRvDyDrkUBbP JeaIATEUWcxBHZLd2CTdw2+NBb++ucv1IZ+NIXegYQg1HuodsUdnEY3wLd4AI/hteeBv5+FPd ZuecdiCAl4Ffv5Rjm5AIXF8auKkRQ9iVvynRTYqgfyjlLOZdRiwrY54tKLTRUmJDu16p9IWdB q3iU5og9Kxb5Dpnub69rfSYX5WJGditDpGdLt5wBTC9xm/QdsOTWoOhE4u4P7QXO3KJDfiyQS 3ufGgg8xYqzPYKW1H2x/9yevivWU7Su2kj3mNvdZB6gowNYfjpnjquprNCpkdZ3wmOrx7KTQt RylG6jDNclBy2fZ3jZkgot9qlel60b5xATsM0OHUQQirC6nVuAc8+/h31uF7qpOHHrP0jGxdJ XBy5seFBOIXe1uzk960r9C/gd3x1Xj3lDV9qlcATTnN3FFfiQAx8l1NyOjZKMZFWgbA+NTqtZ +gvoQ+PIZpbuH+jjepTNo1sEZJO9wMJOlDaSd1+jvwQ0Ou4nqQR56fYQjp6qbn4HAYPapeso+ SKQkQ1iH7DGiOJ5QJwpRACVXCZW0NaOS3q/yqO8gRWHz+fzx85hx+tnTWnAKFTk1VospmgBC7 Rw1FfbCOEzojDKLDYbFF8Wqs0MSEhnyRGyxhqad5oQ== Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_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 Mon May 15 08:31: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: 13240954 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 D9BA3C77B7D for ; Mon, 15 May 2023 08:34:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTc4-0003hU-BO; Mon, 15 May 2023 04:31: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 1pyTc2-0003gv-T8 for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:23 -0400 Received: from mout.kundenserver.de ([212.227.17.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc1-00022Q-AT for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:22 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MkHIV-1qQcN23zJp-00kfkx; Mon, 15 May 2023 10:31:18 +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: Mon, 15 May 2023 10:31:07 +0200 Message-Id: <20230515083113.107056-4-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:6sK2ic5cFtsRtJ1n8P8ASPepa91DdOuLM+KVGPuuZjZsj7dPruT lOIg9hTVHXf6UTvmdAE7aC+rAAM2tzpnwYTrXDTzC0ITPpCBksy+Ide0VBWcD0BiJjBiPNS 2cC5G/m8QIz2ev6jT6NCxF6K7hsLZ3jj8i80pCILn+qFd8vS1t5SCG7mNgw1eUq+IPsf35P xo1fzIndDDcIEJCj72UNg== UI-OutboundReport: notjunk:1;M01:P0:sDXTmsjrIvY=;+arb695rojfRhyqMHqRUD0yWWfC 1mcASJwr+080q8g1W4jiWVLHR6j9Viq5wbkr6EK36dHy/Nt/UOTmIZBEgMjvOUyXX3wj4zCCu PK/gwQKX0JKbPQIlV6vv8IJIsNa1m0N0dP4S0JG33X47JgeQ3jsNy/Cq8hUdrBtkPTkTWzkLC 9Tk8l5FqP0snN3xAc269Yogbkn3BsH0VsQTaYsOuRuS8HhaXTt2jJy3pgyPaqBbourM7Q7rfF lSlCmyFT+FEvx2omzloR0jvKCXMg/yLNx1m1Lx/q6hxZMmsjX68F7/ylJbCE/a81w5AhgSz5f 3gqfWfCfEAEZtZQ2dJpTaqKC5YT/5l0fqTFxSJb2yyTT6pj2W/F324cutpWGzUKQIp5NOp/FE E1TcZZBmhfL2Qebo9IDQHdmDivA5k8UjPOTbDewO8F2KXlQuvrdIlbpSFsgOrd0ITAnrQzy+k EjTE7zIyJtGl0MPx/3KUqaIll/3BgBfPzK0bFbCLFU4VqI+kea+TMmHG6aLjX8h96A6L7VxTh 8kyveTvxTn9VVcLSvXtKKMCHFdX6vLX2guWOvvqAEBa5gkwD4HEoymGFslAlxia9OE6i1KNQI Pi8mGG9QC8d58C0HYaxHPzyw7KL6s5Y9ysRuTt/r8AUKL6R+5cHcmojJzcqEPYcqFzwK+rbOB oRFZxQ4XIAkWXWS/nU8CNd9NfzG0oTHJZSZWwSlQdQ== Received-SPF: none client-ip=212.227.17.10; 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 Mon May 15 08:31: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: 13240951 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 49D7CC77B7D for ; Mon, 15 May 2023 08:33:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTcD-0003j8-Je; Mon, 15 May 2023 04:31: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 1pyTc3-0003hD-PY for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:23 -0400 Received: from mout.kundenserver.de ([212.227.17.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc1-00022h-BK for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:23 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N4i7l-1q8PGD2TId-011mfd; Mon, 15 May 2023 10:31:18 +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: Mon, 15 May 2023 10:31:08 +0200 Message-Id: <20230515083113.107056-5-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:HMWxUQMrN3TGnZXR2lb9FHGGuEygjbSs+QQzVrwNNdFK3MU7nPd DTA/IMnRlYLJ5b3szPZ730ZSH0enM8JsGzYs87HyNzj5HI8JH+TBHweqnwAvKWQM8t/wxo3 JvCyc6s235MZoC2+chJ4TgPrgrmeqbNw5a/c6F79u+DFM8WgsKE0ufi45iMW1CZ6j46S9T4 7iwisHF066OP6eIeQAuRg== UI-OutboundReport: notjunk:1;M01:P0:jctf2yDBmms=;JJDiEugPoxSFR5vbAn4fh0h02cJ kV+vnJWm1QhcNkqgJzvUnsGGtf6zxwzzuV46ExkYXcDjC2FnSuq72Vz0N3Q2KkiBnrLunzAMG 40iv/FzHxvBTQAxqRYWXuISWiZOB7Y92tf7VRA7U/zMzua4CfeC+eNZsToq0XPsKFzOI8ztc4 pW3AZ0RjIvk3BWs2XnRNYxIRqRvbIsBuyFJMXUZmcRo7p/JCYnsnIKTnrc8x4A/rkyemLbvZ1 gq+ASThOct9BoV+4A+oyN+iHmkfR6eoVuE0hS6ndWaC4Lamt2TdfLBuDwcgJLgSUBw2DI/Cb8 KLMftBaHnmUnR0GmAb5FCnlZEyd7Ot6aqIbiuYPIExnBN1LBlrQUvyRMhIcQDkPBJmBEns0KK Wz3wlL1WEEYXpmjQEXQnA4qytPDTVckZ09SsZxRk1tcSQ4U24eY3F7zVqLORKVFVXxCV7V5+c vGg+/7KPyJlJHCTNDz8fJzmvgI7BJqKDF42cG6IQzlikvSH7KN7dG6WNF7nZKdqieOhIcZaL7 StPruHWjMf4ojqHgx9W8ghiLwIL+bSzxnDwhzFqZEb9WUxwIotq38RS6NAZ4Bw4C38ZTMzBIr btbwjvPAACu9juwrLa5GFxEbqLFLdau9WCzIJpitBzGPSsQTbJLKJmPvB7giQe2Va/cC42g9/ jRMTWSL7ZhoSj+Hh2XF5Vf4+Yjx8NtNkYfJVkP0kXw== Received-SPF: none client-ip=212.227.17.24; 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 Mon May 15 08:31:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13240946 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 6DB90C7EE24 for ; Mon, 15 May 2023 08:32:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTd0-0004Ec-Py; Mon, 15 May 2023 04:32: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 1pyTc6-0003i2-2l for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:28 -0400 Received: from mout.kundenserver.de ([212.227.17.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc4-00024p-4U for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:25 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MF35K-1pwFd11y9Y-00FRXG; Mon, 15 May 2023 10:31:19 +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: Mon, 15 May 2023 10:31:09 +0200 Message-Id: <20230515083113.107056-6-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:5seb2bR3HmVylpNwNFNlpL8pQMCZZFvbQMl7NUujwjbdTpK6H7x jl0P6QTqrZiqaM6gHaAbZtf7vKbtu97fO/Zhum/Qf/Q0J/xEcrQiowGztGfG09WjfDh/doc O08Lc5i9Njry8vcFBQ/J8qfdaRkpNwbtoIB32ZimWNpeYLCPQtahQlvpPPpdNss1SVQVgjp pt2fwtAnA3cw55lGb3s5w== UI-OutboundReport: notjunk:1;M01:P0:XD+nFWB5Wcw=;fapg9rV/QaLPBJbODCRndZEYHXD TJ0mzjmZI8l4hr51SZikRGEr4MVnlKS+yr2/AiLhUWDafUx48QbW9u+4gv0yUVBCzJcI/S7RA g6XO9trveo9LRTOCA6Y/RJBGg3DF8i5AAnfvT4hwzyiz7eFcAye/95i/Jzky0jxaqgo55u6rz Z+d+KdOiyVnTblivzfa3euFX5bQq5KjUpkuMmFQxBQnxEET0PRAYlA1gzp8EZqdHKC/ISazZk 0ZjjH5WFn8D+Dpv5bHqpC1MCP73BGX+OgrJ9BxqJb8D7lFPr/QgrB/+2M/tr95xf+X7dCmlh7 Zosd9uHJz1nNqZq+TZM+z9k7FUpneGDEk72phpx+hRx4GR5Y6WFR0WGA+mj7rGTrigb3giWE1 5aCBCcrHBynNo2I0WtuY3Tha9bO4MV11sErL2HefkDS62q1rHNwx+RnTVZd6QA/Pp4TDMvAGT LVk06h6hVYZ/8qKFOmJ7d09hNwWqmPknvLKWARh4xx0Ez2dJo8goee07RZxjbyVYDqiEhOK95 5dIMPkoi2H2DLCXibH13yEaslKVkHnYtN9iHvkilCYct3VQxunEYbVwmQnm8OSluh5kHlua7W hxukXJaLTIshCqqPfFDtZs8G+kaPEcOyzQO4m2j5L29RQpsl8hZejlaZeHF07GEGpXIgIH/mU y+6BhgTlXuqjySWlLiqFC6cnnV+ICXHoybngQoQDdg== Received-SPF: none client-ip=212.227.17.10; 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 Mon May 15 08:31:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13240947 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 AC495C7EE22 for ; Mon, 15 May 2023 08:32:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTcE-0003j9-Uu; Mon, 15 May 2023 04:31: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 1pyTc4-0003hW-AF for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:24 -0400 Received: from mout.kundenserver.de ([212.227.17.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc2-00023j-PF for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:24 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MDykM-1pqjr20cpo-009xMc; Mon, 15 May 2023 10:31:20 +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: Mon, 15 May 2023 10:31:10 +0200 Message-Id: <20230515083113.107056-7-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:w+dGeldcqM4BE2uD9BGBUlH9VV6JqJq6RDfc3MLowwFWljHvtzp eOBqAEfWVenZrfawkpdLmdN2pheXbMcorl9cPdrrlVs0wtkiSgZGTgdviiB7TH3CbwF4UO1 1tZHhu8FVaF31z03egD94NeAU9rQTdiYHdLP1eBqnezfthS/aIJJ+QcZSbPFD/SE1huwMyT OxDNdoifAsKU/2hN2OgZA== UI-OutboundReport: notjunk:1;M01:P0:saVxXJJWVHg=;Cl+5vQRukEqlv1pniWViIFT+lb3 Extuj0/a/s+zDgZwX0mpDnIwnr8RJyHctD9kufFIhYUMk/K1xDmjyY3HUkzYuK66SVjIf80jH Th9W1JCu0hE4dxapOW5yx7I8z+lZiYCDGHYBA917j0S0cvSlltN9PLqdJvfKuF1InZ0uvO4kK STHmY5MmOY7bhs7Rd7L3i7pjpuHFcV6h5f79fHLHLbW09cfWoCJd5gPSCFLtafUpXunhtrzDF hAmLsuRLgtQsnG92CO123/AZ3CzzouYbdpb/N8lXdSPn/xdQMgIj3bGAZZgadIdQ/s9mh8v+/ DyPqIrvTOypJRumQK3w7pHa7FqVPcnqNmnbYBscVHpts0B/97JvUn/MGfyJWusd5D6M2nggh1 A3uJm+4l2UlgP6sY6eEvCKsRFk0926Jn41wMLTcQHVWTZw8ddWTbQ9yA7wliKvjt6M7SzgSod YKo+kc3YrZuqchveb+o/lpfGZ9HjEMJNo9Ur2DM7SV/mvz0Qu745m2Zh1EPnNs39Kb13FnUqo 5JPDgnx4VuPWFhWZCBZsc/bJOvAuj39pteBiqq5XugB+YwCg+ToXwwE6W/JBxCco9+zakJMKz IKYqEHQbGyWH3dE0Idg3p0zVJAU01j28VXDEjmQiSGrbrX+Q8wY9DoynFiq4CDwG3RYFGGRlH Jicqsa3swvi1UXQ4qx5A6hkUCMosn0EwNFRs+bCi1A== Received-SPF: none client-ip=212.227.17.10; 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 Mon May 15 08:31:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13240956 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 65B48C7EE22 for ; Mon, 15 May 2023 08:34:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTcc-0003kg-7t; Mon, 15 May 2023 04:32:09 -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 1pyTc5-0003hm-7e for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:28 -0400 Received: from mout.kundenserver.de ([217.72.192.74]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc3-000245-L2 for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:24 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1McpS0-1qY5Xu3Joo-00Ztzk; Mon, 15 May 2023 10:31:21 +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: Mon, 15 May 2023 10:31:11 +0200 Message-Id: <20230515083113.107056-8-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:POYU1FMBrgY1llzvC1Uzovqgy+EWww/hd+9jojtKk5RnZkDzcRc EnHaEcXijtwo3ONrI3UnpgHw9S/AhqeLsV/tVFkjhvNIiPVE6ZLtAeSwlICPXB+Fnau/tKt y+RJUmQquGJiGKxmD3dXBh2ZoYCmQ/aXoFU7z8iMtpsASWU5OPKqkyOTiPimM7XKrNXIROu vyFJYD4Ae5O0oFsIx6s4Q== UI-OutboundReport: notjunk:1;M01:P0:Qh1NnHwdgXA=;XNPqZh3zcqNsrgxAqTlpOaHeS8G aAYFZvFBA3ySwNxfaBf1ABg7vLFG8XyHK4LTsvs9B+m4SNttr6cM5vLzk/mDvg27FlwocDJri K50Dspywg0kWGcJyP1OYHrQMAwqLX9eC5ABa7p0iVqE3qIvCCs1/5ynUWnpC7qxz+IK6JuLd7 FSTWtm1cYzLhc7ukVKOpWwb+uqELLV/5ueqa8+Uv9wT9lhIKpD9ptWIEId3IozfSmZ+juOYX/ +23bXgx0Xq4L9AdzT5854zblpaHR63PAzEVNxvVgE9wPJNEsl1GHj4xGX8DVMcWozyLpGZMDN NrW3wPcMcGDMRqMhaTaxJ8M+k5VfP6MPZMW378yayMnI4IgxX36eMB8UUvafEa3XrsRwVwoZJ X4PJWSPqyeYHK29hpwA0n9+6A5HdnNZc2tTRVla8BAyJT0pAmKpW3zumw/z3Rq7ykTHfZXL7W xQpRRRDrPOc04VIwqWkoU6pW1epfEmwfAJ79YD7YpzrBuuu9RJOP2sBV5fuIcC1LFMdltxS6d ncAOnksdVuvVSWAuKJPn+WEtTBDhzWFPuNFwlAo5qV9mAyQ2ZHj67+qe1So+4f6AVLN04XJl/ uViNe/BGgro59hQmpuFpW9X6t7RYYKljuCuP3uOoQkMWPIg0COOHnQr+GYgjQeY6Dph0PCIsx sFYmxLRGKJY17uPw+97FHZo272wU9OxYhnH+6fKxmA== Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-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 Mon May 15 08:31:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13240953 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 05264C7EE22 for ; Mon, 15 May 2023 08:34:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTd5-0004ZM-F1; Mon, 15 May 2023 04:32: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 1pyTc9-0003iD-37 for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:29 -0400 Received: from mout.kundenserver.de ([212.227.17.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc7-000273-Em for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:28 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MkHIV-1qQcMq2TDV-00kfkx; Mon, 15 May 2023 10:31:21 +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: Mon, 15 May 2023 10:31:12 +0200 Message-Id: <20230515083113.107056-9-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:O388fsuUadPcZEXzUE7EUzO0L7fcOqZjMtX2XnK2sZcHfCEWBNU gp8hfGVqiWTFcZ157b0wwGT4qHYCQo3NtuCGnCOEh7aHl4OKzMm8rbTcNU2S15050ldhtoI 7JRs7Hv63opM/MRI6xEvlDnLiyjczznVMm4FAfTvhF2o8/wx3eOFhupDi6Jlkbvcl1i107R yE4LJU2DA2b2vZj/7WQuQ== UI-OutboundReport: notjunk:1;M01:P0:/SiC+BTfWLk=;z3EBb6K80gp40/NbWBR8Jdp4FiZ UIsW81DqeTshVz3ywx2/L3Pl9hYzJdzQRqzPLDXXcZAn57uGO3/E4Y0AFEHYiW1F3BvPKawBP +LVMgvxV3vG2wMobhVY3bR5W3R9hURE8WBOJ8QrSAbAs4glSXHAA6nm9MKN31BIQmQi7CBkqZ PMUyENKzaHt9xkgQ/7qyQlb8PqGUeikXx2FY9qzEGAPRjuzkw1/r5yy1KhbjPFCNLRJ+E+mP4 FFJk7voyC2izNLQxMd0XZpyGtDHecZGO4DR10uxpXxCOe7ESLtEpUxydA6hFO1ApTaGJDLsjn pvxDPqZ05KoG9XM4d2XqnRLuECm1he1cN1TfCCpqLo/KmMp0BXLxUbiXTtlJk3xBh/v4fMDP7 2+PEmdwifKJZ+xYe7v/I49NIsKL+5kyUYIGXSoQ+q6h8ZrRjOt7f2yUIq6+9Fq+sor7/HIXab Qpz7oljM0oskbGV5xpwMLNhhXoa18+ZQL15bgdMfNM9lGMOU5jF6e5Mssyb4QQejnklWyEYEj Ldmph4irbo1OR88/MUDM6RQKRGClv2iYl1K19VmORjaEAqASiG604ESs/nxgYyjIaLg+E35Zl QrLISsnFd+3mUcEa1KJvyTwiSrLoUnmeRjPncRLsTjoKxEX9LvNlIoQwl/vR9oTC+/F/DakKO WqHADrA77dQtApHUfkZlJwz+kN1TPeNLEv9tJemAKQ== Received-SPF: none client-ip=212.227.17.24; 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 Mon May 15 08:31:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13240948 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 016F6C7EE31 for ; Mon, 15 May 2023 08:32:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyTcM-0003kK-LY; Mon, 15 May 2023 04:31: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 1pyTc7-0003i4-Mz for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:28 -0400 Received: from mout.kundenserver.de ([212.227.17.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyTc5-00025k-EV for qemu-devel@nongnu.org; Mon, 15 May 2023 04:31:27 -0400 Received: from quad ([37.169.188.112]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N3bfB-1q7JKi0Mpn-010gCv; Mon, 15 May 2023 10:31:23 +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: Mon, 15 May 2023 10:31:13 +0200 Message-Id: <20230515083113.107056-10-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515083113.107056-1-laurent@vivier.eu> References: <20230515083113.107056-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:QefSNvp2s86mozQG6GYc5pbQ9im4IW9hnHVr+ve9ePYDb2MAUXP sHiXujdP/A7/Ktgw/BVGP3VWfkvjkpRuoOeH0llExno5B/oME2iDBpMQDgQ0QHUJ7MzU2re rI1yAKve3SERVROtGfXNQ/6HX6/oj02GX/KETWuG/BTlNpoEceDxv0NZZolHsTZXrZOl9N1 W8+GuEbueH+qX8wC7ngvw== UI-OutboundReport: notjunk:1;M01:P0:4LPFANhDr7E=;P+N2yoRHW+KMr22Sf3iOFDIXshd 54mSY4Y6zNnnN/98KGG+ZIjezT29O1Tey9hiI8f4+5m6BOsfql7vMexOZduXER+cZ1p0PskVM OEY2JHLwUXPqXMqY87ePqnqEtWZp9TR70bAr9ZcfYJLmbpB6y4SlciR+dfWBMTkku4BVAVfS3 H2DgJHZtgr2nQvN1XHwDClPgVILhKeIsV+If3KJwGdgbf10fGiQ+e30iOMGsPrAcOMQsAB/X7 OEGPN1g4TjkyfDnEJHayO3gARpACmIaTBOWcBiJppFYXFbqiU1p/C5gbFuhIS9S2rwV/WGelZ Ca/A1FDz0obk3BO3XFILzwhnMtw5TKJPdjZaSMe+Dx0wbSMfOIW5rhHrDC4U1oR3cmttDQUMI fS3zek4+BEGN2YHgUbkrjbHI6cVRcfGXIVN6cg/aTiTaql6GN4s3G1cILld2IrmbPLMlP6DdM N7LvVztP8H6vqOEj14hiFgcKI+XOqpq//QSi7eDY74wxtyroM7swr7MCl5Hcl10iB6My0Alw+ 2S0rCRWBqEiORXaxbgryl+evudxK/tnjtJpuVTe4OHacKmAUUwZkSSDw0T8cqfAZ4xI0zKyrE AaBKlFNfoaSdT8kQB6/yC7sGbfSEyOrSxP910POtOeOaz/BIu0bJzY7Nl1+OiEapSQn8gbWdn y1ZseyKjEoTpxfll0Ywm53Y5fodpHBlTWnvBED8QUA== Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_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