From nobody Tue Nov 26 22:27:22 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=1703801932; cv=none; d=zohomail.com; s=zohoarc; b=WbRP7I1mfe3oZ68M+1uynji9WqE6EoYvxgaJWrWeJJoXzzt0jmVQhCk3gR47RMMd2MAvi/TzoJleM/u1U2xnzYlsPcoAM23DRDZWCu/dtvhIjeAYf7zjXNtrOFCJ+yuV1MABBvhi3NvPq+Tkxn5vVsiysVNtz5X4yOFIYTsbOlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703801932; 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=G3yL+/JS3JWx1cPp71KUfWtGLWSAB5UNwfPttx6LtRs=; b=npboR1impC5iw9i8uhXLTrGnFgwlLVGNmcX+hNA/Qd+t5KQZ5/UBAqo9NBwHcZr/HE20IxTqIPAtWQ+fxnKyC4sSu3cNyGFivZjVdymwgwJAgwpO2ajUujatpQNOzSh+U7hG2h3PaHODR7lJw5LjyM+Z1+hZPqffJTXcK8xYYoU= 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 1703801932441481.0381182702573; Thu, 28 Dec 2023 14:18:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rIyhj-0007Nt-0C; Thu, 28 Dec 2023 17:18:15 -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 <3IvSNZQMKCnUlVpZhhZeX.VhfjXfn-WXoXeghgZgn.hkZ@flex--scw.bounces.google.com>) id 1rIyhg-0007Mz-R3 for qemu-devel@nongnu.org; Thu, 28 Dec 2023 17:18:12 -0500 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3IvSNZQMKCnUlVpZhhZeX.VhfjXfn-WXoXeghgZgn.hkZ@flex--scw.bounces.google.com>) id 1rIyhf-0007eQ-Ai for qemu-devel@nongnu.org; Thu, 28 Dec 2023 17:18:12 -0500 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5e20c9c4080so106460897b3.3 for ; Thu, 28 Dec 2023 14:18:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1703801890; x=1704406690; 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=G3yL+/JS3JWx1cPp71KUfWtGLWSAB5UNwfPttx6LtRs=; b=ogBF+DBfWRC+ixf4IKrlnqzv7tVVTY70AhDd3vBNQUoypMWudCgKclX0X/SSomaIpT XDhQh/MXOz14XRcyOlu7RCYFEG3psx4tB1InolJ3os7187+bwj0/ua3FcrjGySarMIJy 6NgILLsdCMOQ+ganzsLDG6MR+GtefCS1aQe2RUZmTri0j5ZMLsmQ2IwWd5f0D7NIei+2 kFBSbG5FgSZAOFy7gfJY11Us/1fekTb2iwDoYzWYjTm2tGo+KqlnV84OM+wmXZjshuPJ 6tqY3kyVSCpdB/ZJdc68zSlt8g+BMM9G8jurJ/XI9Wvxpv6wQ0oL1oIZdinUPFgG2ZJ3 Eu3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703801890; x=1704406690; 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=G3yL+/JS3JWx1cPp71KUfWtGLWSAB5UNwfPttx6LtRs=; b=Xhj5MSdBddiLXtNSrx5g5c22UUFbByi3VdJKH15j403Tbyli/lVza4Cp9LN1IVPkgS Te618rC2Gon37Zowvt5L9a5TsTLiTvETS6F+ZcQ+6qbrQW741oJo18jz19ZWDbWkys9n TE8Qulblg62/cNB2uqIKH4P42MonWivdOAmU2BV1wBYZAognyqiZR7ogUvyG8PHhDDzx fHWa0Fz1mCAyrZPvoqyss1pjg320b7vuKcxxekapp1nrT+TcHEy+HnuDvY9J7HYRMivK KTQMX3hathsUbo/ptxIyBTmd8OXtimxb9k2OyhUj1WV0IuuEa+EFV+SZ4vN8qz/15agf DD7w== X-Gm-Message-State: AOJu0YwY7QUEdKKlcHYPj3QfGllZ3Q9vlYzknnoo7ivx+p+GelCw9CT8 iFCtFkcpz5UpyfFTVYN3UGpk01fFhWN3NH1OGS9xDhUmprF/dsKyXvaVPyOzye0e3RrQdYW3efQ TndaPLKCXlY/lZ5wpcsFysbk49Vc+lQ8uJL3H9ziyf0d/tLTjbUXCJB6Tu/U= X-Google-Smtp-Source: AGHT+IE4kfK+U8homqeMEqxsTWHO6hainghMcwR6jZdPLUBzulKR7ZhlTx+U/Rirwquwug7IOlIrXoY= X-Received: from scw-glinux.svl.corp.google.com ([2620:15c:2d3:205:ed19:b942:6cb6:d8bc]) (user=scw job=sendgmr) by 2002:a05:690c:4493:b0:5e6:68a8:be40 with SMTP id gr19-20020a05690c449300b005e668a8be40mr5426507ywb.2.1703801890160; Thu, 28 Dec 2023 14:18:10 -0800 (PST) Date: Thu, 28 Dec 2023 14:17:58 -0800 In-Reply-To: <20231228221759.2839009-1-scw@google.com> Message-Id: <20231228221759.2839009-2-scw@google.com> Mime-Version: 1.0 References: <20231228221759.2839009-1-scw@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v4 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::1149; envelope-from=3IvSNZQMKCnUlVpZhhZeX.VhfjXfn-WXoXeghgZgn.hkZ@flex--scw.bounces.google.com; helo=mail-yw1-x1149.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: 1703801932751100001 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. Fixes: 050a1ba69a ("linux-user: move arm/aarch64/m68k fcntl definitions to = [arm|aarch64|m68k]/target_fcntl.h") 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 Tue Nov 26 22:27:22 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=1703801919; cv=none; d=zohomail.com; s=zohoarc; b=MPkd5pMb6iawds/cbfVC1PH+axUde4cjhlHqUo60iBgUwzQ3Pgrqu8TqSOBGS0hKmj02ViVcq7t0AxllAD8Czv9LM/cti7JBMHXBdK0bz1HK3+u3vyjA5mWK/XzU+cycaBRAqtFBu7jduzS7cUk7lUfmRBwqxGHw+jspMcDmZiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703801919; 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=0LggNekTo5+1TUWwnR81y8RD/l2PY1NK6D4/tU2HiLc=; b=QuNmwsr4UHnHUvmE/gCnbj3Kp3OJcfbhKbuUF+jMvtnfhYFryZR8GGS7LPONprXRdDQraUQKPrLp+Lg4bhVlPMKfpI5imnwSB+7EauzfIars1Chi/GPISAjVewf0QZY3MERFDK7nW/MDDiAj/kqyLXRo55lEzA+AIbmVJO0Zt0Q= 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 1703801919551536.5054673093571; Thu, 28 Dec 2023 14:18:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rIyhp-0007Ov-4D; Thu, 28 Dec 2023 17:18:21 -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 <3J_SNZQMKCnoqauemmejc.amkocks-bctcjlmlels.mpe@flex--scw.bounces.google.com>) id 1rIyhn-0007OX-8B for qemu-devel@nongnu.org; Thu, 28 Dec 2023 17:18:19 -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 <3J_SNZQMKCnoqauemmejc.amkocks-bctcjlmlels.mpe@flex--scw.bounces.google.com>) id 1rIyhl-0007gI-GU for qemu-devel@nongnu.org; Thu, 28 Dec 2023 17:18:19 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d12853cb89so113037597b3.3 for ; Thu, 28 Dec 2023 14:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1703801895; x=1704406695; 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=0LggNekTo5+1TUWwnR81y8RD/l2PY1NK6D4/tU2HiLc=; b=mZDbiCqeh2l+CVHybd2nlnrJBACKbFNzudeYSLBx87QQi/4W8XZxYX6TO5Yl7RSQrL pC2GM4nzL2w4u4kzEGqYHDyrFbvDF4yf0/ZYIPNxQF8FEcZn7Bbyo/4ggaLNRgAILJCh BSqBOnPuWuHYCsA8qETgjBBUUgXKcjLVX7a10c/i3MOgdCzk2vL1Mw5dsW9Ks32Arg2V 52+7fEGzGeV4J618C8uLAcQ54gkB6hoYyNvxQDed7xlx7gSr0chx+pwCGrI3shDky8bM 0rPd/DpEH552Iz8UuwE7u6ArBA/noLm6SuI1nZmAJisuSfZPrQebBn8ZAeJ9nYl+gkmh rAlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703801895; x=1704406695; 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=0LggNekTo5+1TUWwnR81y8RD/l2PY1NK6D4/tU2HiLc=; b=s68bBIomZ0tPP7Sd3eKLnc357yehug6WFfUwZXb/ByYE3IidnY7Dgk0/xvSHMumwT7 sc74TMw/S+MIkd6ULjfmF0PSaTAT65W3K5iFi347wMaXiF3iIh6pa3C/YZ0a0J5K0Wd2 nx+ov88r8kby2XaEz3lmYFwM2yebHsTs24E+WZn1ZEEgbW81bIgtKT6qSjBGc8br55qe sdhvZTbGpeHuKoxKIoFwdXBVHWML+HBT1ytO93sQaWr5cuTE9hcGxExJ2WvhClryONXO l/ygRItnHDdp+KFHhoozO/VZtBkU5DNiATqJADT7fVyGheTpUq0xdYASG0hc8yKj6PiL 6h+A== X-Gm-Message-State: AOJu0YwrA7w6QKtgeprprFG3wDrlpOau3e2y8AU5vmrNZ8GWU143e+Kd TFqIcPsJqhnIUG6psZUK1LR0nWAfPFo76LAo6lvwsaVgpCDT+RFc+vbjoKZNmW6mQD+PIhn0k2t JE1kwmepymQz43/u09YjbnIawK7KbcF0X/WAfNB1OzNzWDOyR9ZHpfDjHzEE= X-Google-Smtp-Source: AGHT+IG4Hp/5QuvqX3lQ26EmZGtX/FJpawfsAVtrcxDuhe+yX2CVGB5pvGzRrNXPMh7sh0wFYtEL76g= X-Received: from scw-glinux.svl.corp.google.com ([2620:15c:2d3:205:ed19:b942:6cb6:d8bc]) (user=scw job=sendgmr) by 2002:a05:690c:c0e:b0:5e6:468e:fea0 with SMTP id cl14-20020a05690c0c0e00b005e6468efea0mr5729823ywb.0.1703801895172; Thu, 28 Dec 2023 14:18:15 -0800 (PST) Date: Thu, 28 Dec 2023 14:17:59 -0800 In-Reply-To: <20231228221759.2839009-1-scw@google.com> Message-Id: <20231228221759.2839009-3-scw@google.com> Mime-Version: 1.0 References: <20231228221759.2839009-1-scw@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v4 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 , Helge Deller 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=3J_SNZQMKCnoqauemmejc.amkocks-bctcjlmlels.mpe@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: 1703801920758100005 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. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2004 Signed-off-by: Shu-Chun Weng Reviewed-by: Helge Deller --- linux-user/syscall.c | 50 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e384e14248..2fa56f3dc6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8308,8 +8308,7 @@ 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; + g_autofree char *pathname =3D NULL; struct fake_open { const char *filename; int (*fill)(CPUArchState *cpu_env, int fd); @@ -8334,12 +8333,45 @@ int do_guest_openat(CPUArchState *cpu_env, int dirf= d, const char *fname, { NULL, NULL, NULL } }; =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) { + pathname =3D g_strdup(fname); } else { - pathname =3D fname; + g_autofree char *proc_name =3D NULL; + struct stat proc_stat; + int fd; + + 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 resolve to it (neither will `realpath(3)`= ). + * That's why we check `fname` against the "/proc/" prefix first. + */ + proc_name =3D g_strdup_printf("/proc/self/fd/%d", fd); + if (lstat(proc_name, &proc_stat) < 0 || !S_ISLNK(proc_stat.st_mode= )) { + /* No procfs or something weird. Not going to dig further. */ + return fd; + } + pathname =3D g_new0(char, proc_stat.st_size + 1); + if (readlink(proc_name, pathname, proc_stat.st_size + 1) + !=3D proc_stat.st_size) { + return fd; + } + + /* 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 +8422,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); } }