From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753927AbbICKpk (ORCPT ); Thu, 3 Sep 2015 06:45:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53927 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751914AbbICKpj (ORCPT ); Thu, 3 Sep 2015 06:45:39 -0400 Date: Thu, 3 Sep 2015 06:45:37 -0400 From: Brian Foster To: Colin King Cc: Dave Chinner , xfs@oss.sgi.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xfs: fix null pointer dereference when mapping is NULL Message-ID: <20150903104537.GA46225@bfoster.bfoster> References: <1441274260-10120-1-git-send-email-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1441274260-10120-1-git-send-email-colin.king@canonical.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 03, 2015 at 10:57:40AM +0100, Colin King wrote: > From: Colin Ian King > > xfs_vm_set_page_dirty checks to see if mapping is NULL however > before this unlikely check it already dereferenced mapping when > initializing inode. Move the inode initialization after the mapping > null check to avoid a potential null pointer dereference. > > Fixes: 22e757a49cf0 ("xfs: don't dirty buffers beyond EOF") > Signed-off-by: Colin Ian King > --- Reviewed-by: Brian Foster > fs/xfs/xfs_aops.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c > index c77499b..d15ae85 100644 > --- a/fs/xfs/xfs_aops.c > +++ b/fs/xfs/xfs_aops.c > @@ -1935,7 +1935,7 @@ xfs_vm_set_page_dirty( > struct page *page) > { > struct address_space *mapping = page->mapping; > - struct inode *inode = mapping->host; > + struct inode *inode; > loff_t end_offset; > loff_t offset; > int newly_dirty; > @@ -1944,6 +1944,7 @@ xfs_vm_set_page_dirty( > if (unlikely(!mapping)) > return !TestSetPageDirty(page); > > + inode = mapping->host; > end_offset = i_size_read(inode); > offset = page_offset(page); > > -- > 2.5.0 > > _______________________________________________ > xfs mailing list > xfs@oss.sgi.com > http://oss.sgi.com/mailman/listinfo/xfs