Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp178736lqd; Tue, 23 Apr 2024 20:52:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQLC1WsWdVJwCN2Ct9cobxhGERSURHVQ+xO7XU+PAmz/oA1m3kc1s7rAsYLcVoMI9i9Tul1kQNtfM45hSrEF6OhRYoflYxYuEu/aZmYA== X-Google-Smtp-Source: AGHT+IGlyyjEE9TC0NWpW1QYQmXSU/yhuOT9/hDAaoktlcbRCmg5sc4Kc+77OewPUqZAIY2p7gWA X-Received: by 2002:a2e:3c17:0:b0:2d6:afdc:2a18 with SMTP id j23-20020a2e3c17000000b002d6afdc2a18mr596135lja.16.1713930755087; Tue, 23 Apr 2024 20:52:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713930755; cv=pass; d=google.com; s=arc-20160816; b=P9ZL4kYGmNOGe45kOF7n2pmL1E+zT8J42IBFsbtFkGP6B4q4gXqyRcgVlJHqcbABTr yjy5Wq/Z9gGzQE0g594HhpwY0+e4QadgQJoIci0YcYLZRp914soEgYB3zIsPCnW0k/9O t78FyVG+z0Qs95VaPDf80EdSu5WSyg7RRB8WsmgIIXdbCg4qR7QWtTZZBDycibJobQ1j 3wdzC3Bv0oXFd+c0K94gW3orJCIKW0/MrP+6oj7yj/4eLGse2kypMiXl8sPIB0dF8ZAd WKlQkoUHt4uR3iMzb/LUvPiB8YVFDv9Gqzy6ZuGCzLXLaGBp2cEPUseC+DKpdIDTdAL0 LqGw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=vKcfk+Qilw7u7ykCXXlxNXZRPQw1f7kFwhyZtueA0j4=; fh=FGAq13Dh0ICWnTZ1bINaUEc79yKht6kuxMzZnIgqSjw=; b=r9VxuzIYM0SVxm3MQ5B12USgh4noHdlqtEjyio1E55UEEuPoHrfN6pPDrxHS/lRwe3 tXjLJgJs+AdFKkZuPrqquxbton1XSK7+tzWfeGTscguC/TpB7cJh6kt2JvEVG/Zs4SOg Hur+/g1Vq10QllM04TgJMxa7JSWOLRui5yfCsrFFHdyczi74WtgHLYozb8HEtEyHP2f1 bhml/cuyraAKtKex/7L39ifqMb9l44m4ix8vKrtF1/6pEj6bgyTGffu5+HLMGrqQ+v/s Iq2xnuoy5r5dvv7asdVFZVcoiYag9S0fNFTP/uKyA3nGsWVwIMXheABT+sWtyIc7xkXB GJOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-156249-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156249-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f18-20020a50d552000000b005701e8c01e4si8098437edj.284.2024.04.23.20.52.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 20:52:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156249-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-156249-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156249-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 13F951F22892 for ; Wed, 24 Apr 2024 03:52:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CE69148FEA; Wed, 24 Apr 2024 03:48:42 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6423F145B0F; Wed, 24 Apr 2024 03:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713930521; cv=none; b=leZ7Pb8SFzQjVEVz00bg7dqlaUsk4Fng+Ftbu5AcC+SGrM5c8TdflmPgW2wK03l7QZF1NG2xbmx24Ss2BzQT7RZcurp3+hhPfl83P06lxmQSdiueCLEbWjHAebqa7caiQikaZvd3qv/vraHspymE4EndJ51V5JRRxGqVAY/oxEk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713930521; c=relaxed/simple; bh=oD/uq+JheDeY/kgmym09d8Qh795Y/FHkwnjjdNNetUI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bGtR9+QlBX+kSZ8XTNIRI79NKynGhrId0M+TbunFDO7wtRizXYxHCOZZwWxwSOG6EfZVJkpM7N7PsSr9QAqtXrZFXF1guD47C5qV40frMZzGd4Bw3Rf91GqK+EMGzkXDhj0M28btygN6r2h2Vu8ntOFxw9XT9JJsED7gTrGYTXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VPQ222Cxyz4f3m76; Wed, 24 Apr 2024 11:48:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7E1761A0175; Wed, 24 Apr 2024 11:48:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBELgShmKXE4Kw--.6143S15; Wed, 24 Apr 2024 11:48:35 +0800 (CST) From: libaokun@huaweicloud.com To: netfs@lists.linux.dev Cc: dhowells@redhat.com, jlayton@kernel.org, zhujia.zj@bytedance.com, jefflexu@linux.alibaba.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 11/12] cachefiles: flush all requests after setting CACHEFILES_DEAD Date: Wed, 24 Apr 2024 11:39:15 +0800 Message-Id: <20240424033916.2748488-12-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240424033916.2748488-1-libaokun@huaweicloud.com> References: <20240424033916.2748488-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgCXaBELgShmKXE4Kw--.6143S15 X-Coremail-Antispam: 1UD129KBjvJXoW7KFWrXr13Zry8uw4UZw13urg_yoW5JFyrpF Way3WUGry09r4qgw1kArZ8J34rJ3sxJF1qgw1UX3s5Arn0vr15Xr1IyryY9F15JrWrGa13 tr1jgFy7Z34jyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUWVWUuwAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24lc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUUNBMtUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/ From: Baokun Li In ondemand mode, when the daemon is processing an open request, if the kernel flags the cache as CACHEFILES_DEAD, the cachefiles_daemon_write() will always return -EIO, so the daemon can't pass the copen to the kernel. Then the kernel process that is waiting for the copen triggers a hung_task. Since the DEAD state is irreversible, it can only be exited by reopening /dev/cachefiles. Therefore, after calling cachefiles_io_error() to mark the cache as CACHEFILES_DEAD, if in ondemand mode, flush all requests to avoid the above hungtask. We may still be able to read some of the cached data before releasing the fd of /dev/cachefiles. Note that this relies on the patch that adds reference counting to the req, otherwise it may UAF. Fixes: c8383054506c ("cachefiles: notify the user daemon when looking up cookie") Signed-off-by: Baokun Li --- fs/cachefiles/daemon.c | 2 +- fs/cachefiles/internal.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index ccb7b707ea4b..06cdf1a8a16f 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -133,7 +133,7 @@ static int cachefiles_daemon_open(struct inode *inode, struct file *file) return 0; } -static void cachefiles_flush_reqs(struct cachefiles_cache *cache) +void cachefiles_flush_reqs(struct cachefiles_cache *cache) { struct xarray *xa = &cache->reqs; struct cachefiles_req *req; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 45c8bed60538..6845a90cdfcc 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -188,6 +188,7 @@ extern int cachefiles_has_space(struct cachefiles_cache *cache, * daemon.c */ extern const struct file_operations cachefiles_daemon_fops; +extern void cachefiles_flush_reqs(struct cachefiles_cache *cache); extern void cachefiles_get_unbind_pincount(struct cachefiles_cache *cache); extern void cachefiles_put_unbind_pincount(struct cachefiles_cache *cache); @@ -426,6 +427,8 @@ do { \ pr_err("I/O Error: " FMT"\n", ##__VA_ARGS__); \ fscache_io_error((___cache)->cache); \ set_bit(CACHEFILES_DEAD, &(___cache)->flags); \ + if (cachefiles_in_ondemand_mode(___cache)) \ + cachefiles_flush_reqs(___cache); \ } while (0) #define cachefiles_io_error_obj(object, FMT, ...) \ -- 2.39.2