From nobody Wed Nov 27 00:40:47 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=1702075405; cv=none; d=zohomail.com; s=zohoarc; b=BWOMbXEQ4tbvTMvc1arLItnOD/PhP6NVf/MTGx5yLueZTEXqe8bv9bEeS5OPUPBeL1BsJyi3GHetVo7o+q9GK7vsdmbYnbJPNykhYrEwoGcK440VQowZlyIxZ0FQEk5i0x68Bgx+JmwR1VYxtE5iCHpFMSmZ45Bbsvy8YcsyNW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702075405; 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=HpcphG95LuIIf3ubc4bAXNdlWqa3b8dqgdEf6cx5a6VSnjjAAgQTNO0FI5ZgQ1UvZ66HfvcUuzq5tyhs2n08azA/HLyTzQxATMMxqXa2jRuWZXf6Gu12TMe9R5lbg2gDIGZgK7eLq5uylLkt0DbUlhQ63sAD7HtBwtHJ6sCl12Q= 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 1702075405589601.2241460669433; Fri, 8 Dec 2023 14:43:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBjY1-0007Wn-Ks; Fri, 08 Dec 2023 17:42:17 -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 <3xZtzZQMKCvwwg0ksskpi.gsquiqy-hiziprsrkry.svk@flex--scw.bounces.google.com>) id 1rBjXz-0007W3-V6 for qemu-devel@nongnu.org; Fri, 08 Dec 2023 17:42:15 -0500 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3xZtzZQMKCvwwg0ksskpi.gsquiqy-hiziprsrkry.svk@flex--scw.bounces.google.com>) id 1rBjXy-0007em-Ie for qemu-devel@nongnu.org; Fri, 08 Dec 2023 17:42:15 -0500 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db53919e062so3384797276.0 for ; Fri, 08 Dec 2023 14:42:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702075333; x=1702680133; 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=a1846F1VGB0ZtjFh7UaEVeCVIjZ2NVXwLFxkdUL1gnLQMZJakThbLFWXWwWk2/tvI+ ESelQua4kpQCJEDwFiJMF24SdBe1bEY06BcCPfXLYRfxjdQ+VETHz2MD8ioldMx45a2M ixmpwh3QKgjzMX+v0qVDY1GUGhA2adkVgBQtBwdFFzCoIVLQ2eP+RreJ1UKgVNckuBjg kb3xQrzPFTDCqs+SzaKhnoSZx5QSVa+Olp8gxsMVKvJvsKUciv6zYJ46c+ctbSPSwvj4 zZjeFybpi7S44QHUnNWq2k+t55tv9D2Y1Fv8lcvbrQ9BZSyxSLWD1umk3qHYp4zNDn9N ShsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702075333; x=1702680133; 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=Nx+9TNWnIp8krQv02ApghqQV1AragrJOCpvcU5kqbsdVZciSDPJPBm/iaHTG6DzQgk +yr5Y5r2mTUbfIdckzKbLh19PzT1sAZVEzHktv4IuBhEmVvTtzrGmYQMv3MPYJYvPGMD utUBHbHizzDiioV7BeFbAqX058ZBl1ddqQVFZYppy7UZ3SOfSjUIh1W0kBwYk4aUMqA/ o9ozFOlc3nMBkO7JYXDGum5ahDg0fwQ6hCFoFhYjFyMVmiu67+ZxuofJpyVu+HFfWOTC 4C1KIIsuc9nPL6vJ00DTFciAaOTquGP872GOQ8yB26yE7R7fHgl2Ff/ob2TyVcGPrBaX Nx3Q== X-Gm-Message-State: AOJu0YwBfKr9kWRdpr1Gk+0g8vhDLSW7pNx8WWBOROI5FaggfnblT2rs D3fSW5No++JJsqDXnoZpbmQCwLBdVAJ/Lzy3Yvyh27DVOfViLRBkfzKqqEV15yfekb9vmWb+5ai g4wkGkj6bpXcFohF5HLQDs37RORmK5ut+YqN5tf2BDjSXZrQpXsbp X-Google-Smtp-Source: AGHT+IGZcnLbMFJ+g4gyffe8wcohsseJdqjUjkpDiBsmVLLodIPGgJCzUYcztICDAdP5VPiePmy3C/w= X-Received: from scw-glinux.svl.corp.google.com ([2620:15c:2d3:205:37bb:5740:1ec:48f2]) (user=scw job=sendgmr) by 2002:a25:9f07:0:b0:db5:4692:3ab7 with SMTP id n7-20020a259f07000000b00db546923ab7mr5571ybq.8.1702075333253; Fri, 08 Dec 2023 14:42:13 -0800 (PST) Date: Fri, 8 Dec 2023 14:42:06 -0800 In-Reply-To: <20231208224207.613445-1-scw@google.com> Message-Id: <20231208224207.613445-2-scw@google.com> Mime-Version: 1.0 References: <20231208224207.613445-1-scw@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v3 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::b49; envelope-from=3xZtzZQMKCvwwg0ksskpi.gsquiqy-hiziprsrkry.svk@flex--scw.bounces.google.com; helo=mail-yb1-xb49.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: 1702075406031100002 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 Wed Nov 27 00:40:47 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=1702075422; cv=none; d=zohomail.com; s=zohoarc; b=Sby5RAgPmtROjgXPrzbGG7N54CcjJ7ARDHNtfFE9uDpUKHhi4bXgNHzB4OyaHflBkN1XvhOl4/CciWlHv6DFwzYYW20+KSsMCVriifzzHqTwDZYKjTNnJFhvzLqNJEenkI9WWWORRBLzFAFfbGN+BN7jk5RCUpAPiPm+KIXSekY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702075422; 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=hORNguViAH2pi6vCqEVU93XiVqEJHtPxd3z4YqE/QaQ=; b=eTdXiKWUE+MrrUjE7YX+qsiZv9lwZ81kcJX9aKuJpsgkxfgKtRyVBrbrqdPVrPmW8qjFdLqkBjNV3pnHH20CMapGdxmdZlRhyfpk/eQhVyapOF1fq/RnUvgZyZayUjNzFkPNDh/QGDuuIGinxjR5e7vm1r2aTfiV92BmTlC5yEo= 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 1702075422416139.40477834981493; Fri, 8 Dec 2023 14:43:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBjY4-0007X0-Hr; Fri, 08 Dec 2023 17:42:20 -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 <3x5tzZQMKCv4yi2muumrk.iuswks0-jk1krtutmt0.uxm@flex--scw.bounces.google.com>) id 1rBjY2-0007Wq-SD for qemu-devel@nongnu.org; Fri, 08 Dec 2023 17:42:18 -0500 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3x5tzZQMKCv4yi2muumrk.iuswks0-jk1krtutmt0.uxm@flex--scw.bounces.google.com>) id 1rBjY1-0007fG-3a for qemu-devel@nongnu.org; Fri, 08 Dec 2023 17:42:18 -0500 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db401df7735so3344453276.3 for ; Fri, 08 Dec 2023 14:42:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702075335; x=1702680135; 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=hORNguViAH2pi6vCqEVU93XiVqEJHtPxd3z4YqE/QaQ=; b=P9x9KsWVJiVAkHePxu1Qa9F/69QVstj4mYdxnmBLNK3AZzuD8ozq0TD7CCQv5QRVqq /91+joxczUsu9sx438TUdop4rkOQIRW8vMA2fNM7+6NVJ0+CwcKRR+siMakrNhOKt5+S KOTfAqDbp24UW9A3sMIRMSBgoUHiTqgqETqJ58UMDgt/XTOT6tzhjJif6t6OPVHvTVL3 0eUcOqbb7LhHEqF2SVufws3vRyTm5jBc1OnQuczon7g+aw0BBbOtsdW8HzwchzlsUiqd A5USjwoQpjKzNKY8irOY4T+Hs7ROUnV35Ny3IhH30VP46ojjZeQQApx0Vi6XY4m78pQ5 G0IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702075335; x=1702680135; 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=hORNguViAH2pi6vCqEVU93XiVqEJHtPxd3z4YqE/QaQ=; b=t9P2MdZXe1cphP3937LWLog0GfQ+ciUlkyusnnJlvAgfWiPkFoI8Bg2axMFzz3JPge KxQW6IF5QwwmNUUYUXwPsHL8mq6fnCBthHvp33HFTYWJiFqxtk7+uc0eg3Jnmv+f3QLA o33N+9d05ZbViFAhfCDYnRinY68qDl8hN0V+LY+fPSTor2+lgCgAXXMDiS8gvI+Pbp06 6X9O+g4fWfl7yzie5XBy59CHGmzTkR4CZNld6CopmUm9OdGPxxpaHd2lHNy8Q28uE40z 0+dWDDWoH/qrLgKqle06he3ms64zfxdC1m8SaUtp5vCXr9+nR5foVqQX4kDGWQYzr+2m 7Dyw== X-Gm-Message-State: AOJu0Yy38pmx0066wsvZIs9XIuEcz989F71z+Mi06E+iLIW5gCgK2t07 x49bfu8gWKuUxfPkRMu3mS+bpye8A9cv3jCqYE//Da+wMlBpGyEbxeJ1QGUvZF28nrSEfz0ghGj zLu2tn0cZ5aaFbdLaI9KVlVuHG4bEt62tNANumu7TGY8cV8ozK0EZ X-Google-Smtp-Source: AGHT+IGusCdAGzcnnYfdTqQzZgJBRtVBKWbOQpE5xGXoD+pt7dcA+ZjSfXEDSao/EyMBO2WTjHtT9go= X-Received: from scw-glinux.svl.corp.google.com ([2620:15c:2d3:205:37bb:5740:1ec:48f2]) (user=scw job=sendgmr) by 2002:a25:7489:0:b0:db7:dce9:76d3 with SMTP id p131-20020a257489000000b00db7dce976d3mr5355ybc.9.1702075335616; Fri, 08 Dec 2023 14:42:15 -0800 (PST) Date: Fri, 8 Dec 2023 14:42:07 -0800 In-Reply-To: <20231208224207.613445-1-scw@google.com> Message-Id: <20231208224207.613445-3-scw@google.com> Mime-Version: 1.0 References: <20231208224207.613445-1-scw@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v3 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::b49; envelope-from=3x5tzZQMKCv4yi2muumrk.iuswks0-jk1krtutmt0.uxm@flex--scw.bounces.google.com; helo=mail-yb1-xb49.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: 1702075424439100002 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 | 47 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e384e14248..7c3772301f 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,42 @@ 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_new(char, proc_stat.st_size + 1); + readlink(proc_name, pathname, proc_stat.st_size + 1); + + /* 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 +8419,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); } }