Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 047CF23AF for ; Wed, 28 Dec 2022 16:58:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78DD5C433D2; Wed, 28 Dec 2022 16:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672246695; bh=BIFGjKClbac489+GA+XbQXaq0314xfuSsCynpLbgrEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pk9cUmVOjjsG8/UNIFOEu2b97ym8zKfJwSfuKMPlmIq3cTVNgP1iKIyItgC/lpl2T tH50CUJTwh1aGwZi5/RY7eD82Vfw78xHPQuTZK64BfjX7GK6iqaxVEqBgrf2FeNjGv oEsYFhKCOqWKQbWwtBcEGoQz/fUQ9Ub8vK/O8xyY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chen Zhongjin , Miklos Szeredi , syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com Subject: [PATCH 6.1 1130/1146] ovl: fix use inode directly in rcu-walk mode Date: Wed, 28 Dec 2022 15:44:29 +0100 Message-Id: <20221228144400.836615899@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221228144330.180012208@linuxfoundation.org> References: <20221228144330.180012208@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Chen Zhongjin commit 672e4268b2863d7e4978dfed29552b31c2f9bd4e upstream. 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-and-tested-by: syzbot+a4055c78774bbf3498bb@syzkaller.appspotmail.com Signed-off-by: Chen Zhongjin Cc: # v5.7 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- 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);