Received: by 10.223.164.221 with SMTP id h29csp2125488wrb; Thu, 2 Nov 2017 06:18:21 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Q/GeDkU6DznJI3XzTmkMsCOO6TxaMoa+BDlp1ycIHuS/Ztp1t6qCz8VphWUe/vtxGKrr5P X-Received: by 10.84.138.131 with SMTP id 3mr3173946plp.238.1509628701432; Thu, 02 Nov 2017 06:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509628701; cv=none; d=google.com; s=arc-20160816; b=ddxOpnuxtGmrXvPjyEFlVwilwoXRkqlybv2iX8zWEbXUSgVheC7pBGOnWzfMjJFaV4 nmtSjd3nngvRg4hjVKnKrqo1erYSb8zkM9s8cjqNmprDsDqDLv+mZxGEdPwCjXOprYaj DCoSaZm8dRFI2bmiCmjpAxX9BRrSEnqXnQVPXB5c9TyxpezxZ0za0wsA4gFftuIi/drg Z6aSHYTh+DbDQwV7MY9uu1wrlS4/+9VSOoK4plDNG1d3URXAWIkHixPb4VI+kKdw67QQ lUvDRg4ppeOv1RlAyZLw7N8xyiUvFx7V922kZ9Lm5mwPlw5Oak3RtZJgS+8KGZuMT5Vu q0Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=4iJl+hgNnQKkhLMcHs4ZXe1hGw/cYK6RMqJKa0BAr7A=; b=M4HIm4mLR143GIBoSnbLNYwyMq3tpzXYaEJoRb1YZZ5tX2NETz4Oabhz/P30Oldbnv /8WDYAoh/m3YP7cs2aSVlTwDdfj+DCajzdduSH5mP21Sqs/hYhq2+PB1DvN5IDhP0S/q H3LLGo0VpN6LLxZ/G3VszQA4uqe2k7ZHwHRHEgZjHoAuiY3TWEkUtXidJaeh3bAq7JG8 yOCuoGi8CGldydFfNO9LsaVVFrlFLYgdnlG8rlLG5eJSzqxS7/Ge3O3m2AlBv0/q0kgR 4vs1fkihy/alOB0mSLp46DGQzm/72T2T+nsHTVn0j0Cy13avE+X2yKKRb+ysseZ+zK1Z CFDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si3505226pgs.96.2017.11.02.06.18.07; Thu, 02 Nov 2017 06:18:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932446AbdKBNPu (ORCPT + 96 others); Thu, 2 Nov 2017 09:15:50 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:46316 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755549AbdKBNPt (ORCPT ); Thu, 2 Nov 2017 09:15:49 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA2DFcU9022562 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 13:15:38 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vA2DFbbH012705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 13:15:37 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vA2DFbk9025262; Thu, 2 Nov 2017 13:15:37 GMT Received: from [192.168.1.74] (/99.156.91.244) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Nov 2017 06:15:36 -0700 Subject: Re: [Jfs-discussion] [PATCH] jfs: Add missing NULL pointer check in __get_metapage To: Juerg Haefliger , jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20171004082441.2405-1-juerg.haefliger@canonical.com> <1dbf4a54-968f-0ca7-da96-e262c653fecb@canonical.com> <778bc3d1-4bf4-ed83-3cc3-19d6efb5cceb@canonical.com> From: Dave Kleikamp Message-ID: <0c8c1f0e-c3af-308f-aee0-d7b8c14f45d8@oracle.com> Date: Thu, 2 Nov 2017 08:15:36 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <778bc3d1-4bf4-ed83-3cc3-19d6efb5cceb@canonical.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/02/2017 01:59 AM, Juerg Haefliger wrote: > > > On 10/30/2017 11:13 PM, Dave Kleikamp wrote: >> On 10/25/2017 02:50 AM, Juerg Haefliger wrote: >>> Is this a patch you might consider? >> >> Sorry it's taken me so long to respond. >> >> I don't think this is the right fix. A failed allocation will still >> result in a null pointer dereference by the caller, __get_metapage(). I >> think the check needs to be put there. Like this: >> >> --- a/fs/jfs/jfs_metapage.c >> +++ b/fs/jfs/jfs_metapage.c >> @@ -663,6 +663,8 @@ struct metapage *__get_metapage(struct inode *inode, >> unsigned long lblock, >> } else { >> INCREMENT(mpStat.pagealloc); >> mp = alloc_metapage(GFP_NOFS); >> + if (!mp) >> + goto unlock; >> mp->page = page; >> mp->sb = inode->i_sb; >> mp->flag = 0; > > I don't understand. This is part of the patch that I sent. Doh! How'd I miss that? > > >> >> Furthermore, it looks like all the callers of __get_metapage() check for >> a null return, so I'm not sure we need to handle the error at this >> point. I might have to look a bit harder at that, since there are many >> callers. > > I don't understand this either :-) Yes, the callers do check for a null > pointer but things blow up (in __get_metapage) before that check without > the above fix. Yeah, the fix to __get_metapage() is necessary. I'm not convinced the first part of the patch, to alloc_metapage(), is necessary. > > ...Juerg > > >> >> Thanks, >> Shaggy >> >>> >>> Thanks >>> ...Juerg >>> >>> >>> On 10/04/2017 10:24 AM, Juerg Haefliger wrote: >>>> alloc_metapage can return a NULL pointer so check for that. And also emit >>>> an error message if that happens. >>>> >>>> Signed-off-by: Juerg Haefliger >>>> --- >>>> fs/jfs/jfs_metapage.c | 20 +++++++++++++------- >>>> 1 file changed, 13 insertions(+), 7 deletions(-) >>>> >>>> diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c >>>> index 1c4b9ad4d7ab..00f21af66872 100644 >>>> --- a/fs/jfs/jfs_metapage.c >>>> +++ b/fs/jfs/jfs_metapage.c >>>> @@ -187,14 +187,18 @@ static inline struct metapage *alloc_metapage(gfp_t gfp_mask) >>>> { >>>> struct metapage *mp = mempool_alloc(metapage_mempool, gfp_mask); >>>> >>>> - if (mp) { >>>> - mp->lid = 0; >>>> - mp->lsn = 0; >>>> - mp->data = NULL; >>>> - mp->clsn = 0; >>>> - mp->log = NULL; >>>> - init_waitqueue_head(&mp->wait); >>>> + if (!mp) { >>>> + jfs_err("mempool_alloc failed!\n"); >>>> + return NULL; >>>> } >>>> + >>>> + mp->lid = 0; >>>> + mp->lsn = 0; >>>> + mp->data = NULL; >>>> + mp->clsn = 0; >>>> + mp->log = NULL; >>>> + init_waitqueue_head(&mp->wait); >>>> + >>>> return mp; >>>> } >>>> >>>> @@ -663,6 +667,8 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock, >>>> } else { >>>> INCREMENT(mpStat.pagealloc); >>>> mp = alloc_metapage(GFP_NOFS); >>>> + if (!mp) >>>> + goto unlock; >>>> mp->page = page; >>>> mp->sb = inode->i_sb; >>>> mp->flag = 0; >>>> > From 1582936626463752223@xxx Thu Nov 02 07:00:05 +0000 2017 X-GM-THRID: 1580314796840603396 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread