Received: by 10.223.164.221 with SMTP id h29csp2156694wrb; Thu, 2 Nov 2017 06:46:02 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TBhp5LH9+0G35gnP45KIv2kIStX089SCCCUdFyKwOqHDXjhSX4Ip15m2k0xMM/Xb7+2VU8 X-Received: by 10.159.245.150 with SMTP id a22mr2344657pls.165.1509630362507; Thu, 02 Nov 2017 06:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509630362; cv=none; d=google.com; s=arc-20160816; b=hN9eyFGgkD4PMN2jJIT5GTDFtVWO190w9W+uKGGM8yilej2p05UIV1olvh7bAO81Of ojAVDKLUaQB3N1WtDhmOcB3Vcr/q9WikKYmvL7THDkeh2XkCIOxDVLboccJAlhveo0WV PTLBGQmk90/nOyzHNic3h+ynj+JeU6eiCn5+TyrVthSFmlvPQCPP4HYmEcPj2BJmvbVl Oi1K0Ke0UyGUCHmC/TLhJ5AAP+G+MjNLqyl2Vi+gvhsUuB2Fc1ACgSn597QOG27QIcO/ mvSZk5mi3eTjhfg16D/J61FkBPLbRRTwy3RJFkBvNWGmu8Q5fzNmvTZA1uNFERwBIP13 3QhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=0uamZrGJ8ph8KSFUi3Guy3qGsKsS7bhjsDUtCeVstgo=; b=fNRHLIR8etPzbz1ZP1gWzJuh7/g0iWpRU9yTLCPXVvFQ6Y0z49VHsL9Gp2htaDWGDZ at0anTttlZNh1Gxz0EOf4xUV1Sg3uQydmeqOYtijGjH+mjcHOmRo1H1/P6JwADWpwRkj hi0YkNEUbjYEYcE3jsaOW1vs5XqkinTAXRCat1wqFLaG7VNGkxnZUeF9jUT7SvxBypUp IV0LOq5V2wxPEdd1u3KnfIt/NXCU3l4S4dUkcefV8AjbMDG1CcoAntG0yJOQ1bm0UOgd XfNjP4aQZBuCuwThY+ib6gdZPFk4fqsGqtmHLNyU+iZYI5FVtsf+6sOH0hIEsLxeur+T 2WVA== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t6si3620796pgr.822.2017.11.02.06.45.48; Thu, 02 Nov 2017 06:46:02 -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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933146AbdKBNnr (ORCPT + 96 others); Thu, 2 Nov 2017 09:43:47 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:33767 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755530AbdKBNnq (ORCPT ); Thu, 2 Nov 2017 09:43:46 -0400 Received: from mail-wm0-f70.google.com ([74.125.82.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1eAFmb-0003sf-9w for linux-kernel@vger.kernel.org; Thu, 02 Nov 2017 13:43:45 +0000 Received: by mail-wm0-f70.google.com with SMTP id 64so2908631wme.12 for ; Thu, 02 Nov 2017 06:43:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=0uamZrGJ8ph8KSFUi3Guy3qGsKsS7bhjsDUtCeVstgo=; b=Atmc5ZwKDj7vWfh4xqjjHRVZLuQlIHvNZrZ3+GS9o8dQidRPfeQW4x0tNDdpZja1s9 26to8dSfLGMFSi+c3MyUkVROFru4mrdNHMsFOXXfWawoFnfJeEHCMLHjzEU0ozGdvVoM 5iDEQLuz8PoNFSRgxU4UerM5s+tGBGvY6mytRVc7BKXZZz0J4gqdKPPnmgf0sDKC9PZW 1RbxqB5xiHjAyI0N6A3YrwcyMi9En8ZUTZd73VtDW6rw1yRZrkr2t1Yuk7PbuG/oTbgm m5Xgtdr9YZ84lrurjZ8WKE25qDnaIl1facD6+ir47nell+nXDBd+0YeY5KzvNXzGeehz cELA== X-Gm-Message-State: AMCzsaXA6i1loQQF+tTdeDONKt1JVVyE5RQzB79K361V2Tx+tHPNZI4m pL5PEu8m1A8nosgykpeAKUtBQcBV0bVQKvFLK/5EG/SZq4JB0uBCai2zi7ZSIVkCL4a1EWk7SeK 2yxUo3d3XuuFp3Ful5VWt3E/RfGcUGFn49rvyBx8b5Q== X-Received: by 10.80.145.13 with SMTP id e13mr4409133eda.22.1509630224722; Thu, 02 Nov 2017 06:43:44 -0700 (PDT) X-Received: by 10.80.145.13 with SMTP id e13mr4409119eda.22.1509630224488; Thu, 02 Nov 2017 06:43:44 -0700 (PDT) Received: from [192.168.1.99] (adsl-84-227-115-101.adslplus.ch. [84.227.115.101]) by smtp.gmail.com with ESMTPSA id u51sm2926167edm.59.2017.11.02.06.43.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Nov 2017 06:43:43 -0700 (PDT) Subject: Re: [Jfs-discussion] [PATCH] jfs: Add missing NULL pointer check in __get_metapage To: Dave Kleikamp , 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> <0c8c1f0e-c3af-308f-aee0-d7b8c14f45d8@oracle.com> From: Juerg Haefliger Message-ID: <50f61041-7507-6410-ddf5-36892759be8b@canonical.com> Date: Thu, 2 Nov 2017 14:43:42 +0100 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: <0c8c1f0e-c3af-308f-aee0-d7b8c14f45d8@oracle.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="sIKMBOG2ROdp3UrGXsFCGoGiMnVFTMw0l" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --sIKMBOG2ROdp3UrGXsFCGoGiMnVFTMw0l Content-Type: multipart/mixed; boundary="3rvg9XUGpfGQcGwHdCvABJDAs1gxd9CLf"; protected-headers="v1" From: Juerg Haefliger To: Dave Kleikamp , jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org Message-ID: <50f61041-7507-6410-ddf5-36892759be8b@canonical.com> Subject: Re: [Jfs-discussion] [PATCH] jfs: Add missing NULL pointer check in __get_metapage References: <20171004082441.2405-1-juerg.haefliger@canonical.com> <1dbf4a54-968f-0ca7-da96-e262c653fecb@canonical.com> <778bc3d1-4bf4-ed83-3cc3-19d6efb5cceb@canonical.com> <0c8c1f0e-c3af-308f-aee0-d7b8c14f45d8@oracle.com> In-Reply-To: <0c8c1f0e-c3af-308f-aee0-d7b8c14f45d8@oracle.com> --3rvg9XUGpfGQcGwHdCvABJDAs1gxd9CLf Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 11/02/2017 02:15 PM, Dave Kleikamp wrote: > 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 *ino= de, >>> unsigned long lblock, >>> } else { >>> INCREMENT(mpStat.pagealloc); >>> mp =3D alloc_metapage(GFP_NOFS); >>> + if (!mp) >>> + goto unlock; >>> mp->page =3D page; >>> mp->sb =3D inode->i_sb; >>> mp->flag =3D 0; >> >> I don't understand. This is part of the patch that I sent. >=20 > 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 man= y >>> callers. >> >> I don't understand this either :-) Yes, the callers do check for a nul= l >> pointer but things blow up (in __get_metapage) before that check witho= ut >> the above fix. >=20 > Yeah, the fix to __get_metapage() is necessary. I'm not convinced the > first part of the patch, to alloc_metapage(), is necessary. It's not. I just thought it'd be nice to get some sort of notification in the log when the alloc fails. But if the callers log it then that's fi= ne. =2E..Juerg >> >> ...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 als= o 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 =3D mempool_alloc(metapage_mempool, gfp_mask)= ; >>>>> =20 >>>>> - if (mp) { >>>>> - mp->lid =3D 0; >>>>> - mp->lsn =3D 0; >>>>> - mp->data =3D NULL; >>>>> - mp->clsn =3D 0; >>>>> - mp->log =3D NULL; >>>>> - init_waitqueue_head(&mp->wait); >>>>> + if (!mp) { >>>>> + jfs_err("mempool_alloc failed!\n"); >>>>> + return NULL; >>>>> } >>>>> + >>>>> + mp->lid =3D 0; >>>>> + mp->lsn =3D 0; >>>>> + mp->data =3D NULL; >>>>> + mp->clsn =3D 0; >>>>> + mp->log =3D NULL; >>>>> + init_waitqueue_head(&mp->wait); >>>>> + >>>>> return mp; >>>>> } >>>>> =20 >>>>> @@ -663,6 +667,8 @@ struct metapage *__get_metapage(struct inode *i= node, unsigned long lblock, >>>>> } else { >>>>> INCREMENT(mpStat.pagealloc); >>>>> mp =3D alloc_metapage(GFP_NOFS); >>>>> + if (!mp) >>>>> + goto unlock; >>>>> mp->page =3D page; >>>>> mp->sb =3D inode->i_sb; >>>>> mp->flag =3D 0; >>>>> >> --3rvg9XUGpfGQcGwHdCvABJDAs1gxd9CLf-- --sIKMBOG2ROdp3UrGXsFCGoGiMnVFTMw0l Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQI7BAEBCAAlBQJZ+yEOHhxqdWVyZy5oYWVmbGlnZXJAY2Fub25pY2FsLmNvbQAK CRB1TDqW+fi0jJWPD/4n7WszNth+vevocQmgpzUBD9uNrSstSZda/Dx0YPYB5Wve c1kX8IuDhmuKJ7268woewKIs8mziOxrcjIcYTGzWPISVhU6ZXChF2q/405qrbidp ukVlNhy9IfOP8xrw1DIFQtLvSbEbuHyYJJ3LmMMvwmTOmGcSNH1Ct2RPcIUu1Biq xPzQIteztdBupw9Xw51tjI8vEdZTon2TE1nFOTZJ2YoSVaSo0rE+xi182e/620kZ 1hqIKhtx+VtmDZiBh2OFSnsdqHtzmwy4Nqd76ZAAN9oCIJYUbCIgSWxGii1LeMdr Gjw0O3LgUGo6YgIYhAE9o8Xk6KInznG7UZBodXVVV+jM5/i8Z5n5p3ogv/Dj8l3l KeeAiBOpYBXOjyT2J+l8t34Bgoh7etAhWNR77d1M4em31RltyDcvMWRYQ8ojgruI Df/XZxWECWsiN4/HKZDaLmjNDPHM+Jq/HVE3dRYBFZBoBlBMOog2WM18++g59/R9 MkSNBF+NDHzrBejztv/jcCLe1aDAff4nKt9gV0PDT+ymukGylEhkAKlyotoWzqe4 vvR3OkJU0jiS+LJ7EKCRPpLO90z6N46ZKuJi7CcCesSomX38woaAOMmn9iR7KkNo cO5C6gVptjKtA3F9ulGvFPFZyKhnamXWaLBANWvHQ9cKQ/iQnAnyR240s04ldg== =MP7x -----END PGP SIGNATURE----- --sIKMBOG2ROdp3UrGXsFCGoGiMnVFTMw0l-- From 1582960424983760504@xxx Thu Nov 02 13:18:21 +0000 2017 X-GM-THRID: 1580314796840603396 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread