Message ID | 20221124092602.259809-1-chenzhongjin@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3289680wrr; Thu, 24 Nov 2022 01:41:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ePJ4xiCw591LcupXpXtMm9f4j/hWpI0Xo6Di8kw7AM+x2CnuOqhSHME7dlC08k4BROs2v X-Received: by 2002:a17:902:dac2:b0:188:f5c7:4d23 with SMTP id q2-20020a170902dac200b00188f5c74d23mr13350762plx.125.1669282892416; Thu, 24 Nov 2022 01:41:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669282892; cv=none; d=google.com; s=arc-20160816; b=IadX2MI+jSnpS98tGJTmQPf+hWkWTADXlKhgSxi779pmx3idtHRy9fCKNf5n/GfS/M dD7XCsFcBr3/vXsgdd6wGffWRgaazgNOfXopXHUbVWzN9K4HvXxwKXLuqxOjY5siGgt6 5KAkd+XuPbp7GL+Hlmd7JjvrGHMVS56ct7wkanhzp1mdJQ5exxIoJsBo6s0JhNsKHDB1 8pEXK1v6i/SHgtgoA1KqK/5Y/8Cf4PQ5vaxxEEQlAhJfUw0LbPfr0DzwTuLb54u5Udn7 yRlH3/ZphkZX4+yxqOuOAqgMVWrIj8LKZBsPJWoWvOcGSznwoJNvAYCUviH5yDsX7yHp Q6EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=1jrYWc0T03lSYWbwFrPLFEvp97qCmTSgQolliseb36w=; b=Tr/2pkrC2jEpVq35YnNvM2w3SFyTCJ0wAdFlp22r2NvEwzYqKmePmPKESB2nTIW/5W fOtLngi0CzVq03Ob8GLo4ejm9qvazoN8qxCMqnIhLQNbwM1GraHDY567ygAwOv0VcdcA 5NtMpH+d3tGIq+pgYojQ6mpQKH/HJ0qyZ7Kut3kKGr5T6UYo1eys0vrXDU2f0ubweGzz 4g0yLx9nJ4eGXuBl8zyjqB5dzXvFKnI6hMI94QBceF3oNu6wfAe/4/JeOoyO7NzuZdk+ v5zW2xgLUlba11hFWHGOb1piBV54C3A42Evg/CE3tIyJBPHskfKhqq7qDQAcmBf9AUyt odQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020aa79548000000b0053837d7cf84si251620pfq.254.2022.11.24.01.41.19; Thu, 24 Nov 2022 01:41:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbiKXJ3P (ORCPT <rfc822;fengqi706@gmail.com> + 99 others); Thu, 24 Nov 2022 04:29:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiKXJ3O (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 24 Nov 2022 04:29:14 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB0B94E43A; Thu, 24 Nov 2022 01:29:13 -0800 (PST) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NHt3C2SP1zmW5j; Thu, 24 Nov 2022 17:28:39 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 24 Nov 2022 17:29:06 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 24 Nov 2022 17:29:06 +0800 From: Chen Zhongjin <chenzhongjin@huawei.com> To: <syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com>, <linux-unionfs@vger.kernel.org>, <linux-kernel@vger.kernel.org> CC: <chenzhongjin@huawei.com>, <miklos@szeredi.hu> Subject: [PATCH] ovl: Fix use inode directly in rcu-walk mode Date: Thu, 24 Nov 2022 17:26:02 +0800 Message-ID: <20221124092602.259809-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750369978326919274?= X-GMAIL-MSGID: =?utf-8?q?1750369978326919274?= |
Series |
ovl: Fix use inode directly in rcu-walk mode
|
|
Commit Message
Chen Zhongjin
Nov. 24, 2022, 9:26 a.m. UTC
syzkaller reported a null-ptr-deref error:
https://syzkaller.appspot.com/bug?id=bb281e89381b9ed55728c274447a575e69a96c35
ovl_dentry_revalidate_common() can be called in rcu-walk mode.
As document said, "in rcu-walk mode, d_parent and d_inode should not be
used without care". Check inode here to protect access under rcu-walk
mode.
Fixes: bccece1ead36 ("ovl: allow remote upper")
Reported-by: syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
---
fs/overlayfs/super.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
Comments
On Thu, Nov 24, 2022 at 05:26:02PM +0800, Chen Zhongjin wrote: > syzkaller reported a null-ptr-deref error: > https://syzkaller.appspot.com/bug?id=bb281e89381b9ed55728c274447a575e69a96c35 > > ovl_dentry_revalidate_common() can be called in rcu-walk mode. > As document said, "in rcu-walk mode, d_parent and d_inode should not be > used without care". Check inode here to protect access under rcu-walk > mode. > > Fixes: bccece1ead36 ("ovl: allow remote upper") > Reported-by: syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com > Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com> Hi, Thanks for the quick analysis and patch. I simplified the patch a bit without changing the attribution. Thanks, Miklos ---- From: Chen Zhongjin <chenzhongjin@huawei.com> Subject: ovl: fix use inode directly in rcu-walk mode ovl_dentry_revalidate_common() can be called in rcu-walk mode. As document said, "in rcu-walk mode, d_parent and d_inode should not be used without care". Check inode here to protect access under rcu-walk mode. Fixes: bccece1ead36 ("ovl: allow remote upper") Reported-by: syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com> Cc: <stable@vger.kernel.org> # v5.7 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> --- fs/overlayfs/super.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -139,11 +139,16 @@ static int ovl_dentry_revalidate_common( unsigned int flags, bool weak) { struct ovl_entry *oe = dentry->d_fsdata; + struct inode *inode = d_inode_rcu(dentry); struct dentry *upper; unsigned int i; int ret = 1; - upper = ovl_dentry_upper(dentry); + /* Careful in RCU mode */ + if (!inode) + return -ECHILD; + + upper = ovl_i_dentry_upper(inode); if (upper) ret = ovl_revalidate_real(upper, flags, weak);
On 2022/11/24 20:45, Miklos Szeredi wrote: > On Thu, Nov 24, 2022 at 05:26:02PM +0800, Chen Zhongjin wrote: >> syzkaller reported a null-ptr-deref error: >> https://syzkaller.appspot.com/bug?id=bb281e89381b9ed55728c274447a575e69a96c35 >> >> ovl_dentry_revalidate_common() can be called in rcu-walk mode. >> As document said, "in rcu-walk mode, d_parent and d_inode should not be >> used without care". Check inode here to protect access under rcu-walk >> mode. >> >> Fixes: bccece1ead36 ("ovl: allow remote upper") >> Reported-by: syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com >> Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com> > Hi, > > Thanks for the quick analysis and patch. > > I simplified the patch a bit without changing the attribution. > > Thanks, > Miklos > > ---- > From: Chen Zhongjin <chenzhongjin@huawei.com> > Subject: ovl: fix use inode directly in rcu-walk mode > > ovl_dentry_revalidate_common() can be called in rcu-walk mode. As document > said, "in rcu-walk mode, d_parent and d_inode should not be used without > care". > > Check inode here to protect access under rcu-walk mode. > > Fixes: bccece1ead36 ("ovl: allow remote upper") > Reported-by: syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com > Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com> > Cc: <stable@vger.kernel.org> # v5.7 > Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> > --- > fs/overlayfs/super.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > --- a/fs/overlayfs/super.c > +++ b/fs/overlayfs/super.c > @@ -139,11 +139,16 @@ static int ovl_dentry_revalidate_common( > unsigned int flags, bool weak) > { > struct ovl_entry *oe = dentry->d_fsdata; > + struct inode *inode = d_inode_rcu(dentry); > struct dentry *upper; > unsigned int i; > int ret = 1; > > - upper = ovl_dentry_upper(dentry); > + /* Careful in RCU mode */ > + if (!inode) > + return -ECHILD; > + > + upper = ovl_i_dentry_upper(inode); > if (upper) > ret = ovl_revalidate_real(upper, flags, weak); > Thanks for review! LGTM Best, Chen
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index a29a8afe9b26..d61ab192dfd9 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -139,11 +139,19 @@ static int ovl_dentry_revalidate_common(struct dentry *dentry, unsigned int flags, bool weak) { struct ovl_entry *oe = dentry->d_fsdata; + struct inode *inode; struct dentry *upper; unsigned int i; int ret = 1; - upper = ovl_dentry_upper(dentry); + if (flags & LOOKUP_RCU) { + inode = d_inode_rcu(dentry); + if (!inode) + return -ECHILD; + upper = ovl_upperdentry_dereference(OVL_I(inode)); + } else + upper = ovl_dentry_upper(dentry); + if (upper) ret = ovl_revalidate_real(upper, flags, weak);