Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2281893lqo; Mon, 20 May 2024 00:09:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDrnEPYSX7qfh6jtn4KwVeI8DMDs30lm76pOYKPboIpYin4Um7A/wFC/vxWGI7IzOUv1+Z42Nb3c4VcxSgRX19wuyvBUEcvLMwNcQLYg== X-Google-Smtp-Source: AGHT+IFDsGmDFtV2ukQUKDH2FBWPbD6yRmcSKOEzEMEKI/idTxOSizIH4TqQgrHwK+v0+U+osgUo X-Received: by 2002:a17:902:e5d2:b0:1f3:5ca:4200 with SMTP id d9443c01a7336-1f305ca4422mr14721835ad.2.1716188975657; Mon, 20 May 2024 00:09:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716188975; cv=pass; d=google.com; s=arc-20160816; b=jaDD0htYHGxDk1wz4nPO/2fpJrehnzO4OeyuiykWn55HVvEtplz+454Z+C/BKlw0/O uwU1quoRdRaWReBnz97f6V9/erkVKjYuxcjSVLGmeJlixHN3lJ71MWgunSgwV4zwY0FV 7d9dy1X3xxOCGs4pEQ9IPmACdEEv82kVXmVt2YYPRi4RuIZp0LNVEf41X9Ozs4nnUAWi mKTyCmog4sgqe3J2jJbUxuJoInHicRLJJ7HSVHsy3RvXWSbfrq/8d5zJDv8nUrJidfNQ JnFk8GrNkDCSiE/DER+qt6GNcvmAWVfXpPTFBshK9xG4lcqf4mho89VsnY23G5vczBRw SSvw== 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:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=MDsSId074xo3EY1nI/gNouEZEC8qd9U9t2v9Vm9rIbo=; fh=VvJBipBEabZLyCpPRM9XygDwqTVFQZHqClQWlp0FMM8=; b=D7H2EoRRV3zzA4q2CBlIzHhMzQdRNHuo/GVpr5wyISmjm0/ZUvtH6Z2VV9ijsp9rnj jfaHMpdF9q3vqWzq4B8ILyYo15KBduTDH1VexeVA3uvVV23l8bvnHJgbO5I5MaB7DQbi KOwnskK6I4oplZSFusH76WUWYs8+b27QMAwWhXjRDUa138x0n2ctOEpIe/7ffRoR6Qgs d1jDNnsWnURq7XaPI16NcXpCoD88D9Zsq8RFYBzLxeSpfyQLLmNRtBNYqakZ7xgSeGFw DXoPDVjnBGRnQ4NSJZdpvr64Tn5Bk1fyNYztJk4JNnRE0tETz6ZGtJh7LY756SsjRVhM mVgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=aXET4ZKT; 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-183444-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183444-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 sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c038b52si209236085ad.352.2024.05.20.00.09.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 00:09:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183444-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=aXET4ZKT; 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-183444-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183444-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 49046281823 for ; Mon, 20 May 2024 07:09:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7E7418AED; Mon, 20 May 2024 07:09:26 +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="aXET4ZKT" Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (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 C58D91B7F4; Mon, 20 May 2024 07:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716188965; cv=none; b=gAHc2GFduqaGVWK2+n3uGPsFXHy9xFMJPaRk3zzH3Q4gkLYzC3l7yrsyJaeiiR9QjiwG1p8zE/NTtdhVYLop+ffVHUFZnX6CZzKLJFD3mOf3fyl+LV0EjNHQNdZ66cO1byM2yetj5uFqHCCUArUU5OGy9lWBfH7jh6NIaxom2Yk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716188965; c=relaxed/simple; bh=JmovHuASvA+p1UsintWL61loAHcJzRWLo3Jjwj74OjQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mbbRPMo4Fr28c3+KSIqq1TzFm190fDHjJFi6FXmtvh5t8lucn4lCqVlJXzqRJSDyJHYhF1nLWGUK3nIXndMoxdzi0THJuJtto9lnjm3L5JJKhJhLGzEPItQgDrjLzDBdc2LYJ7kZvHRbx7I6CI5xhtGYwZdTY73zIrDY8++9EuU= 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=aXET4ZKT; arc=none smtp.client-ip=115.124.30.124 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=1716188954; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=MDsSId074xo3EY1nI/gNouEZEC8qd9U9t2v9Vm9rIbo=; b=aXET4ZKTNGS4FY28AswQ7chQwxMwaiq285OgWDn7i+iV/yafqAbASX4rmkWBm0Ue11K4zTmDIRgcMaj/yaAtZFZnUp+eHFluI2Bz1446uMcYjtTw4N90uBQ+VC/Aq3/Fj0FCSL6Fv7xGvQh96P1rZof+yjZBquj8WbTgkzdE/P0= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067113;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0W6ny017_1716188952; Received: from 30.221.148.185(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0W6ny017_1716188952) by smtp.aliyun-inc.com; Mon, 20 May 2024 15:09:13 +0800 Message-ID: <764c7b94-9ca9-4288-b806-b3e99fbd05c5@linux.alibaba.com> Date: Mon, 20 May 2024 15:09:11 +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: hsiangkao@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> Content-Language: en-US From: Jingbo Xu In-Reply-To: <20240515084601.3240503-2-libaokun@huaweicloud.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/15/24 4:45 PM, libaokun@huaweicloud.com wrote: > From: Baokun Li > > 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: Jingbo Xu > --- > 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); > -- Thanks, Jingbo