From owner-svn-src-all@freebsd.org Mon Jan 8 17:02:46 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C9E1FE77CEF for ; Mon, 8 Jan 2018 17:02:46 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-io0-x22d.google.com (mail-io0-x22d.google.com [IPv6:2607:f8b0:4001:c06::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 89AB02A08 for ; Mon, 8 Jan 2018 17:02:46 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-io0-x22d.google.com with SMTP id n14so15068977iob.4 for ; Mon, 08 Jan 2018 09:02:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=unTpTTy5P5yekblp+kxMeO/ogtZMPUK2fYnEk0u73O0=; b=XCecOU/uNDpaoqlC80WBaaJWOwROagFQdlQwNbJ3k199hnna+jKuknyX2ddmkHiIIL rk/b1EYpSA8xhZqcLJGO92tAqz8t7bAt9FNcLY6Om9q9yCfTStjvUVQYcI0PuFq3TOrl KtP7hS1DfRIQn7qdPSz9eMFkAjdGSLrDqP5bivbibrTO4G0lRXi11fW85oEBcRRp4JCy VxpRcD1Y5tRyxLrDvpQYdwCXVDYQoDofNxEnhcDq1D+H4VcRl5XNzGftdlIIu4axoDfZ JzSDqdQlVma+Y6H/xuio60MA3jwAD6qv+JQwr8XkftleWudWnbIrDVIkBSa9nRzTA9oX QAyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=unTpTTy5P5yekblp+kxMeO/ogtZMPUK2fYnEk0u73O0=; b=N70JavB4zmLyYGvcE1s/KhXeG33PJuxam5M12VebUIvLRue6vmVXaD9Q28ldrW7AA8 0ur3KYvytzCfx9NGSIii23QBGaZAvpfn7J8UWyBSSlFlxYsowHR9l365kS6UdkwjTmQo nUmNoTxp+FQOFRUtMeZNpV5ZmbGF4olm3lZineXCVz0P/HNTjtO01g/g2lsXmZS8Ofo4 rRfa3Ned4YCNwN8uHkGqNxaBVxsXw1FFLz4M8sCDAVSWKcqrV2pMQ2kvnYFlsLyVFLOv TG1D6b2DxdkayfcOsmkEPeyKbc99+EJ0RZrSTI9jVvEdCm4NZYzpnEpC7reHWJMxF8FI suiA== X-Gm-Message-State: AKwxytfsm2Us5BtUjPeaxO4zI4VkgkdGFU9NT5HBP9rN3xnbOZJefWJF xYijlV7MAN467ae6De3UH34pvYaxY1HLFNOv7ox9iA== X-Google-Smtp-Source: ACJfBot5MLf47CGTojacU1hu8Zxwg3+gS8wBCrYqgTMujYBR8G0WRHXTK6o8VfSxKTZtihBNbnZ3Y4loIv1p23MJmz4= X-Received: by 10.36.91.210 with SMTP id g201mr8912782itb.50.1515430965869; Mon, 08 Jan 2018 09:02:45 -0800 (PST) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 10.79.160.217 with HTTP; Mon, 8 Jan 2018 09:02:45 -0800 (PST) X-Originating-IP: [2603:300b:6:5100:1052:acc7:f9de:2b6d] In-Reply-To: <20180108162938.GD2412@raichu> References: <201801072238.w07McjLP099234@repo.freebsd.org> <8D8CA434-2A87-44D9-AC27-5166802FBBC2@fubar.geek.nz> <0a6ad324-46f2-9270-5abd-dbc3e734cc8b@FreeBSD.org> <1515428308.44630.2.camel@freebsd.org> <20180108162938.GD2412@raichu> From: Warner Losh Date: Mon, 8 Jan 2018 10:02:45 -0700 X-Google-Sender-Auth: H2NfmkKECbc5gxtf5L3fpojOZjk Message-ID: Subject: Re: svn commit: r327684 - in head/sys/compat: cloudabi32 cloudabi64 To: Mark Johnston Cc: Ian Lepore , Pedro Giffuni , Ed Schouten , Andrew Turner , Ed Schouten , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jan 2018 17:02:46 -0000 On Mon, Jan 8, 2018 at 9:29 AM, Mark Johnston wrote: > On Mon, Jan 08, 2018 at 09:18:28AM -0700, Ian Lepore wrote: > > On Mon, 2018-01-08 at 09:13 -0700, Warner Losh wrote: > > > On Jan 8, 2018 8:37 AM, "Pedro Giffuni" wrote: > > > On 01/08/18 10:13, Ed Schouten wrote: > > > > > > > > > > > Hi Andrew, > > > > > > > > 2018-01-08 8:37 GMT+01:00 Andrew Turner : > > > > > > > > > > > > > > Won=E2=80=99t this lead to a NULL pointer dereference on overflow= ? > mallocarray > > > > > can return NULL even with M_WAITOK. > > > > > > > > > Yes, it will, but an overflow shouldn't happen in the first place. > > > > ri_data_len is compared with UIO_MAXIOV a few lines above. Even if = an > > > > overflow would happen, this would cause a kernel panic due to a NUL= L > > > > pointer dereference later on, which is likely easier to debug than > > > > some piece of code that overruns a buffer. > > > > > > > > In this case, mallocarray() is preferred, because it makes it more > > > > obvious that we're allocating a buffer that is accessed as an array= , > > > > as opposed to single structure. > > > > > > > > OK... > > > The behavior of mallocarray() somewhat inconsistent with malloc(9), > > > realloc(9) and reallocf(9) but this is clearly documented., so we jus= t > > > assume the developer knows what he/she is doing :). > > > > > > > > > This is one reason it didn't go in before... the error semantics > suck... we > > > re are a poor match for existing code. > > > > > > Warner > > > > Yeah, having a bunch of functions with malloc in the name, all taking > > the same M_WAITOK flag, but that flag has different implications for > > calling code in regards to just one of the malloc functions... > > contigmalloc(M_WAITOK) isn't guaranteed to succeed either. In that case, > M_WAITOK just means "try harder to defragment physical memory in the > request space before giving up." > > > that's just a recipe for creating bugs. It makes this whole function a > bad > > idea. > > A NULL return value from mallocarray() indicates a bug in the caller. I > don't see why it isn't preferable to crash quickly and loudly in that > case. > When this came up before, people wanted a check_mallocarray(a, b) so they could centralize all the integer overflow knowledge in one place... Seems like we're creating ABIs that are more error prone than the problem we're trying to catch... Warner