Received: by 10.192.165.148 with SMTP id m20csp2975159imm; Mon, 7 May 2018 04:39:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrc+uTxCQxOIObfuvSXSwrN6OxmeskmUbiJk4WN5G05+PwYRi5CFLsmAJ2eEUcHmMyQO7gt X-Received: by 2002:a63:7003:: with SMTP id l3-v6mr16331521pgc.14.1525693178730; Mon, 07 May 2018 04:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525693178; cv=none; d=google.com; s=arc-20160816; b=fzl4stYgyVFXla8YhqdLX5FW/kj9MEhOriiX0DI9fH7WqsoaeQhMIpS1PFL4Q/KeKs ZaP73/DsNfyr4hNHXg8ohjuTxtysF4SHFD7LfxwIePDT6Jko4TNe8ohqACEmpsnur0Lj tsq2Fy6GXCRZJIIkG8PXMNoYb7COyb8qBhZvnrt2xVvv6mk7Fpx+kI/RFZ3VeeVazl73 ApzefCntWSg9VvEN9o1Dn8wPss0lAtQloe3LBh8RrE4z7CxGLRnfOi8DZrX/NLHnQMT+ CWVrDFmTg8HfTyTR4uO+AKBOpgiQxT7Jk82BLl9VSStjVAMBablX+OoxmTZo39okvzNn vN5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=XjE8Pn5fyMvzUPXAsiRqeHoDpybgGTTm0D6o7PuLJ0w=; b=HlWL5oBm47E3ybfz7ID9Fmbjhsc6wkxAbyACsyNwDHrnx55rndXtCoOT+8nVlRRjsD FfPz/PWWweNHsdc4FB65HxXE9WH4nNn4LJLN77RvmFAfBvq8yz5pmsIbWwkaQULt8JGc INI5XoSUVr84pvbGOtHSzKhcl6ATLMinyhFVaTgqJntv2e2edMrPkP8qm2t5/WkIPOTN YKRTcAVa9L6UV4ylx+wCW5tgXe5To/ueoLhsnRX8be3KAtU6lkYy7YnCvKnhfN/Kb3iQ 4OvWXfGqx6OuI5ceWrfa3H1AO9Sn1H3CzgYR0DyCL2NtsESb0fKrlGWs12uqMSkeVgxL WqJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dIYGG3DM; 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 m3-v6si2670371pgd.58.2018.05.07.04.39.24; Mon, 07 May 2018 04:39:38 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dIYGG3DM; 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 S1752147AbeEGLjI (ORCPT + 99 others); Mon, 7 May 2018 07:39:08 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35470 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751960AbeEGLjF (ORCPT ); Mon, 7 May 2018 07:39:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=XjE8Pn5fyMvzUPXAsiRqeHoDpybgGTTm0D6o7PuLJ0w=; b=dIYGG3DM5MUIObDWtN3gMnhMa OUcbzIea3ismLFFavFiK4A77RqTNCrvQ537wY2/oPuyBHu2WYId6Iu/E8GQ0WMQWxvExJiwCxFLfM NCkquNHVHjbuOK6h5rxeKtbiCf5cIQst/VSMGmlKxvWtOmdk5mPkinlt+VPTdYb13Qhl46C6Lr73D RENcN6uCRhWPbFqzzdR9qbxGN/SFYt+KK3fzN+n89Awf82APVf5YIk5vcS8ZIDNT3FUU/XFAZgTTJ lnMx0GidDOxt/t+54k7DUVx0s7csMkTpk4xMDNIjWEa529SoK9SpqihMt3U4crGT9iQyg9+Nf9i9E CVaspr46Q==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fFeTu-0000xz-PW; Mon, 07 May 2018 11:39:02 +0000 Date: Mon, 7 May 2018 04:39:02 -0700 From: Matthew Wilcox To: Kees Cook Cc: Matthew Wilcox , Linux-MM , LKML , Rasmus Villemoes Subject: Re: *alloc API changes Message-ID: <20180507113902.GC18116@bombadil.infradead.org> References: <20180505034646.GA20495@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 04, 2018 at 09:24:56PM -0700, Kees Cook wrote: > On Fri, May 4, 2018 at 8:46 PM, Matthew Wilcox wrote: > The only fear I have with the saturating helpers is that we'll end up > using them in places that don't recognize SIZE_MAX. Like, say: > > size = mul(a, b) + 1; > > then *poof* size == 0. Now, I'd hope that code would use add(mul(a, > b), 1), but still... it makes me nervous. That's reasonable. So let's add: #define ALLOC_TOO_BIG (PAGE_SIZE << MAX_ORDER) (there's a presumably somewhat obsolete CONFIG_FORCE_MAX_ZONEORDER on some architectures which allows people to configure MAX_ORDER all the way up to 64. That config option needs to go away, or at least be limited to a much lower value). On x86, that's 4k << 11 = 8MB. On PPC, that might be 64k << 9 == 32MB. Those values should be relatively immune to further arithmetic causing an additional overflow. > Good point. Though it does kind of creep me out to let a known-bad > size float around in the allocator until it decides to reject it. I > would think an early: > > if (unlikely(size == SIZE_MAX)) > return NULL; > > would have virtually no cycle count difference... I don't think it should go in the callers though ... where it goes in the allocator is up to the allocator maintainers ;-) > > I'd rather have a mul_ab(), mul_abc(), mul_ab_add_c(), etc. than nest > > calls to mult(). > > Agreed. I think having exactly those would cover almost everything, > and the two places where a 4-factor product is needed could just nest > them. (bikeshed: the very common mul_ab() should just be mul(), IMO.) > > > Nono, Linus had the better proposal, struct_size(p, member, n). > > Oh, yes! I totally missed that in the threads. so we're agreed on struct_size(). I think rather than the explicit 'mul', perhaps we should have array_size() and array3_size(). > Right, no. I think if we can ditch *calloc() and _array() by using > saturating helpers, we'll have the API in a much better form: > > kmalloc(foo * bar, GFP_KERNEL); > into > kmalloc_array(foo, bar, GFP_KERNEL); > into > kmalloc(mul(foo, bar), GFP_KERNEL); kmalloc(array_size(foo, bar), GFP_KERNEL); > and the fun > > kzalloc(sizeof(*header) + count * sizeof(*header->element), GFP_KERNEL); > into > kzalloc(struct_size(header, element, count), GFP_KERNEL); > > modulo all *alloc* families... > > ? I think we're broadly in agreement here!