Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2198632lqo; Sun, 19 May 2024 19:21:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWSyvGqU2929UUWc/ptUby0r+kh9aiHbi4+fudBF0cWvLuF7eLq1j9xqONMoaHXliB+bJa749bu+dso3djfoMugTk1NNjN5nkgqZoHoeg== X-Google-Smtp-Source: AGHT+IEpErnL8SC98+NddNRvGaqZHgKaYoiWE6HOqaog1lsScgrSToVwmZplI1/mDRQ3YiYjpL7M X-Received: by 2002:a05:6122:318f:b0:4d3:36b9:2c26 with SMTP id 71dfb90a1353d-4df8835e770mr27118643e0c.14.1716171683275; Sun, 19 May 2024 19:21:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716171683; cv=pass; d=google.com; s=arc-20160816; b=pUbs7aSDmme//2pi2EyFJWT+QFbmfl5Q8kGWN5HAil5/D+43mGzST2rQTkyoq0QsYT 8mWVc0vy5NqAMG2oRDA9eMu4NSJJxEJiZ1Hl2mtD5BarW7uWVrPHcJjMVa+fAVcVoAuO O/njnDzPpQe+HunBUVjSSVU2RJmizOC5MvElLSWSdLgE4v9YJWagquMxVdkzYyUu3THU rgru6yALaPq6PzjiDlcAoBnZzDd1I+xWQtfRp6vDlWssldN7o7G7sOSg+DWteOyMv7mZ W64R8iY+QW6cf924sJ0RTrg/YfjjTJIfcRv6aFJuQ/hVqz9jBKjJlXk17evyrefSDDwi +WPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=JEAxIHH4Mzu7tZcEd3SvUP+FFw/Ul2NIJxhCNffO0+0=; fh=+pegVmHDK94zlEjj6Xvli0jIeEH4D6+NJP9ZZwH1bQI=; b=AGXnklQGczN2fa0zfLsdzlb/BZw2YXvU5F2VU0c3xZYTW9VFnaCknSRx3aDaPhIlAg nspS/s3JZctYt/HA3GW1iHSqcOLOHsWOT6JViXIVsy/dWEqDAQicY43ckhOEx97/Zg+L y2onXZYUX2sZFKPMYwxvPJ1MEYAOB7GWzGUtpx7vMgBiMci1kLcp0sfqfPHbl+0XZb7y YqLrip/N0SDRYzMhB34rYrlVSXR7b3ysFF8c78KY74rBbfPHtt7YO8oI3G9WBVfQdpbk F1LD+9k8+CckUAnKzfJbn/6IbPAZIx+3/r8qI/88+L+ZXCApyPgbNJdsZD+GnaZyZBDJ +/cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=MFkpSrBr; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-183354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf3382cdsi2369734085a.495.2024.05.19.19.21.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 19:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183354-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; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=MFkpSrBr; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-183354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com 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 015A51C216F8 for ; Mon, 20 May 2024 02:21:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 004B1C8CE; Mon, 20 May 2024 02:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="MFkpSrBr" Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (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 B0ED9D27E; Mon, 20 May 2024 02:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716171674; cv=none; b=d3ud1KI6CmwwqMO7FjWFmMGz1avUyz2bzHDLV1YpJS6KX/plAZhz5j8mTV8Hs3Pg/lJmNiS+Q+FTZbxQnr4hCsYUZGs4o0WiSee4BtAZ1muRFPrwwSkZVHIRrDsyjBmdPNz14Vh6AxqmQGPxergJGWcvV9bEDCf/qc/oE7Uv1VI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716171674; c=relaxed/simple; bh=/iOGvsrjFGV63irIU6immb0EJljLXPU1vagBsVi7LVc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lHJ5WXN+BOjtW0w/rXjAp9kz3tIbs2tb+HeFiEiX6HbQNHq27jktnYJaf55R4Ht4FF141C08T/o9qCUvboL4me2r0P+/j6ZdCEcCsDOztiVEZw8g7DbWyPBNbkkEN22epb/a56RecOYrK2t5W7H2fsr1Waj1BQ7atwg9zrj4aiQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=MFkpSrBr; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1716171664; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=JEAxIHH4Mzu7tZcEd3SvUP+FFw/Ul2NIJxhCNffO0+0=; b=MFkpSrBrZRhc48OZoZkxsaOukLJDOXfom+K0gwp1Xupa065wBdq2NGWvCTkLWTPdP9KYYQ09ML5bc+KrNY5/5UydFP4xViGqpkqj/vmPoP2Y0EHWNfs6dXd+aCb5tcHDEz/cUTSEsOb7o3TNSoTcDqYLlwjPC12hWS0mh5waYiI= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067110;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0W6kg4SN_1716171661; Received: from 30.97.48.204(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0W6kg4SN_1716171661) by smtp.aliyun-inc.com; Mon, 20 May 2024 10:21:03 +0800 Message-ID: Date: Mon, 20 May 2024 10:20:59 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 01/12] cachefiles: remove request from xarry during flush requests To: libaokun@huaweicloud.com, netfs@lists.linux.dev, dhowells@redhat.com, jlayton@kernel.org Cc: jefflexu@linux.alibaba.com, zhujia.zj@bytedance.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yangerkun@huawei.com, houtao1@huawei.com, yukuai3@huawei.com, wozizhi@huawei.com, Baokun Li References: <20240515084601.3240503-1-libaokun@huaweicloud.com> <20240515084601.3240503-2-libaokun@huaweicloud.com> From: Gao Xiang In-Reply-To: <20240515084601.3240503-2-libaokun@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/5/15 16:45, libaokun@huaweicloud.com wrote: > From: Baokun Li The subject line can be "cachefiles: remove requests from xarray during flushing requests" > > Even with CACHEFILES_DEAD set, we can still read the requests, so in the > following concurrency the request may be used after it has been freed: > > mount | daemon_thread1 | daemon_thread2 > ------------------------------------------------------------ > cachefiles_ondemand_init_object > cachefiles_ondemand_send_req > REQ_A = kzalloc(sizeof(*req) + data_len) > wait_for_completion(&REQ_A->done) > cachefiles_daemon_read > cachefiles_ondemand_daemon_read > // close dev fd > cachefiles_flush_reqs > complete(&REQ_A->done) > kfree(REQ_A) > xa_lock(&cache->reqs); > cachefiles_ondemand_select_req > req->msg.opcode != CACHEFILES_OP_READ > // req use-after-free !!! > xa_unlock(&cache->reqs); > xa_destroy(&cache->reqs) > > Hence remove requests from cache->reqs when flushing them to avoid > accessing freed requests. > > Fixes: c8383054506c ("cachefiles: notify the user daemon when looking up cookie") > Signed-off-by: Baokun Li > Reviewed-by: Jia Zhu Reviewed-by: Gao Xiang Thanks, Gao Xiang > --- > fs/cachefiles/daemon.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c > index 6465e2574230..ccb7b707ea4b 100644 > --- a/fs/cachefiles/daemon.c > +++ b/fs/cachefiles/daemon.c > @@ -159,6 +159,7 @@ static void cachefiles_flush_reqs(struct cachefiles_cache *cache) > xa_for_each(xa, index, req) { > req->error = -EIO; > complete(&req->done); > + __xa_erase(xa, index); > } > xa_unlock(xa); >