From nobody Tue Dec 30 23:06:05 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C173C4332F for ; Thu, 9 Nov 2023 19:09:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345165AbjKITJp (ORCPT ); Thu, 9 Nov 2023 14:09:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345118AbjKITJj (ORCPT ); Thu, 9 Nov 2023 14:09:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D363C1B for ; Thu, 9 Nov 2023 11:08:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699556931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uLRQJON7Ac90EDnJlEoBuTyXHqH7isfPCOz8x1WkVk0=; b=gpJfhRKaRidR6s0nkeGZt5gI563xwZEl2PKMDdzpYEmCoZ82Qlq5evP3zIc+kPrkouJxUX Hgg062fnsiMBbCIaflzS9yLB5N1/IKyyHQhtrcr4caD/HKy0mQ2r6YD8hR2gs2HNal4s2B 0nhw/+mEpiFZzvBxonK9yLoR+daCZgg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-120-rEHXra9eOGScqRP2kSZytg-1; Thu, 09 Nov 2023 14:08:47 -0500 X-MC-Unique: rEHXra9eOGScqRP2kSZytg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D6E092815E24; Thu, 9 Nov 2023 19:08:46 +0000 (UTC) Received: from pasta.redhat.com (unknown [10.45.224.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id A66BE492BE7; Thu, 9 Nov 2023 19:08:45 +0000 (UTC) From: Andreas Gruenbacher To: Jens Axboe Cc: Andreas Gruenbacher , Alexander Viro , Christian Brauner , Abhi Das , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs: RESOLVE_CACHED final path component fix Date: Thu, 9 Nov 2023 20:08:44 +0100 Message-ID: <20231109190844.2044940-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Jens, since your commit 99668f618062, applications can request cached lookups with the RESOLVE_CACHED openat2() flag. When adding support for that in gfs2, we found that this causes the ->permission inode operation to be called with the MAY_NOT_BLOCK flag set for directories along the path, which is good, but the ->permission check on the final path component is missing that flag. The filesystem will then sleep when it needs to read in the ACL, for example. This doesn't look like the intended RESOLVE_CACHED behavior. The file permission checks in path_openat() happen as follows: (1) link_path_walk() -> may_lookup() -> inode_permission() is called for each but the final path component. If the LOOKUP_RCU nameidata flag is set, may_lookup() passes the MAY_NOT_BLOCK flag on to inode_permission(), which passes it on to the permission inode operation. (2) do_open() -> may_open() -> inode_permission() is called for the final path component. The MAY_* flags passed to inode_permission() are computed by build_open_flags(), outside of do_open(), and passed down from there. The MAY_NOT_BLOCK flag doesn't get set. I think we can fix this in build_open_flags(), by setting the MAY_NOT_BLOCK flag when a RESOLVE_CACHED lookup is requested, right where RESOLVE_CACHED is mapped to LOOKUP_CACHED as well. Fixes: 99668f618062 ("fs: expose LOOKUP_CACHED through openat2() RESOLVE_CA= CHED") Signed-off-by: Andreas Gruenbacher diff --git a/fs/open.c b/fs/open.c index 98f6601fbac6..61311c9845bd 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1340,6 +1340,7 @@ inline int build_open_flags(const struct open_how *ho= w, struct open_flags *op) if (flags & (O_TRUNC | O_CREAT | __O_TMPFILE)) return -EAGAIN; lookup_flags |=3D LOOKUP_CACHED; + op->acc_mode |=3D MAY_NOT_BLOCK; } =20 op->lookup_flags =3D lookup_flags;