From patchwork Sat Aug 5 22:48:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksa Sarai X-Patchwork-Id: 13342695 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 A6A43C04E69 for ; Sat, 5 Aug 2023 22:48:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230040AbjHEWs5 (ORCPT ); Sat, 5 Aug 2023 18:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbjHEWsz (ORCPT ); Sat, 5 Aug 2023 18:48:55 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C09EC19B5; Sat, 5 Aug 2023 15:48:54 -0700 (PDT) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4RJHnH2g5Vz9scK; Sun, 6 Aug 2023 00:48:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cyphar.com; s=MBO0001; t=1691275731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IH0KsC6OjiP5vq0A6Tdbg/v/G6fKP45ZcMl0AmDcmOA=; b=OCzkM9IUSZsSp6kO/WcZlLSUvAUOX3yTN30CSP6tAsr24VByzDMWKJUa3vvGeTo/Qlg8h1 LcJpsf7EuGYPDVIDdHiEJFaaFVAe43P/sw/oUiQuEU+iGUeHfyYbpnGkgGfWeda8PPeV9B 3D7D450vtUNt713nJI0zSW0vsZJwTUtlCXKOJKnWBFjRIqy/wLJqioHO3CIlHVFhuua73a LciCHOkNg6AE+fGFqtGhqkec5fjfJx/JeBS5T3pdN0gV8I6PrcBTAXFuEh/VuK/2i9ETcB Q1hTsGr1udZeiE/NLAew1Hw3V29+EcIAId20Hsz85CColTmfdNQ1gAd7MUbUSw== From: Aleksa Sarai Date: Sun, 06 Aug 2023 08:48:08 +1000 Subject: [PATCH v2 1/2] open: make RESOLVE_CACHED correctly test for O_TMPFILE MIME-Version: 1.0 Message-Id: <20230806-resolve_cached-o_tmpfile-v2-1-058bff24fb16@cyphar.com> References: <20230806-resolve_cached-o_tmpfile-v2-0-058bff24fb16@cyphar.com> In-Reply-To: <20230806-resolve_cached-o_tmpfile-v2-0-058bff24fb16@cyphar.com> To: Alexander Viro , Christian Brauner , Jens Axboe , Pavel Begunkov Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Aleksa Sarai , stable@vger.kernel.org X-Developer-Signature: v=1; a=openpgp-sha256; l=1006; i=cyphar@cyphar.com; h=from:subject:message-id; bh=OiJ0X41F7OTqXAqgldma319Yo5G2MNu2En+iv/Foe7M=; b=owGbwMvMwCWmMf3Xpe0vXfIZT6slMaScu3jiTIpvTXiAgVgoU8rPSOv3ZvyVqebmq5xCdxzY6 6R58fP8jlIWBjEuBlkxRZZtfp6hm+YvvpL8aSUbzBxWJpAhDFycAjCRNU0Mf6XN2Thcf/bw/zds yXj1a/+KVZZfHvjZ7tHZenTK1rWlZ2IY/leeV+p6aXDv7xuzwr9HV0xbv4bnjMa0nXUlfCZvr0t eDmYGAA== X-Developer-Key: i=cyphar@cyphar.com; a=openpgp; fpr=C9C370B246B09F6DBCFC744C34401015D1D2D386 X-Rspamd-Queue-Id: 4RJHnH2g5Vz9scK Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org O_TMPFILE is actually __O_TMPFILE|O_DIRECTORY. This means that the old fast-path check for RESOLVE_CACHED would reject all users passing O_DIRECTORY with -EAGAIN, when in fact the intended test was to check for __O_TMPFILE. Cc: stable@vger.kernel.org # v5.12+ Fixes: 99668f618062 ("fs: expose LOOKUP_CACHED through openat2() RESOLVE_CACHED") Signed-off-by: Aleksa Sarai --- fs/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/open.c b/fs/open.c index b8883ec286f5..2634047c9e9f 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1337,7 +1337,7 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) lookup_flags |= LOOKUP_IN_ROOT; if (how->resolve & RESOLVE_CACHED) { /* Don't bother even trying for create/truncate/tmpfile open */ - if (flags & (O_TRUNC | O_CREAT | O_TMPFILE)) + if (flags & (O_TRUNC | O_CREAT | __O_TMPFILE)) return -EAGAIN; lookup_flags |= LOOKUP_CACHED; } From patchwork Sat Aug 5 22:48:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksa Sarai X-Patchwork-Id: 13342696 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 59D4CC001DB for ; Sat, 5 Aug 2023 22:49:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbjHEWtB (ORCPT ); Sat, 5 Aug 2023 18:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbjHEWs7 (ORCPT ); Sat, 5 Aug 2023 18:48:59 -0400 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050:0:465::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 914AD19B5; Sat, 5 Aug 2023 15:48:58 -0700 (PDT) Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4RJHnM24c3z9sXg; Sun, 6 Aug 2023 00:48:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cyphar.com; s=MBO0001; t=1691275735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTrtNNENm22a5owwWX6fpH4Q0oDQAef+vTZzTwxbU1c=; b=C6iyo5xuH4J6DGdV5Wj/y8uix7OOeA27r7ua4t2iV+7C6dZA8n5Ldj6aFLCYDQfgHTGcQh kmBvrUCDvougnR6fgcy2cxKzNVgCBma+Zw9YZMIn+EiJPH2ADKmrCAN1qWVWCYPLusDsP6 B4QDsE6njXYpWhexLFd2tCCHqG4Z34ioEGajXFPcpBvQqewxkqcV9S/26DFLtGk3128C7E J4tw0VX1+UzMU4eOgChKBLunnrmBknICUOtnYqJQbfwp7TIt2jHi7EiTqmzGHHNacWJgaL HCjncVCUHuWulXxj2fkMksi0X8TmZ2eb9YmRvdH9vTFsuFPRSgceYVPPqCmSUw== From: Aleksa Sarai Date: Sun, 06 Aug 2023 08:48:09 +1000 Subject: [PATCH v2 2/2] io_uring: correct check for O_TMPFILE MIME-Version: 1.0 Message-Id: <20230806-resolve_cached-o_tmpfile-v2-2-058bff24fb16@cyphar.com> References: <20230806-resolve_cached-o_tmpfile-v2-0-058bff24fb16@cyphar.com> In-Reply-To: <20230806-resolve_cached-o_tmpfile-v2-0-058bff24fb16@cyphar.com> To: Alexander Viro , Christian Brauner , Jens Axboe , Pavel Begunkov Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Aleksa Sarai , stable@vger.kernel.org X-Developer-Signature: v=1; a=openpgp-sha256; l=1068; i=cyphar@cyphar.com; h=from:subject:message-id; bh=/9+yxvKGEmdLwvOcpr7FLQ4otf1WYZ3hs0L34KRntms=; b=owGbwMvMwCWmMf3Xpe0vXfIZT6slMaScu3jy1qz3bXtf7e40zt7d8OH4hXe7nFZkBQgbVGuLX f/EbzeptaOUhUGMi0FWTJFlm59n6Kb5i68kf1rJBjOHlQlkCAMXpwBMxPQUI8PFv0cnPOSYuMPY 5cbsM7N/PNl8xn/ZdfbKSWyRRtc5DmWsZ/ifLyMbYaIQtfnvivM3siPmsVs11Ee3qW2UPb75t7x d6zc+AA== X-Developer-Key: i=cyphar@cyphar.com; a=openpgp; fpr=C9C370B246B09F6DBCFC744C34401015D1D2D386 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org O_TMPFILE is actually __O_TMPFILE|O_DIRECTORY. This means that the old check for whether RESOLVE_CACHED can be used would incorrectly think that O_DIRECTORY could not be used with RESOLVE_CACHED. Cc: stable@vger.kernel.org # v5.12+ Fixes: 3a81fd02045c ("io_uring: enable LOOKUP_CACHED path resolution for filename lookups") Signed-off-by: Aleksa Sarai --- io_uring/openclose.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_uring/openclose.c b/io_uring/openclose.c index 10ca57f5bd24..a029c230119f 100644 --- a/io_uring/openclose.c +++ b/io_uring/openclose.c @@ -35,9 +35,9 @@ static bool io_openat_force_async(struct io_open *open) { /* * Don't bother trying for O_TRUNC, O_CREAT, or O_TMPFILE open, - * it'll always -EAGAIN + * it'll always -EAGAIN. */ - return open->how.flags & (O_TRUNC | O_CREAT | O_TMPFILE); + return open->how.flags & (O_TRUNC | O_CREAT | __O_TMPFILE); } static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)