From nobody Wed Nov 27 03:53:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1701400967; cv=none; d=zohomail.com; s=zohoarc; b=nrV6sKoJOcccAKJ02f5wMrfGbl5iLnHOJqAmmc/DBBxcha9/xSub2FfKnM1EFDusQhCSTDRTIggfpYPvGsg9GGRBFpcv9Eto7B5G5JlCPPI63OGvE+MW8bSuDAxiIBrqWP2o5zWtv43gZG4ndhPo0ExNnnsVk99o2pXMcFvOKJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701400967; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VKbYtxb998M7xtd1yWMMXx/v8cMCtWZz5lASK6nmDYE=; b=SNaJ/TEKyiMNzNPi2bM83KQ+hQNbBMz6EAnY2DBTgd5DzBredoclboZy5yi4rf8Lwo644kqglKYZPZQPNCxvHN7sEg3rhkJrBdl/NvhIGTC0G12sGiOnZ9GaUxF0Yt4dYPJuIK7xT3E7j7feuIciddfqOO+97iULSIo2c1WPUx4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701400967510264.8987148949949; Thu, 30 Nov 2023 19:22:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8u6R-0002wc-Mp; Thu, 30 Nov 2023 22:22:07 -0500 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 <3WlFpZQMKCtMH1L5DD5A3.1DBF3BJ-23K3ACDC5CJ.DG5@flex--scw.bounces.google.com>) id 1r8u6P-0002wS-TE for qemu-devel@nongnu.org; Thu, 30 Nov 2023 22:22:05 -0500 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3WlFpZQMKCtMH1L5DD5A3.1DBF3BJ-23K3ACDC5CJ.DG5@flex--scw.bounces.google.com>) id 1r8u6O-0002gN-Ag for qemu-devel@nongnu.org; Thu, 30 Nov 2023 22:22:05 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-db53c05f802so99554276.0 for ; Thu, 30 Nov 2023 19:22:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701400923; x=1702005723; darn=nongnu.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VKbYtxb998M7xtd1yWMMXx/v8cMCtWZz5lASK6nmDYE=; b=4mTAgyMVZeq3N6N/j1b3Gf5Jj1+8UV+yzfO1bol6nRcvQ3xmijXdCs74KrcFwW0uUN oM1sjkfgCUCqCH5tayH4Gh4+P4oP1AvyH8U/rhjG8Zx3fAHGnuLZWhakRRiDYT/NvxUW XG/OKQDQsiCRHFEK3osPwtcZTUJ+4QDJ27k2GjUMBZo7PiKYjbItTZ3E7cvGUttTK/8r R6QYLHv7eFW/42BA/dqMAusqHOKSNlqncZ/D/qeH7zLXtMiKj9BinVP0KuE4v6oorTXI 71cBPSI4Ct8Jjx/GHUY/nnYGAlPs3DKorH9R83PZi0fNkEB5HNUe5YpEFUaV7xOvAPoL 4EXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701400923; x=1702005723; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VKbYtxb998M7xtd1yWMMXx/v8cMCtWZz5lASK6nmDYE=; b=Cvcn1Q/mMTUa2Mn0ahwgxrOj/O0adNfrwVcGd8EQXKJ3zg5Zrwt/OAOVbDcfjXsyk+ KCAWD7bTtxQrKzZb1VWFiKTp2IlClOgjAYMYV1rh6OLZBCxs0R5Tm6C9TRJwIbo/t27l Y0DFhd9NGIr1X+i8uwxuaTHrOMhnBORfN2Iqoqm8tgy3zPBu21WYnR2uXoMMF0KUKV24 LaGP2ib0ki5hUCksG8pLJqgvqr+zB4WPIc8aSNnDL8qWp+lcRLxMxTjH5V70ettewwCc G8Unfyf2gBEqaie91bZ5V3/ine03XAVxUQKPyhJshapf8mUQ1aXfl/Ox6BU6uCMKeh/i fKHg== X-Gm-Message-State: AOJu0Yy7iTr05lmtPHYpc8n0BRTEZS+GwgwM+Zn7M+GQSgcyy5fYsZNf 8Irz/karxi/o7IfZRT7p/65E+OHrybNwGw1C0OdPsw0huvLqih84AKR5J/0iFvuyNDsbh6viICz 3rJxbAOpJW2KdMUi6BbWNufjicy0z1zWmNjOmneR0e+FvkedwQNr9 X-Google-Smtp-Source: AGHT+IF0pkFEVEe24I1m+2hvHcW84ltuusXuQag8MxkVDGE9QApvMMBseTFz6rveXp8lt93r9r4G1ow= X-Received: from scw-glinux.svl.corp.google.com ([2620:15c:2d3:205:73b4:ef07:4b25:48e5]) (user=scw job=sendgmr) by 2002:a25:3055:0:b0:ca3:3341:6315 with SMTP id w82-20020a253055000000b00ca333416315mr828722ybw.0.1701400922851; Thu, 30 Nov 2023 19:22:02 -0800 (PST) Date: Thu, 30 Nov 2023 19:21:39 -0800 In-Reply-To: <20231201032140.2470599-1-scw@google.com> Message-Id: <20231201032140.2470599-2-scw@google.com> Mime-Version: 1.0 References: <20231201032140.2470599-1-scw@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH 1/2] linux-user: Define TARGET_O_LARGEFILE for aarch64 From: Shu-Chun Weng To: qemu-devel@nongnu.org Cc: Laurent Vivier , Richard Henderson , Shu-Chun Weng Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3WlFpZQMKCtMH1L5DD5A3.1DBF3BJ-23K3ACDC5CJ.DG5@flex--scw.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, 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, USER_IN_DEF_DKIM_WL=-7.5 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1701400967835000002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In 050a1ba, when moving the macros from preprocessor-guarding to file-based definition, TARGET_O_LARGEFILE appeared to have been accidentally left off. This may have correctness implication, but so far I was only confused by strace's output. Signed-off-by: Shu-Chun Weng Reviewed-by: Laurent Vivier --- linux-user/aarch64/target_fcntl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-user/aarch64/target_fcntl.h b/linux-user/aarch64/target_= fcntl.h index efdf6e5f05..55ab788a7c 100644 --- a/linux-user/aarch64/target_fcntl.h +++ b/linux-user/aarch64/target_fcntl.h @@ -11,6 +11,7 @@ #define TARGET_O_DIRECTORY 040000 /* must be a directory */ #define TARGET_O_NOFOLLOW 0100000 /* don't follow links */ #define TARGET_O_DIRECT 0200000 /* direct disk access hint */ +#define TARGET_O_LARGEFILE 0400000 =20 #include "../generic/fcntl.h" #endif From nobody Wed Nov 27 03:53:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1701400967; cv=none; d=zohomail.com; s=zohoarc; b=h2FDIR6ebh5BH40DO48kqHPkCxnyeA3RdIfxiJl3zwgkOrm2U6FWcP6Mrz6RyE3YBC7EB5QrSprJGKSEcthEQGT2152/VLIPIbbmUndz2aGf/A7irCxLjVWeysDVnUHNkeStnNsDIESFV2W1rJHNTVujCMx5y1W/oXxxGWJSDTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701400967; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=51XLYpmadR/yFErptaAwZRJFyAyQ9e208pyzDLJGMCw=; b=mdZZF5vfFaQBl3njUKKT7His94FrHyTuX2AOTNmzqGO2tI5JR82e7Okp3aSpjXI1y/vxLlQ4/xTg4MTQRwjSogjpmFW0SKn0ryHWJApq1qA548L7Y1NS8xJ5HfSdmCDI7/0WJsXU4KhOhH2Q9Hg7a4UV+wch+VbQcUtjHHGnDH4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701400967525384.371203570179; Thu, 30 Nov 2023 19:22:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8u6X-0002xB-8u; Thu, 30 Nov 2023 22:22:13 -0500 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 <3X1FpZQMKCtgM6QAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--scw.bounces.google.com>) id 1r8u6V-0002wy-Sz for qemu-devel@nongnu.org; Thu, 30 Nov 2023 22:22:11 -0500 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3X1FpZQMKCtgM6QAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--scw.bounces.google.com>) id 1r8u6U-0002hH-8B for qemu-devel@nongnu.org; Thu, 30 Nov 2023 22:22:11 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5cfe0b63eeeso30219467b3.0 for ; Thu, 30 Nov 2023 19:22:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701400928; x=1702005728; darn=nongnu.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=51XLYpmadR/yFErptaAwZRJFyAyQ9e208pyzDLJGMCw=; b=JpzxLoGzGHe1Mdbwctviv0WvIErQjZyOTFuVImBV3DDcHCQvoAm8/guryfDAOU2u41 mG9qc48QxXPowKqHcPaJOXqGrcYiXnnqjP8JHsS9rYVRDotvPrqc146jYtAnkf2O03pN x/Fe7SKiTOTvjeezvt5TzXhuATCE2tI7MEGg69dW213FhcFnWsvdTBrmZwiZjnh+0hhp ol/yiuuMB+7BEhT8LuTqDT/9tRbN/9L1R+UHUpLFOoy/nqcVSJVA9cLG3oXkyvHk1mUX 9R2pvCTdIrBmOL97ddLZbWJPQc7kE3lB4dFswb0Fyhc054GcY5Aqtl3l6jf61nxqYo/l 3L7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701400928; x=1702005728; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=51XLYpmadR/yFErptaAwZRJFyAyQ9e208pyzDLJGMCw=; b=fGop2+N3lfwblY115XpL+EU3AvlYYR8kHWGrI+9AOgWVfg6S5EiXF1Be66PPfgWLWU imcP28faqFJA+WmEKakZhuzL+BDn3VgCOg2scbWZZuFqqhyolsf+ZEcxWb1W8Kpku2zV Djht3hrG7ikHh8jRuZY7Yr6OmtfKLavBCnbdCYNTR0q5ptm84lj3PcMfHn60qBhNi5Xx MryOLAC368roAF2qFA6EB1g+otE0VwnZLglsvGdcrZWOGi/Vzi8K4k3R0lX4vRwEqCPB V1WSyqA+zRed4/aYAaADqcZDYFglhkqMQ+emjoZaMKUilD5rGLYU898gtxF935W6E6IZ Z/Tg== X-Gm-Message-State: AOJu0Ywmj6kLFXTj3MP4y55oT2LDyszHKyeqplkGsN2KqNLV+vLLYqSX dimxKz3kqG6SS15F3AcR3alPuZ4/uPTY/s5olXQAnGsmGEx5YJyVVDd4jmvBBy8kIlggEqVzWTE HugZNmRGLu2E9Zl7UqbYoO27M453EoLpZ2QuGyTIhhZwdepV7JTh+ X-Google-Smtp-Source: AGHT+IEGMC6Glz+2p+GzbJfZHMYK/AKaec8yADZ0Bd/fJuUgvHAIKCWPqL3+YO8tMI4CNiE/uSMiXBY= X-Received: from scw-glinux.svl.corp.google.com ([2620:15c:2d3:205:73b4:ef07:4b25:48e5]) (user=scw job=sendgmr) by 2002:a05:690c:340b:b0:5cb:73ab:3e4d with SMTP id fn11-20020a05690c340b00b005cb73ab3e4dmr681976ywb.6.1701400927960; Thu, 30 Nov 2023 19:22:07 -0800 (PST) Date: Thu, 30 Nov 2023 19:21:40 -0800 In-Reply-To: <20231201032140.2470599-1-scw@google.com> Message-Id: <20231201032140.2470599-3-scw@google.com> Mime-Version: 1.0 References: <20231201032140.2470599-1-scw@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH 2/2] linux-user: Fix openat() emulation to not modify atime From: Shu-Chun Weng To: qemu-devel@nongnu.org Cc: Laurent Vivier , Richard Henderson , Shu-Chun Weng Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3X1FpZQMKCtgM6QAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--scw.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, 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, USER_IN_DEF_DKIM_WL=-7.5 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1701400967847000003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit b8002058 strengthened openat()'s /proc detection by calling realpath(3) on the given path, which allows various paths and symlinks that points to the /proc file system to be intercepted correctly. Using realpath(3), though, has a side effect that it reads the symlinks along the way, and thus changes their atime. The results in the following code snippet already get ~now instead of the real atime: int fd =3D open("/path/to/a/symlink", O_PATH | O_NOFOLLOW); struct stat st; fstat(fd, st); return st.st_atime; This change opens a path that doesn't appear to be part of /proc directly and checks the destination of /proc/self/fd/n to determine if it actually refers to a file in /proc. Neither this nor the existing code works with symlinks or indirect paths (e.g. /tmp/../proc/self/exe) that points to /proc/self/exe because it is itself a symlink, and both realpath(3) and /proc/self/fd/n will resolve into the location of QEMU. Signed-off-by: Shu-Chun Weng --- linux-user/syscall.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e384e14248..25e2cda10a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8308,8 +8308,6 @@ static int open_net_route(CPUArchState *cpu_env, int = fd) int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname, int flags, mode_t mode, bool safe) { - g_autofree char *proc_name =3D NULL; - const char *pathname; struct fake_open { const char *filename; int (*fill)(CPUArchState *cpu_env, int fd); @@ -8333,13 +8331,39 @@ int do_guest_openat(CPUArchState *cpu_env, int dirf= d, const char *fname, #endif { NULL, NULL, NULL } }; + char pathname[PATH_MAX]; =20 - /* if this is a file from /proc/ filesystem, expand full name */ - proc_name =3D realpath(fname, NULL); - if (proc_name && strncmp(proc_name, "/proc/", 6) =3D=3D 0) { - pathname =3D proc_name; + if (strncmp(fname, "/proc/", 6) =3D=3D 0) { + pstrcpy(pathname, sizeof(pathname), fname); } else { - pathname =3D fname; + char procpath[PATH_MAX]; + int fd, n; + + if (safe) { + fd =3D safe_openat(dirfd, path(fname), flags, mode); + } else { + fd =3D openat(dirfd, path(fname), flags, mode); + } + if (fd < 0) { + return fd; + } + + /* + * Try to get the real path of the file we just opened. We avoid c= alling + * `realpath(3)` because it calls `readlink(2)` on symlinks which + * changes their atime. Note that since `/proc/self/exe` is a syml= ink, + * `pathname` will never resolves to it (neither will `realpath(3)= `). + * That's why we check `fname` against the "/proc/" prefix first. + */ + snprintf(procpath, sizeof(procpath), "/proc/self/fd/%d", fd); + n =3D readlink(procpath, pathname, sizeof(pathname)); + pathname[n < sizeof(pathname) ? n : sizeof(pathname)] =3D '\0'; + + /* if this is not a file from /proc/ filesystem, the fd is good as= -is */ + if (strncmp(pathname, "/proc/", 6) !=3D 0) { + return fd; + } + close(fd); } =20 if (is_proc_myself(pathname, "exe")) { @@ -8390,9 +8414,9 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd,= const char *fname, } =20 if (safe) { - return safe_openat(dirfd, path(pathname), flags, mode); + return safe_openat(dirfd, pathname, flags, mode); } else { - return openat(dirfd, path(pathname), flags, mode); + return openat(dirfd, pathname, flags, mode); } }