From owner-dev-commits-src-main@freebsd.org Fri Jul 9 22:41:38 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BE84F667794 for ; Fri, 9 Jul 2021 22:41:38 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GM7SL3R0Cz3nbN for ; Fri, 9 Jul 2021 22:41:38 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: by mail-qt1-x830.google.com with SMTP id v10so8723485qto.1 for ; Fri, 09 Jul 2021 15:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ZAaMmPy3viyS6h8rtZDadXHtxla3RXLgeQVjodelawg=; b=W1QTpeN2Pv3LToA4aCuM+4kOk9LcNQCDw4qnVHoXs5XOhzf/Gu3MPLzFeompA3JkKk Ke5TQQyrQBqM+/vvMJHVZYlRiYKcZG7Tp/joaZPUlFfso1eKttXksJffuOpaoCHn85FJ mOYV6mwCO4pI2caiTxJunuQKIJtjp1AbOvLWOl91hFJX5iscbqEYYv6x1oCLrUzD0uFY 3vKrX8N67StKDZDZen6H4/LYPHepkrounW/6UKDiAcBH7nQAttGyOGycTrzTycet6cn/ GUGU2fvOlGv4M0KTu8Rb1V6Wuz440gck1Ho1rxz44/qadIH8z65sAZA490TQ+DCOQFKR aTag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ZAaMmPy3viyS6h8rtZDadXHtxla3RXLgeQVjodelawg=; b=EDEEMcQQzBKRLYUVuR7+8XAVWCqLV71DsjvrEhDifHvHbMsD9jqOHyGzYDdyzi4zoj U+Z4pyWlHJUcz4qJMd60jUR53+yr8uYEsbO8Bp5CoXAhKk6VAxz1mxNRWUt09s5MNtKL PiAlbByWLasi6tlk+NpRsEsurcR1KURybB8KOjJCEKgZaUO6omCd+n0hNmRu+CaIeRV9 /htqFLky9acxSgCzbZ4yKPJUJzTN7l1OUvKGR/cDToutlX+v8JIsoI258GkBueftluN5 sJK64rddoKBzXbthWAcivFNRe7HakonL+QfgFQBtKpTLOgmd23pkX0T+WoauZ/b86jRY MeIQ== X-Gm-Message-State: AOAM5303H/5RBLXAeGtYfnww245gTqrWZgfCUv7wxfQz1K4trx/emc/W 3U1Y9mxLaajIZvcLSP3oT7Mffw== X-Google-Smtp-Source: ABdhPJwhOCTup/lglIQLB5ltY0IBECbDou8j5qSWaNZJceaAlYv6hjKDmK5cZ0xdmF55gEaJC0+HDw== X-Received: by 2002:ac8:6698:: with SMTP id d24mr35978620qtp.37.1625870497611; Fri, 09 Jul 2021 15:41:37 -0700 (PDT) Received: from mutt-hbsd (pool-100-16-224-136.bltmmd.fios.verizon.net. [100.16.224.136]) by smtp.gmail.com with ESMTPSA id q206sm3156226qka.19.2021.07.09.15.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 15:41:37 -0700 (PDT) Date: Fri, 9 Jul 2021 18:41:36 -0400 From: Shawn Webb To: Warner Losh Cc: Warner Losh , src-committers , "" , dev-commits-src-main@freebsd.org Subject: Re: git: 72821668b039 - main - stand/kmem_zalloc: panic when a M_WAITOK allocation fails Message-ID: <20210709224136.qprhblk43ndtmxqf@mutt-hbsd> X-Operating-System: FreeBSD mutt-hbsd 14.0-CURRENT-HBSD FreeBSD 14.0-CURRENT-HBSD X-PGP-Key: https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/blob/master/Shawn_Webb/03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc References: <202107091726.169HQvGQ084473@gitrepo.freebsd.org> <20210709195425.xzk2azaor4ielmb4@mutt-hbsd> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="53mirfa322pvcatr" Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4GM7SL3R0Cz3nbN X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jul 2021 22:41:38 -0000 --53mirfa322pvcatr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 09, 2021 at 02:34:12PM -0600, Warner Losh wrote: > On Fri, Jul 9, 2021 at 1:54 PM Shawn Webb > wrote: >=20 > > On Fri, Jul 09, 2021 at 05:26:57PM +0000, Warner Losh wrote: > > > The branch main has been updated by imp: > > > > > > URL: > > https://cgit.FreeBSD.org/src/commit/?id=3D72821668b039c276914569e9caa1c= dfa4e4cb674 > > > > > > commit 72821668b039c276914569e9caa1cdfa4e4cb674 > > > Author: Warner Losh > > > AuthorDate: 2021-07-09 17:21:18 +0000 > > > Commit: Warner Losh > > > CommitDate: 2021-07-09 17:21:18 +0000 > > > > > > stand/kmem_zalloc: panic when a M_WAITOK allocation fails > > > > > > Malloc() might return NULL, in which case we will panic with a NU= LL > > > pointer deref. Make it panic when the allocation fails to preserve > > the > > > postcondtion that we never return a non-NULL value. > > > > malloc(9) tells us that M_WAITOK will never fail. I'm thinking this > > conditional might need to be negated for the !M_WAITOK case, in which > > malloc(9) could indeed fail. > > > > Although, even as I type this email, I just realized that a different > > function, Malloc, is being called. What's the difference between > > malloc and Malloc? > > >=20 > The block of code is to be used in the standalone environment. > The Malloc() function there doesn't have wait/nowait variants and > can fail (though in the boot loader, that almost never happens except > when there's a bug). The code is for wrappers around kmem_zalloc > which is the OpenZFS spelling of malloc. It assumes that kmem_zalloc > with M_WAITOK will never return NULL, so it never checks. This > changes a weird panic when the returned NULL pointer is dereferenced, > to an orderly panic when the malloc that the code assumes will never > fail actuall fails. This at least gives better context of where the error > happened and what the error was. In practice, this is a big nop, but > we have had issues with other Malloc calls in the past failing because > of bugs that caused us to ask for a ridiculous amount of memory. >=20 > Make sense? That makes much more sense. Thanks a lot for the clarification! --=20 Shawn Webb Cofounder / Security Engineer HardenedBSD https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/raw/master/Shawn_Webb/03A= 4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc --53mirfa322pvcatr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAmDo0J4ACgkQ/y5nonf4 4fq4tRAAoQKdCupdv+PZ+1R36+kh9uRyFkOk+/fR5VkQl8anqid7GMAYx6fwEC5k bsqj95tIBJZ00iV0pjoqdCJYgzmBAOcrs8ZNNka1Q42kgSyqk+xgHe2MHGnVaQ7g 60zCj8267dpo+nhQVp0vkffpSgb+qpLm9wKZQ0wDe4hExyZNBabSfOubCrLDCkwW m8t/iG0laOAtbRNJ2EqWuELIAkqKZpuume0KUH4iL14d8RjhpPCQecwA7orPZnDU sZnO2te2qQbckBRhfCNEMNW7pBY7JfIPyzqfa4Bk0vdWtm7PIJnFwxi59IvqWKtZ jwCWMNzNNIt9wZDOnB0ktuLZWRxQvCqcV2SQ96lDIQCbWYEnzxItGqD9INpqh3y2 Jfl7dnWDmcnnHHfHYRaYJgW4yEqnqpAB8V/BhgES4bnYN4vCst3LWheEPBpKOe3s Ar4735O+QwdR9hFKyHPVeVokaeFSu46mfD/3/li1F7/HcLNKpqs7KxvCksZE+uHq Fv3n7ddWrndI+DTkFzPtvleVBQjhpS828rgoP5jCC6liFRkOp/omFD85g4l68L73 ejKAn6ZWiP/LzS/8La9xDfHRQ3SMsw8CVO81m83b9WixDlnCLLx66WGnA596pMkb OFvNA7c4hZHr9z5H46/C2hZ8G9mpaW2e7R/U2IbkN8y4x0bSTj8= =RxBr -----END PGP SIGNATURE----- --53mirfa322pvcatr--