Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3178236lqo; Wed, 15 May 2024 01:56:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOenKqfl3DJCYJ9RVMzJ4riLQK0eHigaDOXP3a+VojdrLv65XZBdt9P/bY3PsiRhmidaPFLezPzf6JXVRI9ZkeG0BHo5S9QoPnkjsjbA== X-Google-Smtp-Source: AGHT+IEQHW4VQ308pXuMe/Pi6SWFUOZeyZRuYv96en5MQjIGtI0iR0Dt10XS2T/foCmTesbO4EtN X-Received: by 2002:a17:907:3208:b0:a59:c367:560c with SMTP id a640c23a62f3a-a5a2d665e1emr1113084366b.60.1715763408495; Wed, 15 May 2024 01:56:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715763408; cv=pass; d=google.com; s=arc-20160816; b=CymVD/fEHPEMP4bLxRBs9SRDIrsetybnduqiDSfu5qxJROHVkkZuVdE0DOzYwHVDjM k++Qe5kyiYrCiKQeGM32uz4Sz5gbdWR+NmLCWZqCgQjNjent4IH1sVZ1Rb5Fg2J7svj9 eW6yY29by8ztxVy0xBUScyO3x+utYz6ZB3kmm5lrI0UQDDUHZlUSF38XQ7ahs9L+p42f ncOTMXWeGK3JUEC5HJUxZV3G9WFsDUEH7YNV7vjLIjPbScut34yJJ/YaIJJii9Wdwq8R hiWBvgfbktsP4cit1vJyBXsKwPMpkFtsJF71VmLwJ87cdPZbccHLN8Z2vmc7xJeAdUM9 IsJw== 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:message-id:date:subject:cc:to :from; bh=1JRY9+CYTQqqOCR2fi4RIA282AS061AZqQbbpjTWEJo=; fh=dfpuzL54LAMf7GQmHoqmub+qZCPWKUPNTVFHnj8Vxqk=; b=nu8P5lzqy+Ar4Es1eUeFZVOhK3+0d+Mftk4C0R7wy+s4fM/Az/D1BaeHvSIPjusQyG LqLv72rTO3VMJPvb3AQ7UWEuipdF+iApNESdjGokF/tg9HNlsdoJvuMPvtjFOJicMBjV GH41ggJmlw4F+6GswmPQCatOmjHOpp0WENu7KaV+GGEBtruHTWfZQXQ4L9OmSuIHCgNr 2qDieR7OOlR/NKrIjCAYd43TCdeAnDMWHASQIUgtqb8t6xsvvzDteLFxDqILB8jWMZyI 7ApWAGvLgbU5pDz2Gnk0k7LHDDDjENEVKKGe5Y+lF5j1OllZuFbTJTVz608+rHj2b75j tdXQ==; 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-179671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179671-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 a640c23a62f3a-a5a8a6efd1fsi136914466b.738.2024.05.15.01.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 01:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179671-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-179671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179671-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 40FCD1F2125B for ; Wed, 15 May 2024 08:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F1135811A; Wed, 15 May 2024 08:56:37 +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 8BDD24F1FE; Wed, 15 May 2024 08:56:33 +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=1715763396; cv=none; b=HVjeeiHumFZs6SuoR0PdzO4VQeyqkG/ZeeusCl+NuHXEiFo6jmDValXt6McY7IX212hP4maW2Cd4RbNTJsODiIahqoprq+8uSI4fAnv15VJQnmOfgiQx71gwjt6NGvV3afm8nq4/sr5VePVZiUZ/qpmmW/x8Q8/yexjM2j6bwkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715763396; c=relaxed/simple; bh=Uc4tFnEVf0RBkrgW0ECtX/HMO8s5cgdWU4r75pK1QsY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=F1mUH0yfI0U6N3axJD1baEfbVPVh2/a8G++ZzECjr/geZVW2qOhoKk7SYWjiAMGF+P1Zc+W+EHAzoirXzpST96tCFaROKIgU5OPh+hcsuTrvnONT/KzRPpOiQKqQJQMEvL1YlC+jqPo8iDer/Uom1E4sI5wbJY3hqLLZdgaWe2A= 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.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VfRsb75Pzz4f3mHb; Wed, 15 May 2024 16:56:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 2C3731A120E; Wed, 15 May 2024 16:56:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDHlxC7eERm68LgMg--.42328S4; Wed, 15 May 2024 16:56:29 +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 v2 00/12] cachefiles: some bugfixes and cleanups for ondemand requests Date: Wed, 15 May 2024 16:45:49 +0800 Message-Id: <20240515084601.3240503-1-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 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:cCh0CgDHlxC7eERm68LgMg--.42328S4 X-Coremail-Antispam: 1UD129KBjvJXoWxXr1fur4rCw1xGF4xWw1kAFb_yoW5GrWrpF WSk3Wakry8Wr40k3s7Ar4rJryrA3yfAF9Fgw12g34DAwn8Xr15ZrWxtr15XFy5CrZxJw42 q3WUuF97J34qv3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvE14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUuVWrJwAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r 1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CE b7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0x vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjfUYWrWUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/ From: Baokun Li Hi all! This is the second version of this patch series. Thank you, Jia Zhu and Jingbo Xu, for the feedback in the previous version. We've been testing ondemand mode for cachefiles since January, and we're almost done. We hit a lot of issues during the testing period, and this patch set fixes some of the issues related to ondemand requests. The patches have passed internal testing without regression. The following is a brief overview of the patches, see the patches for more details. Patch 1-5: Holding reference counts of reqs and objects on read requests to avoid malicious restore leading to use-after-free. Patch 6-10: Add some consistency checks to copen/cread/get_fd to avoid malicious copen/cread/close fd injections causing use-after-free or hung. Patch 11: When cache is marked as CACHEFILES_DEAD, flush all requests, otherwise the kernel may be hung. since this state is irreversible, the daemon can read open requests but cannot copen. Patch 12: Allow interrupting a read request being processed by killing the read process as a way of avoiding hung in some special cases. Comments and questions are, as always, welcome. Please let me know what you think. Thanks, Baokun Changes since v1: * Collect RVB from Jia Zhu and Jingbo Xu.(Thanks for your review!) * Pathch 1: Add Fixes tag and enrich the commit message. * Pathch 7: Add function graph comments. * Pathch 8: Update commit message and comments. * Pathch 9: Enriched commit msg. Baokun Li (11): cachefiles: remove request from xarry during flush requests cachefiles: remove err_put_fd tag in cachefiles_ondemand_daemon_read() cachefiles: fix slab-use-after-free in cachefiles_ondemand_get_fd() cachefiles: fix slab-use-after-free in cachefiles_ondemand_daemon_read() cachefiles: add output string to cachefiles_obj_[get|put]_ondemand_fd cachefiles: add consistency check for copen/cread cachefiles: add spin_lock for cachefiles_ondemand_info cachefiles: never get a new anonymous fd if ondemand_id is valid cachefiles: defer exposing anon_fd until after copy_to_user() succeeds cachefiles: flush all requests after setting CACHEFILES_DEAD cachefiles: make on-demand read killable Zizhi Wo (1): cachefiles: Set object to close if ondemand_id < 0 in copen fs/cachefiles/daemon.c | 3 +- fs/cachefiles/internal.h | 5 + fs/cachefiles/ondemand.c | 218 ++++++++++++++++++++++-------- include/trace/events/cachefiles.h | 8 +- 4 files changed, 177 insertions(+), 57 deletions(-) -- 2.39.2