From nobody Fri May 17 10:13:22 2024 Delivered-To: importer@patchew.org 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1587149401; cv=none; d=zohomail.com; s=zohoarc; b=a8zdgOaFZcA9iq7f8kmbRS1uEHeMwrfGtsyoFuNvVvcI1Haqk5CPQwk7YokT4mRUF3FJrynFsmQoNn6Utc+WE4l6jNSvY/6sf7TDVlWmrSW+V/sRA6S88bfY1WxGlMP2A9uHrTKF6FYG7JhMIHCWsbgYwQxrjQE4ugMszBL98ZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587149401; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=DlNMpF2CMpqeTP2iekn92c+9jpUi7a1OMI+kSZWpYVM=; b=WSGV6aDQK3F3hY1PPJvFZQw4qdkjaQpEF43VpuYHvoPv5bgsc2X3clAx+zoVfZkKMp7ikqKoMyvq6OU1RJ7rEKqqoXIq8jAEGaTrKpcsmA8wPMO66P2H4Qed6qcDMLz2jnSkoia3qP8cwmtSjCFcJLRcRz25ZAkn6Sivz1nylNY= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587149401935531.1912261568946; Fri, 17 Apr 2020 11:50:01 -0700 (PDT) Received: from localhost ([::1]:50774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPW3s-0005GS-A7 for importer@patchew.org; Fri, 17 Apr 2020 14:50:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57059) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPW2y-0003yi-0G for qemu-devel@nongnu.org; Fri, 17 Apr 2020 14:49:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPW2w-0001SR-MM for qemu-devel@nongnu.org; Fri, 17 Apr 2020 14:49:03 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:39360) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPW2w-0001Qo-Fm for qemu-devel@nongnu.org; Fri, 17 Apr 2020 14:49:02 -0400 Received: by mail-pl1-x632.google.com with SMTP id k18so1284276pll.6 for ; Fri, 17 Apr 2020 11:49:02 -0700 (PDT) Received: from vader.tfbnw.net ([2620:10d:c090:400::5:82d8]) by smtp.gmail.com with ESMTPSA id ml24sm5908747pjb.48.2020.04.17.11.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2020 11:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DlNMpF2CMpqeTP2iekn92c+9jpUi7a1OMI+kSZWpYVM=; b=FmAcCsfssTVy/6B6h9bQmP0/X7fKXkMGL5s0b6QNRYEgIKnM2mnXviQLPjPzMzxZkv RRGgQgut/zZuad59e1HhxrlV+8CEEqc4lD4G0r9taOUCjY+Ho5vFlLYXbVL8N/YMoLmf ZCD1iCGNywiL54lNG7yB2f9Nh/2k69uhKPTe2bQTjW25VNMnHCVE/X1TuJAqstZAaf8m fNl0b18fVppfOsYDC+B1tDr+iFgJCpE/6x5YAO2a3MqNGJEiCoM7AXL2jucFxVojXya/ MQ3dHhwnOi5tB01ZpOzRpY7gJU1AfSPPm1ccDYxyUMnjtsMRfzmoJBdATxtYrGvYe9bb rOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DlNMpF2CMpqeTP2iekn92c+9jpUi7a1OMI+kSZWpYVM=; b=mgckI/bpJ3CElQwLrHF0wZkcvgf/feLL4FczFnCPqF514+WKiXixZRStWIdSdtJdDi okuK3TsNbFnEAE7LWX28fgzmMj01/hdaKQR4j9DJmts/IAUXNvWas6vThidKSy+hbHZP ULU5MpFtRUTjNspkcywgKkfJLL323epvY36rFtU7j/2xAbLBz11aDgCkhLGZb9vO2vX7 LQP7GAWuueNZRgEpgHowzgPQkaAKAhnfKFiRqhPI8szNZIPf7/TobJv+Fc/h2Hr/yHS6 3vgcSXymOfPtYR6//yC4TtQoynVJhuWpiNXX3Q2BJ4PBhmMWLSimBSzL38te1Anc2Ckx pamw== X-Gm-Message-State: AGi0PuZPk2bcb8HIE0OyaiTreJk82jvIaLelD0O+f0MXvf9Rd3VGvPub yaY3X55UuXnwvfVBwIm6+mflqXVfjJ8= X-Google-Smtp-Source: APiQypIv8WETmEXuCrNbbIhSYBFdIlhv5m8cMUJppkzqxZh5T1rR3mCm/iVn1tOlXXwuJW46BsQFrA== X-Received: by 2002:a17:902:8b82:: with SMTP id ay2mr4961733plb.285.1587149340917; Fri, 17 Apr 2020 11:49:00 -0700 (PDT) From: Omar Sandoval To: Greg Kurz , Christian Schoenebeck Subject: [PATCH v2] 9pfs: local: ignore O_NOATIME if we don't have permissions Date: Fri, 17 Apr 2020 11:48:24 -0700 Message-Id: X-Mailer: git-send-email 2.26.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::632 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @osandov-com.20150623.gappssmtp.com) Content-Type: text/plain; charset="utf-8" From: Omar Sandoval QEMU's local 9pfs server passes through O_NOATIME from the client. If the QEMU process doesn't have permissions to use O_NOATIME (namely, it does not own the file nor have the CAP_FOWNER capability), the open will fail. This causes issues when from the client's point of view, it believes it has permissions to use O_NOATIME (e.g., a process running as root in the virtual machine). Additionally, overlayfs on Linux opens files on the lower layer using O_NOATIME, so in this case a 9pfs mount can't be used as a lower layer for overlayfs (cf. https://github.com/osandov/drgn/blob/dabfe1971951701da13863dbe6d8a1d172ad96= 50/vmtest/onoatimehack.c and https://github.com/NixOS/nixpkgs/issues/54509). Luckily, O_NOATIME is effectively a hint, and is often ignored by, e.g., network filesystems. open(2) notes that O_NOATIME "may not be effective on all filesystems. One example is NFS, where the server maintains the access time." This means that we can honor it when possible but fall back to ignoring it. Acked-by: Christian Schoenebeck Signed-off-by: Omar Sandoval --- Changes from v1: * Add comment * Add Christian's acked-by hw/9pfs/9p-util.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index 79ed6b233e..546f46dc7d 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -37,9 +37,22 @@ static inline int openat_file(int dirfd, const char *nam= e, int flags, { int fd, serrno, ret; =20 +again: fd =3D openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK, mode); if (fd =3D=3D -1) { + if (errno =3D=3D EPERM && (flags & O_NOATIME)) { + /* + * The client passed O_NOATIME but we lack permissions to hono= r it. + * Rather than failing the open, fall back without O_NOATIME. = This + * doesn't break the semantics on the client side, as the Linux + * open(2) man page notes that O_NOATIME "may not be effective= on + * all filesystems". In particular, NFS and other network + * filesystems ignore it entirely. + */ + flags &=3D ~O_NOATIME; + goto again; + } return -1; } =20 --=20 2.26.1