Received: by 10.192.165.148 with SMTP id m20csp25457imm; Thu, 19 Apr 2018 15:18:32 -0700 (PDT) X-Google-Smtp-Source: AIpwx483eyw2lI/rZBUPfrRsIXRuZcG6A8sJyfjoKWKTzg/Ccormr1wo6fFFjbA3/TPiJBT6TfCN X-Received: by 2002:a17:902:8685:: with SMTP id g5-v6mr7781063plo.46.1524176312640; Thu, 19 Apr 2018 15:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524176312; cv=none; d=google.com; s=arc-20160816; b=GCK+BoK0XvTHXojrZV59QjgKBU0JB1WIjzcRHlN44Gw0NUk31VsTRS8PyF/YtG9wau 4XHYMw2eJr+YICZ76yoSXAtsWZju12/n3pNXRp8q3FtU9Wzplvg3GyQSSzatP8yhj0uu 5YKI+zHEdZUrEo6JBnOzCRSp0QlqV2Y0T9/YsQGo+OgJceocZNrHRrE58ZcRhDHC2NzT MvGHsOVQntwFymU++3VlKowHPkZrKkv5RBQfYZaZeafNtukgCsTCi/r9AsmekUIA8P7b W+mdOvnEoJChZYzu8T22zYp/JSMWs3bNW25JwKw12CMTtIHmMnu5hV9TTtdyHG0EXvuA tyuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:references :in-reply-to:subject:cc:date:to:from:arc-authentication-results; bh=5ZttJ2E9ClVE+y2GgK4QpI89z61fl5SfdNf8pBWYqfM=; b=tqewK2E2MUeKahESNSiNdA1K1hdObDu6lZzFQRHVXIIapBJ3VfNRGmuoG08WJMIDg2 hWmghtTsJEF4VNReILR1NOghJRS/4CvgerWNNqvNcOp60CbQTTvpFG/k8dscg+AfCv2x rPOzbmh5E8vHHBR/eL3FuyxX21N0KoixmA2Nx2sORYyfIV+BLzfhALeCEEs4k+haKd5x cH0WcM1HocHcXJSUDkay20ChMaVlQmAb89ZPN26IntOagUAnNwpNR447MBRXFxLQTXVJ WYcjbncSqsXZGvu5UD3MsoNThJFj7ZgYWSP83NgHw1/tVTr+Ea+ffCIMVoSku28rk+dW 2WXA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f96-v6si4373321plb.418.2018.04.19.15.18.13; Thu, 19 Apr 2018 15:18:32 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753691AbeDSWQ0 (ORCPT + 99 others); Thu, 19 Apr 2018 18:16:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:46206 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753500AbeDSWQZ (ORCPT ); Thu, 19 Apr 2018 18:16:25 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2631EAC29; Thu, 19 Apr 2018 22:16:23 +0000 (UTC) From: NeilBrown To: Thomas Gleixner , Mike Snitzer Date: Fri, 20 Apr 2018 08:16:10 +1000 Cc: LKML , Kees Cook , Segher Boessenkool , Kernel Hardening , Andrew Morton , Boris Brezillon , Richard Weinberger , David Woodhouse , Alasdair Kergon , Anton Vorontsov , Colin Cross , Tony Luck Subject: Re: [patch V2 7/8] dm verity fec: Check result of init_rs() In-Reply-To: References: <20180419100441.548834519@linutronix.de> <20180419100935.340306831@linutronix.de> <20180419134647.GA9817@redhat.com> Message-ID: <87o9ieq1ud.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, Apr 19 2018, Thomas Gleixner wrote: > On Thu, 19 Apr 2018, Mike Snitzer wrote: > >> On Thu, Apr 19 2018 at 6:04am -0400, >> Thomas Gleixner wrote: >>=20 >> > From: Thomas Gleixner >> >=20 >> > The allocation of the reed solomon control structure can fail, but >> > fec_alloc_bufs() ignores that and subsequent operations in dm verity u= se >> > the potential NULL pointer unconditionally. >> >=20 >> > Add a proper check and abort if init_rs() fails. >>=20 >> This changelog makes little sense: init_rs() isn't in play relative to >> this patch. > > fio->rs =3D mempool_alloc(v->fec->rs_pool, GFP_NOIO); > > f->rs_pool =3D mempool_create(num_online_cpus(), fec_rs_alloc, > fec_rs_free, (void *) v); > > static void *fec_rs_alloc(gfp_t gfp_mask, void *pool_data) > { > struct dm_verity *v =3D (struct dm_verity *)pool_data; > > return init_rs(8, 0x11d, 0, 1, v->fec->roots); > } > > So init_rs() is part of the chain, right? > > Yes. I missed the NOIO part. But.... > >> And it runs counter to this commit's changelog: >>=20 >> commit 34c96507e8f6be497c15497be05f489fb34c5880 >> Author: NeilBrown >> Date: Mon Apr 10 12:13:00 2017 +1000 >>=20 >> dm verity fec: fix GFP flags used with mempool_alloc() >>=20 >> mempool_alloc() cannot fail for GFP_NOIO allocation, so there is no >> point testing for failure. >>=20 >> One place the code tested for failure was passing "0" as the GFP >> flags. This is most unusual and is probably meant to be GFP_NOIO, >> so that is changed. >>=20 >> Also, allocation from ->extra_pool and ->prealloc_pool are repeated >> before releasing the previous allocation. This can deadlock if the = code >> is servicing a write under high memory pressure. To avoid deadlocks, >> change these to use GFP_NOWAIT and leave the error handling in place. >>=20 >> Signed-off-by: NeilBrown >> Signed-off-by: Mike Snitzer >>=20 >> Seems there is no real need for this patch. Neil, what do you think? I think the code is correct as-is. > > The analysis above forgot to look at the mempool->alloc() callback. So ye= s, > while the NOIO is good at the mempool level, but init_rs() uses GPF_KERNEL > so there might be a different can of wurms lurking. The ->alloc call back is not relevant to the question of when mempool_alloc() can return NULL. If the ->alloc() callback returns a non-NULL value, it will be returned by mempool_alloc(). If it returns NULL, that will not be returned. mempool_alloc() *only* returns NULL in one place: if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) { spin_unlock_irqrestore(&pool->lock, flags); return NULL; } so a NULL return is purely dependent on the GFP flags passed. GFP_NOIO contains __GFP_DIRECT_RECLAIM, so NULL cannot be returned. It seems quite broken that init_rs() uses GFP_KERNEL. It should take a gfp_t arg for the allocation. If the mempool_alloc() above really needs GFP_NOIO, then it could theoretically deadlock as it performs a GFP_KERNEL allocation inside rs_init(). So in that sense, the code is not correct as-is. It could possibly be fixed by calling memalloc_noio_save() / memalloc_noio_restore() around the call to init_rs() in fec_rs_alloc(). Thanks, NeilBrown --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlrZFSoACgkQOeye3VZi gbmLsRAAxMcISn8430PLb2pWi84yysdQvxdbkQ2zEW8SCTzs+YO37RRAQBqW4NrW /80BpwUTDQLqogu3QTifQoxeEKEKl9oWr1FVVm2T0pITzhBtaE7xiurUgo3zSdtK T/ApYrTUILAKcP2WHIn0d4ksgfasi5am1mOpdhnSFVpjaoikVTUIViiWwVxxX+tL bOkxqobl9pbc0SkUHXH5h1GE3ncaiPnBMDjBR8u2+BZRj8Tka1eqpU29eqb8Rt3m P6/qSZPiDjwS5eI8ANH3itoGIfk74RZvH7+snzqN7N2PhXA5vCBRo2wcVB6KUhGb Qe67qGPVQKNLMjTunt99ud4t0gHmEiw9zRsBlPlQp/OJfmkK2X9fw8Ll4VCri8m6 N363pkrcir58SUcxcthqL9DriHY43uBENSSgW0UOqfvbnjWU9sr2FVblXh0rUC3h hayF7PJnPBT1DIZWIM6quy92Hp3IVcd24HZDucyIg5+8d9UT41OwsoGLbAT+H/pz KENO/wqpE/JexVfFPeipnQbhT/TKiqCFOZEpEcgYErbs4H/hUspeVJxR67iqtpj3 YCE6hZhWvsca7JETXpBtlteG1Ifzy1rlMEYz4WvxTHutMJR1pelz5I9qHCzXwXFf tMcxI0CkB9DNHNzU2OFRqUOiZ5+ZXSnJfgCxWqHJimbkYV/wTzQ= =+r10 -----END PGP SIGNATURE----- --=-=-=--