Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp103218lqp; Tue, 21 May 2024 20:51:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUEHgkoA7I0Wl7AAVDbcFt1kyt8VDkKXlwRDF/dlnZmL0fyMq8jq9TYBmF6Vb0csQ6GFgfwIM0s6eK344cbjhEjIe6mu8arlphDGf0Fvg== X-Google-Smtp-Source: AGHT+IEdvPWEfU0Yp6EtBEXQDHo7wAQJawlx4Hqz1ldmKNBX1ZKpDLR1244nURTRyFqHF3sS5qaN X-Received: by 2002:a05:622a:245:b0:439:b456:25b6 with SMTP id d75a77b69052e-43f7a301c4fmr183203631cf.30.1716349896913; Tue, 21 May 2024 20:51:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716349896; cv=pass; d=google.com; s=arc-20160816; b=tEPB7HaiZZ5N+XGnlzZILZY4/Vg0PCobBs1PrivCHtgoiPzjhzzxFOOQSInEjQxE86 SL50TAlWJlvNbqsYi7u9rc6/EIOVDVVJC/X7BKtRUdAj1fkKrABHVFK9C0iwRN574M1z I7mCeazpyNZbhStCw58wxe0bFIHkzTOLgygqvwrrnamtwxs2g10CA3/dQyMbrYK+okNe T/rew3UAFdFYY5uzbscCAzjaumKCdi1ryOnrOBZaK35j+bJxkqNTyZ5SzJsu9D9+45b5 5FypXfE9HRopvxSFl6ptocq/FZ64hqDVr7oR4GCbtnGmYpAVoQt+89EE2YzJqGjpoe2G uUvQ== 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=dViMVUMutmpZIz4ro8SOgcCM8TxOZwJXLKRwiN39cd8=; fh=dfpuzL54LAMf7GQmHoqmub+qZCPWKUPNTVFHnj8Vxqk=; b=lSQCuN1l54dNN8+0cCwvO0oXLCc2mdI9149Y37T6jhiSv0AIgVnaf391lk5xRxzlJA my6MECyfI9YgCtYZ+nWr40/kX6+RuM1et2X6Z3fvFS9fxBXe2Knk3BsHdBjZQLD0JQER 2NYeTzT63mJMNkgBcza53fbW6nV2A1nB5L/+dSEDrr5Z6hZNvVE0Heb69+nvquu9V3pQ 5+u9ImfKPTpbatE8B4HMBjIlnO0tBPsucFpdXTY9zNDqPLIzuBsmZNEA6aQqDLImwiZB 1dACMDjYWjWMJG6ysYivtU8ZCw5OE9NhvgOyl7Zubrix2yrQ/CBksucNllpWrKY3DJvL +4Wg==; 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-185740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185740-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df566fa8fsi24004501cf.379.2024.05.21.20.51.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 20:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-185740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185740-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A11331C21B57 for ; Wed, 22 May 2024 03:51:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 97CE97E567; Wed, 22 May 2024 03:50:07 +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 B7FBF78C83; Wed, 22 May 2024 03:50:04 +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=1716349806; cv=none; b=G7tHAK2fYG6faZbaqlq3MtguMJVuKWnHgUed5cxdrdG8p3FqHDHYjasNyz1AG+nZfODyjdGAl0YdyH3KUPVeMJ0MiCrEfSi3BVnIumpXcweTxiooULXbk8mBMJu0Eb0FTBqkjiHroP/xicTkA7s9V4TLwEc7kB572Yw7R0pPDvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716349806; c=relaxed/simple; bh=kWxVJ/dGHXmL6Pb3y1v6dGD5eivC2kR2xmKgb20co9U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L6AHkx4ZvxUwmT66xbUAteGhfbN/3Oi2YnD0YuN2MYJzAcCRkJAwkBJXOo8RNvZ6cNI/LYm7pDyEB3J1diqycnL95CEI/AIjVuQTHLdMQT2j1k8h6gKZ+ZFxspshv3juoJlyl1YVDOIjrC4JAr/mr2eNKVm83F6iorLRmse2ZQM= 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 4Vkckl0Sj3z4f3m7R; Wed, 22 May 2024 11:49:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 84BDE1A016E; Wed, 22 May 2024 11:50:01 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBFea01mxlBXNQ--.57627S15; Wed, 22 May 2024 11:50:01 +0800 (CST) From: libaokun@huaweicloud.com To: netfs@lists.linux.dev, dhowells@redhat.com, jlayton@kernel.org Cc: hsiangkao@linux.alibaba.com, jefflexu@linux.alibaba.com, zhujia.zj@bytedance.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, libaokun@huaweicloud.com, yangerkun@huawei.com, houtao1@huawei.com, yukuai3@huawei.com, wozizhi@huawei.com, Baokun Li Subject: [PATCH v3 11/12] cachefiles: flush all requests after setting CACHEFILES_DEAD Date: Wed, 22 May 2024 19:43:07 +0800 Message-Id: <20240522114308.2402121-12-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240522114308.2402121-1-libaokun@huaweicloud.com> References: <20240522114308.2402121-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:cCh0CgBHGBFea01mxlBXNQ--.57627S15 X-Coremail-Antispam: 1UD129KBjvJXoWxurykGw4fJw1rAw4UArW5Jrb_yoW5Jw4DpF Way3WUGry09r4qgw1kArZ8A34rt3sxJF4DWw1UX3s5Arn0vr15Xr1IyryY9r15JrWrGa13 tr1jgFy7Z34jyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04 k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7Cj xVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjTRupB-UUUUU 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 closing /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 closing 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 Acked-by: Jeff Layton --- 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