From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AACB1C4727C for ; Thu, 1 Oct 2020 09:28:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E5532176B for ; Thu, 1 Oct 2020 09:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731884AbgJAJ2n (ORCPT ); Thu, 1 Oct 2020 05:28:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:33524 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbgJAJ2n (ORCPT ); Thu, 1 Oct 2020 05:28:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8FC8DAC35; Thu, 1 Oct 2020 09:28:41 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 37EE91E12EF; Thu, 1 Oct 2020 11:28:41 +0200 (CEST) Date: Thu, 1 Oct 2020 11:28:41 +0200 From: Jan Kara To: Anmol Karn Cc: jack@suse.cz, jeffm@suse.com, linux-kernel@vger.kernel.org, reiserfs-devel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, syzkaller-bugs@googlegroups.com, syzbot+9b33c9b118d77ff59b6f@syzkaller.appspotmail.com Subject: Re: [Linux-kernel-mentees] [PATCH] fs: reiserfs: xattr: Fix null pointer derefernce in open_xa_root() Message-ID: <20201001092841.GC17860@quack2.suse.cz> References: <20201001090547.431840-1-anmol.karan123@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201001090547.431840-1-anmol.karan123@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 01-10-20 14:35:47, Anmol Karn wrote: > d_really_is_negative() checks for the dentry->d_inode whether it's NULL > or not, but in open_xa_root(), when it checks 'privroot->d_inode', it > doesn't check whether privroot is NULL or not, this leads to a null > pointer dereference while calling it from open_xa_dir() while > initializing xaroot. > > - fs/reiserfs/xattr.c > The bug seems to get triggered at this line: > > if (d_really_is_negative(privroot)) > return ERR_PTR(-EOPNOTSUPP); > > Fix it by adding a NULL check for privroot. > > Reported-and-tested-by: syzbot+9b33c9b118d77ff59b6f@syzkaller.appspotmail.com > Link: https://syzkaller.appspot.com/bug?extid=9b33c9b118d77ff59b6f > Signed-off-by: Anmol Karn Thanks for the patch! I've already fixed the problem myself (slightly differently) but I'll comment about your patch below for educational purposes :). See https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/commit/?h=for_next&id=c2bb80b8bdd04dfe32364b78b61b6a47f717af52 > diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c > index 28b241cd6987..a75480d0ee7e 100644 > --- a/fs/reiserfs/xattr.c > +++ b/fs/reiserfs/xattr.c > @@ -121,8 +121,9 @@ static struct dentry *open_xa_root(struct super_block *sb, int flags) > struct dentry *privroot = REISERFS_SB(sb)->priv_root; > struct dentry *xaroot; > > - if (d_really_is_negative(privroot)) > + if (!privroot || d_really_is_negative(privroot)) { > return ERR_PTR(-EOPNOTSUPP); I don't think EOPNOTSUPP is correct return code for !privroot case. AFAICS it would propagate out of reiserfs xattr code and would result in denying access to lookup_one_len() so xattr dir could never be initialized for such filesystem. So we need to return 0 (success, no xattrs present) in this case and because this is just a special case when we are initializing xattr dir and recurse back into xattr code, I've decided to perform this check directly in reiserfs_xattr_get(). > + } There's no need for additional braces in this 'if'. > > inode_lock_nested(d_inode(privroot), I_MUTEX_XATTR); Honza -- Jan Kara SUSE Labs, CR From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C95CEC47420 for ; Thu, 1 Oct 2020 09:28:47 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1D82D2176B for ; Thu, 1 Oct 2020 09:28:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D82D2176B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id C47E9844FB; Thu, 1 Oct 2020 09:28:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cSs4z-z36rGL; Thu, 1 Oct 2020 09:28:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2102F84471; Thu, 1 Oct 2020 09:28:46 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0AA0EC016F; Thu, 1 Oct 2020 09:28:46 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id B9C73C0051 for ; Thu, 1 Oct 2020 09:28:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A9142853B9 for ; Thu, 1 Oct 2020 09:28:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VlGQ4qTkO48x for ; Thu, 1 Oct 2020 09:28:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by whitealder.osuosl.org (Postfix) with ESMTPS id ADD9C8347D for ; Thu, 1 Oct 2020 09:28:43 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8FC8DAC35; Thu, 1 Oct 2020 09:28:41 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 37EE91E12EF; Thu, 1 Oct 2020 11:28:41 +0200 (CEST) Date: Thu, 1 Oct 2020 11:28:41 +0200 From: Jan Kara To: Anmol Karn Message-ID: <20201001092841.GC17860@quack2.suse.cz> References: <20201001090547.431840-1-anmol.karan123@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201001090547.431840-1-anmol.karan123@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Cc: jack@suse.cz, syzbot+9b33c9b118d77ff59b6f@syzkaller.appspotmail.com, jeffm@suse.com, syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org, reiserfs-devel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [Linux-kernel-mentees] [PATCH] fs: reiserfs: xattr: Fix null pointer derefernce in open_xa_root() X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" On Thu 01-10-20 14:35:47, Anmol Karn wrote: > d_really_is_negative() checks for the dentry->d_inode whether it's NULL > or not, but in open_xa_root(), when it checks 'privroot->d_inode', it > doesn't check whether privroot is NULL or not, this leads to a null > pointer dereference while calling it from open_xa_dir() while > initializing xaroot. > > - fs/reiserfs/xattr.c > The bug seems to get triggered at this line: > > if (d_really_is_negative(privroot)) > return ERR_PTR(-EOPNOTSUPP); > > Fix it by adding a NULL check for privroot. > > Reported-and-tested-by: syzbot+9b33c9b118d77ff59b6f@syzkaller.appspotmail.com > Link: https://syzkaller.appspot.com/bug?extid=9b33c9b118d77ff59b6f > Signed-off-by: Anmol Karn Thanks for the patch! I've already fixed the problem myself (slightly differently) but I'll comment about your patch below for educational purposes :). See https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/commit/?h=for_next&id=c2bb80b8bdd04dfe32364b78b61b6a47f717af52 > diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c > index 28b241cd6987..a75480d0ee7e 100644 > --- a/fs/reiserfs/xattr.c > +++ b/fs/reiserfs/xattr.c > @@ -121,8 +121,9 @@ static struct dentry *open_xa_root(struct super_block *sb, int flags) > struct dentry *privroot = REISERFS_SB(sb)->priv_root; > struct dentry *xaroot; > > - if (d_really_is_negative(privroot)) > + if (!privroot || d_really_is_negative(privroot)) { > return ERR_PTR(-EOPNOTSUPP); I don't think EOPNOTSUPP is correct return code for !privroot case. AFAICS it would propagate out of reiserfs xattr code and would result in denying access to lookup_one_len() so xattr dir could never be initialized for such filesystem. So we need to return 0 (success, no xattrs present) in this case and because this is just a special case when we are initializing xattr dir and recurse back into xattr code, I've decided to perform this check directly in reiserfs_xattr_get(). > + } There's no need for additional braces in this 'if'. > > inode_lock_nested(d_inode(privroot), I_MUTEX_XATTR); Honza -- Jan Kara SUSE Labs, CR _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees