From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754714AbdKBG7P (ORCPT ); Thu, 2 Nov 2017 02:59:15 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54690 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750883AbdKBG7N (ORCPT ); Thu, 2 Nov 2017 02:59:13 -0400 X-Google-Smtp-Source: ABhQp+Q+9q945yrciCLUOD+fxliVWds6lRq4kW3q9kjipf+Wxi2MDGp23Id07GVIn77ZdoSTs3/8og== 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> From: Juerg Haefliger Message-ID: <778bc3d1-4bf4-ed83-3cc3-19d6efb5cceb@canonical.com> Date: Thu, 2 Nov 2017 07:59:09 +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: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="spMKUtu6qeU420WaSXuXI6WIeTBJu5ej1" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --spMKUtu6qeU420WaSXuXI6WIeTBJu5ej1 Content-Type: multipart/mixed; boundary="LWfRjL3iqIQT1ebG5cu4PFg0bcalL6GMx"; protected-headers="v1" From: Juerg Haefliger To: Dave Kleikamp , jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org Message-ID: <778bc3d1-4bf4-ed83-3cc3-19d6efb5cceb@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> In-Reply-To: --LWfRjL3iqIQT1ebG5cu4PFg0bcalL6GMx Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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? >=20 > Sorry it's taken me so long to respond. >=20 > 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: >=20 > --- 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 =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 > Furthermore, it looks like all the callers of __get_metapage() check fo= r > 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. =2E..Juerg >=20 > Thanks, > Shaggy >=20 >> >> 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(g= fp_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 *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; >>> --LWfRjL3iqIQT1ebG5cu4PFg0bcalL6GMx-- --spMKUtu6qeU420WaSXuXI6WIeTBJu5ej1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQI7BAEBCAAlBQJZ+sI9HhxqdWVyZy5oYWVmbGlnZXJAY2Fub25pY2FsLmNvbQAK CRB1TDqW+fi0jMVgD/wOQQVeGi4AK5VgmDyIOJFMILf3ifAgOFTGDtIxZWFyf/fH 5V1yMkofSQL4KC+YbhXiBjKeElnVgZLQpQkaqI9qfaarGeZIdml6MWg7QVJrxo6Y qtrsttAiDFRePkAy11FTLvzwLGS31WmPGWXcHdGW7pL7h4SdqB0ylSoyEIgReFsh jYEt95zMwpC+n9EkTMWYkuFaJqr07WlHEDz2yVw7yIbmGbOS1mi09YL5HnWh8UZU fpIJKVw/UFKkcO2cVFJ1IZW2CGVZfboiNFoAMN2BmTr8aBv/Q7l9woOdlcRrKXZW l2Gas3uLsmOPri4LWQtKKJW4rG7Qpc3l/AVcJ8H6oDaVz5NYoDvQ3+j1C9HMJaoy eEihkJlFiqurxcRXA+p0xXB0WE8NtfY6sVIc/VGTEGOOH1fytlQjhNAjn1Xy4YWB aP1Nr/L32aCH2xwGwEvER4wnCSfOpdj94+3ZbGFUiB0+NHxIbui69cH00CEEwzkg qF4DXD1llbcvXZeTddqkZq3axPBRaaQPM9i7mKwbax9YgUKtBe45gHduD2A0icx2 P+iW5wcVnY93w4umYmOjrrb7Jq4NjWj1KcQm4r47YV0WxNW4seTZ2vfpZ9es41Z9 0m9Zs5sZs3KWY7EsGF5iuBuQkHVu+Alc91XOq6kJQprFrhJjllB3sMUbZ0MHMw== =k8UF -----END PGP SIGNATURE----- --spMKUtu6qeU420WaSXuXI6WIeTBJu5ej1--