From patchwork Tue Jun 27 16:09:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 696889 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp3868258wrm; Tue, 27 Jun 2023 09:17:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5th4OINVaiDpQ24WGBnHCExj8VJ5n62A3bB7QGIIAS2F6+gG/Id9uyJK+WjStu/kK91iry X-Received: by 2002:a1f:41cf:0:b0:471:9069:9491 with SMTP id o198-20020a1f41cf000000b0047190699491mr14488989vka.1.1687882659745; Tue, 27 Jun 2023 09:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687882659; cv=none; d=google.com; s=arc-20160816; b=I74M9MpIvmls6+DqILHynl2E1aCtjrVooaYhy9f3SO/QCoOBlDx+g6eISJdn63Wruo pJI9m+JM5nv3qAd3ewbFNrNg0UBUde0PZ7z/GNCGi+FqbHhYIE1jvVz8R+nTlaQ0RwU9 BUFSp5r2Q+chDNczNLIogYbSCvZpUD9Lg7DLAGGtPDI4b2b8fk8h1A350wvxL570SaWg BPmOEOvjxMldJ9++A8PySW+OmoQNeUuyLlzTtXiAFY3PC+jeVvWos5Cku7UXINUJAwvT ZpoXq3PxrDItoIu01wgQwyTx/JLV0AuS+ycnOjWOrRfF3VsK2PpbxwaxPuGuHm/+CV+z VzlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eCS1WP/4CzEo+1xOyZvf30/WwlM8X9DNuki85IAdOWI=; fh=B6/adVaiTRj/g/M/QPigvyXZO+x+u/FNsaNX2Qo1+tw=; b=vQ+bdEr97YJuuL+l7VclYV4oa+IrghvhD0qloFnopjtqqu0357PZmBtAfBNs799vtA i2qZ76SAzP3jXx04/+r/zJjIQ+RqWro4usBrCjPzRGYtFkrZWDXOllcBgn43MSCjt/y7 P8PJqoqHwt5jA0iKjsZkHjgiXxA6zhsStntzSS34FYX1gLVgv2k1CVZPqsXc+03AVBmR 22szCxZFUZDhGT+nT+5HeJ4Xz29UFXqmponAljeMPeDvRnuqP0LwkUfviZip7sQQeKm5 0BJGPPOf74tEzGwSbTIuPrvFjEYRMEEkOTrBIkInz9Nvq0c/jwqbVIvpyObPcqnR/4Lp xU+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kMgCZIKA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v4-20020a05620a090400b007653ea7ae1dsi2031792qkv.374.2023.06.27.09.17.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Jun 2023 09:17:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kMgCZIKA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEBMK-000170-HX; Tue, 27 Jun 2023 12:16:04 -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 1qEBMH-00011p-BL for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:01 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEBMA-00087D-Gz for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:00 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fa96fd79f0so32712355e9.3 for ; Tue, 27 Jun 2023 09:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687882549; x=1690474549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eCS1WP/4CzEo+1xOyZvf30/WwlM8X9DNuki85IAdOWI=; b=kMgCZIKARsYeLXIUoi0iIZ5bHtOUqNrlk7Tu9jd4+JgreQn7ZnStKnqzgMww7WigLI zQzDjjdHrx1WFaXA20vlxih6Gw0RLw6z7WlJc3Hn3AOeUHmsu7RGDall3S8HscBMqILk zqTpCcCnP0HZjyw2VWzds7hSWZcSlas7TFwusMCgmN4Y0vkynfKDN+z5ulNctEpYjtmB dr/fIHtTPZtC3NBtiJHg6ROr020Qu1HZ7mHcv3h4KK3zGZH6lNJiLWpPHUC9UDAldh5H WaYTwAxxzahYBf7NVKnfv3h8vctII1yjFBgcaClsQAdmLRvEyiC5pWAZSWKl3RiydFj8 8YWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687882549; x=1690474549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eCS1WP/4CzEo+1xOyZvf30/WwlM8X9DNuki85IAdOWI=; b=S1qQQsXlznNvgTvmKP/2T2Msd4tTec4dAjHEKH6dSPzyGDsX5c1/4261Gqk8S98xpZ mNu60ExfozwlRT9p2Lg5HN23YDlL/P7j24bZr+t3QldoUUF7eaCnUzthwZ5AfXv1qSa9 Bf1e77Ba/t74ZLZyO6RqYSMnTov4SqDK+EmtFl4TWOZnRxFEWK3OMoNMW7a51vQJIhPg MgV+t6wTcmglwY091qUCCez2kDLznsGJ2nfKZyhYelABRcnw9QSRChaGNI9F4pXakVZX FzpkAMCVtsyrbqOYyXCjWiAPk55/4MhF4GFsH1s0MgCPxaErk4zOmILsrwSl71D8sD/i ofIQ== X-Gm-Message-State: AC+VfDxwaH7FR4qK+SJjWNmpUcts5lFO02Ze48BGizubt0PbMlGRK1LG dupYdB7BpwxcCKOelJLkpX6/OQ== X-Received: by 2002:a1c:ed0b:0:b0:3f5:fff8:d4f3 with SMTP id l11-20020a1ced0b000000b003f5fff8d4f3mr36066448wmh.7.1687882549365; Tue, 27 Jun 2023 09:15:49 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id u6-20020a05600c210600b003fafe32c8f6sm5024518wml.10.2023.06.27.09.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 09:15:48 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 573621FFD5; Tue, 27 Jun 2023 17:09:47 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Juan Quintela , Thomas Huth , Cleber Rosa , Leonardo Bras , Beraldo Leal , Peter Maydell , Bin Meng , Yanan Wang , Darren Kenny , Alexander Bulekov , Marcel Apfelbaum , Peter Xu , Radoslaw Biernacki , Laurent Vivier , Paolo Bonzini , Eduardo Habkost , qemu-arm@nongnu.org, Stefan Hajnoczi , Richard Henderson , Bandan Das , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Dani?= =?utf-8?q?el_P=2E_Berrang=C3=A9?= , Alexandre Iooss , Marcin Juszkiewicz , Leif Lindholm , Laurent Vivier , Qiuhao Li , Mahmoud Mandour , Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= , Ilya Leoshkevich Subject: [PATCH v3 29/36] linux-user: Expose do_guest_openat() and do_guest_readlink() Date: Tue, 27 Jun 2023 17:09:36 +0100 Message-Id: <20230627160943.2956928-30-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627160943.2956928-1-alex.bennee@linaro.org> References: <20230627160943.2956928-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich These functions will be required by the GDB stub in order to provide the guest view of /proc to GDB. Reviewed-by: Alex Bennée Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson Message-Id: <20230621203627.1808446-2-iii@linux.ibm.com> Signed-off-by: Alex Bennée --- linux-user/qemu.h | 3 +++ linux-user/syscall.c | 54 ++++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 92f9f5af41..a5830ec239 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -165,6 +165,9 @@ typedef struct TaskState { } TaskState; abi_long do_brk(abi_ulong new_brk); +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + int flags, mode_t mode); +ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz); /* user access */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f2cb101d83..fa83737192 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8448,7 +8448,8 @@ static int open_hardware(CPUArchState *cpu_env, int fd) } #endif -static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int flags, mode_t mode) +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + int flags, mode_t mode) { struct fake_open { const char *filename; @@ -8520,6 +8521,36 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int return safe_openat(dirfd, path(pathname), flags, mode); } +ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz) +{ + ssize_t ret; + + if (!pathname || !buf) { + errno = EFAULT; + return -1; + } + + if (!bufsiz) { + /* Short circuit this for the magic exe check. */ + errno = EINVAL; + return -1; + } + + if (is_proc_myself((const char *)pathname, "exe")) { + /* + * Don't worry about sign mismatch as earlier mapping + * logic would have thrown a bad address error. + */ + ret = MIN(strlen(exec_path), bufsiz); + /* We cannot NUL terminate the string. */ + memcpy(buf, exec_path, ret); + } else { + ret = readlink(path(pathname), buf, bufsiz); + } + + return ret; +} + static int do_execveat(CPUArchState *cpu_env, int dirfd, abi_long pathname, abi_long guest_argp, abi_long guest_envp, int flags) @@ -8994,7 +9025,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, case TARGET_NR_open: if (!(p = lock_user_string(arg1))) return -TARGET_EFAULT; - ret = get_errno(do_openat(cpu_env, AT_FDCWD, p, + ret = get_errno(do_guest_openat(cpu_env, AT_FDCWD, p, target_to_host_bitmask(arg2, fcntl_flags_tbl), arg3)); fd_trans_unregister(ret); @@ -9004,7 +9035,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, case TARGET_NR_openat: if (!(p = lock_user_string(arg2))) return -TARGET_EFAULT; - ret = get_errno(do_openat(cpu_env, arg1, p, + ret = get_errno(do_guest_openat(cpu_env, arg1, p, target_to_host_bitmask(arg3, fcntl_flags_tbl), arg4)); fd_trans_unregister(ret); @@ -10229,22 +10260,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, void *p2; p = lock_user_string(arg1); p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0); - if (!p || !p2) { - ret = -TARGET_EFAULT; - } else if (!arg3) { - /* Short circuit this for the magic exe check. */ - ret = -TARGET_EINVAL; - } else if (is_proc_myself((const char *)p, "exe")) { - /* - * Don't worry about sign mismatch as earlier mapping - * logic would have thrown a bad address error. - */ - ret = MIN(strlen(exec_path), arg3); - /* We cannot NUL terminate the string. */ - memcpy(p2, exec_path, ret); - } else { - ret = get_errno(readlink(path(p), p2, arg3)); - } + ret = get_errno(do_guest_readlink(p, p2, arg3)); unlock_user(p2, arg2, ret); unlock_user(p, arg1, 0); }