Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp872090lqd; Wed, 24 Apr 2024 21:57:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIDlXCygd0lhQbdqnf4PjqTNxZ8iUBwe0LbHPEpuCM3v1H1AK2W/zrAef61tJjAMK0ZUVrFjsKnigE9HtilfX4oVlZKrJXfCc97PdJog== X-Google-Smtp-Source: AGHT+IEcmkpRnxr80hqtjuxG8L346BQxtj87Nil8PjH4CviKafEXILRXbNrYR55NYzho7E0B3zNj X-Received: by 2002:a2e:9058:0:b0:2d4:37ca:92d1 with SMTP id n24-20020a2e9058000000b002d437ca92d1mr2554997ljg.42.1714021032279; Wed, 24 Apr 2024 21:57:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714021032; cv=pass; d=google.com; s=arc-20160816; b=oydP/TwTn5exSstIcapYAEPELT9iue7wPqqRbdMtc4Pi7pCsaP6XkrGbu7P7smBMn9 CgIW/raKYY/exZUcDwke+06VecGaM2Xv8BR5kJgodCKY44EhU3mfKtv6k50eWmHAcUs8 pI5PIg8mBrPNmfweVTnTWKM7nvfPBjVNsbeCWHTwL2jup+RAmRxMlOmmI0TDcodKfP1U Q+YCOFxoMFrbbgKLXe0njL5ZN9jXL7D4S9QKNgoWHaQFLSdueDBd8MDS6IIZ0tgFcSTL 9Y2aFi7l4KTKK57GBf7aaaohAY9R10rjTy4jbVgh+CS4iPc0Vbymbs/XZOku6M/1Ava4 jEGg== 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=BKeDMR/VAwY6KFTp7q+D4M4FMjxN7DS4mVLtRqQA6Ps=; fh=x/2l9+rRMs1DnhHr07b2OSuE/i08zstbUXTCECKbxe4=; b=xjgfGB1vfo6AsuA1T3LzU+x+s4tkXa1giD8jysG1H4H402NMp/bEtwwP5Z2kSA/86r HoR4EJ4CwjkOuudqDvZOlnDMoljSuEm1ong8KHFMXZPUoIvUchGg2qYd9mCeMNw9ZQoH 8otqLk6pUjmFt/+J2lQE6vFi6ejHEjAyvmvpsw/Zky8hdBfvA5T9HhHuHEyI16c5K+5f bmGMpHZH5w+sU5Bq5vZ8oE4hEt6lELfmhFSk1hv3mPcERMqJhHt7gKGmkF/lWC4hby8h ob6qvwMpHOOOtuwRowOcj+gzOm8gVIayf82IE+8kz59aet81F+6GCRhE+Q3xHz/gCqYc X3Tw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=SIkE3VWH; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-158008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d1-20020a50f681000000b0057234295ff9si1185201edn.61.2024.04.24.21.57.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 21:57:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=SIkE3VWH; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-158008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.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 am.mirrors.kernel.org (Postfix) with ESMTPS id DC20B1F21FB4 for ; Thu, 25 Apr 2024 04:57:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACB0639FF3; Thu, 25 Apr 2024 04:56:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="SIkE3VWH" Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F2B239AE7 for ; Thu, 25 Apr 2024 04:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714021016; cv=none; b=S1X0Vo5OnzmKFTBqUB89RbHK791ZzmMMgseY9hnATYCZCYlaD+ohcpxO67G2y4he9l/gRgx57QKuLfD+9V7yFSdZ95bi3YBzQvBVho4IOdWSKEizkC6tlv6jhsGhjgw5BVhuMxexJkZXsRa2s1+kOZJuZ+uKRAWx6wJRSIPBphE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714021016; c=relaxed/simple; bh=Pli5F8AnSKspK5aT0/lVVdtVxvdyhbgTwOdQGvsPv/I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AEjcnMxqti1JvdmTPSQj+LGMXhBY6Z2S0v6cnKumqJ5dNj4n/wmEO+FqZwHuNa6eOEibUFd64AfjOxzbC7oxBQq9F4oj5tbWLsAR29b3alCzNmbj3jq3a+YMYrA5edbJ0gt8NURx1kkOpI0LatDQG5lsGl/hO3WTs/YXGKRZXFU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=SIkE3VWH; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ecf05fd12fso572330b3a.2 for ; Wed, 24 Apr 2024 21:56:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1714021014; x=1714625814; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=BKeDMR/VAwY6KFTp7q+D4M4FMjxN7DS4mVLtRqQA6Ps=; b=SIkE3VWHuphvLl7NOhjQq7Nkh9WeBBu84dzIf1WYHLMCfhSz6cIo1AAb9gtEEN+V09 j3XgFvLtTx4P3kaJzs6PtylnirDue+lnKo7b2F7nCSPQndL4HzG3oPasG2NjjNqvVkCM T+BGd9N2l6xgty705iubHWpa9UJOdIbA43XeCGFjkTfmbrVOF/r4VlEzMurm9QUpGXI3 diSOy/n0mkFg1cbGq1yiF6M0gXzrHl+6SUqCAGHD/0txT8SF334h8YrakG/Y61+BYusQ 6SY6kVKLZN2NzfpaxNI3cX/yGc7km4phtFbMKBaBtMWlKJepK8WBNy0ErU8uOKTV+p61 YO+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714021014; x=1714625814; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=BKeDMR/VAwY6KFTp7q+D4M4FMjxN7DS4mVLtRqQA6Ps=; b=co+XeTsPEqFuvB9mm6nvPudx7R2DsgDpYqqsTTNSkVmlRT2OY+aX9oYg5LdiSHXvfR jOgYQvXJCPJSUKdHm1XR1R8yR0tNezp38FqUrZXULn1G2jEz1HheDwhTlQp83mnIq1Wb WGZgUFAGIw0sKeph+ZAdJK62hTlLKPxmVzwD+zulGJkcOZlZh0n4Ax0PcgraeCZ3qojV F6nP9NDvyeI+4HL4Eb9LFEt0j9uIombMw5Lxr1mj0xUqYXCZMusu9WPXh9fpBjjPY1Zi zrVRJVnYBFOVOZ7FLtXUktApU0kvhnOwITx2uS2rNghkJtWPSK7uZ/mdHFbZa42NQ0Do KY1w== X-Forwarded-Encrypted: i=1; AJvYcCVVvA4uRR2A2PirxfSvVe0NbH6sBqlNDlOQ1LAOnn4PoPkXAzmE/wAakArh2/e2rVnETur5fqBB41jbZFDM/8UvNX3DlxsQDKClG/sT X-Gm-Message-State: AOJu0YzcZ7xcU87JlWutEp2ZCfijNFHarEkhQspKwwQHhI8ecq4T8kUq ScGAx713AGqG6rVZ+WTusPpx+ww07t1ZZ0rd6suip58McsWkAV5eL4F3ljdUonA= X-Received: by 2002:a05:6a20:840a:b0:1a7:7818:720e with SMTP id c10-20020a056a20840a00b001a77818720emr5781273pzd.21.1714021013910; Wed, 24 Apr 2024 21:56:53 -0700 (PDT) Received: from [10.3.132.118] ([61.213.176.9]) by smtp.gmail.com with ESMTPSA id r6-20020a17090a5c8600b002ade3490b4asm6319376pji.22.2024.04.24.21.56.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Apr 2024 21:56:53 -0700 (PDT) Message-ID: <32f04cea-1c41-4c16-98fb-86be6ecefc87@bytedance.com> Date: Thu, 25 Apr 2024 12:56:47 +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 10/12] cachefiles: Set object to close if ondemand_id < 0 in copen To: libaokun@huaweicloud.com, netfs@lists.linux.dev Cc: dhowells@redhat.com, jlayton@kernel.org, jefflexu@linux.alibaba.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Zizhi Wo , Baokun Li , zhujia.zj@bytedance.com References: <20240424033916.2748488-1-libaokun@huaweicloud.com> <20240424033916.2748488-11-libaokun@huaweicloud.com> From: Jia Zhu In-Reply-To: <20240424033916.2748488-11-libaokun@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2024/4/24 11:39, libaokun@huaweicloud.com 写道: > From: Zizhi Wo > > If copen is maliciously called in the user mode, it may delete the request > corresponding to the random id. And the request may have not been read yet. > > Note that when the object is set to reopen, the open request will be done > with the still reopen state in above case. As a result, the request > corresponding to this object is always skipped in select_req function, so > the read request is never completed and blocks other process. > > Fix this issue by simply set object to close if its id < 0 in copen. > > Signed-off-by: Zizhi Wo > Signed-off-by: Baokun Li Reviewed-by: Jia Zhu > --- > fs/cachefiles/ondemand.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c > index 7c2d43104120..673e7ad52041 100644 > --- a/fs/cachefiles/ondemand.c > +++ b/fs/cachefiles/ondemand.c > @@ -182,6 +182,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) > xas_store(&xas, NULL); > xa_unlock(&cache->reqs); > > + info = req->object->ondemand; > /* fail OPEN request if copen format is invalid */ > ret = kstrtol(psize, 0, &size); > if (ret) { > @@ -201,7 +202,6 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) > goto out; > } > > - info = req->object->ondemand; > spin_lock(&info->lock); > /* The anonymous fd was closed before copen ? */ > if (info->ondemand_id == CACHEFILES_ONDEMAND_ID_CLOSED) { > @@ -222,6 +222,11 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) > wake_up_all(&cache->daemon_pollwq); > > out: > + spin_lock(&info->lock); > + /* Need to set object close to avoid reopen status continuing */ > + if (info->ondemand_id == CACHEFILES_ONDEMAND_ID_CLOSED) > + cachefiles_ondemand_set_object_close(req->object); > + spin_unlock(&info->lock); > complete(&req->done); > return ret; > }