Received: by 10.223.185.116 with SMTP id b49csp1139391wrg; Wed, 14 Feb 2018 12:13:55 -0800 (PST) X-Google-Smtp-Source: AH8x225MLMSenqcHmyIbg/xJZ4+48yZ79JOstorr0YEdZOW3NKlEbqdWrWGJq3dW518CQ9SqLc+2 X-Received: by 10.99.96.66 with SMTP id u63mr170950pgb.49.1518639235239; Wed, 14 Feb 2018 12:13:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518639235; cv=none; d=google.com; s=arc-20160816; b=W5YX7nezk/3pPMKTwKzW67HJRtI3h5mi8xwsA8rTlgjukdXMT0uepaIba6Bjhxpc4+ D8dedGstO7Sv1bKKJltpZARWVb6cJFtPi0PFgklMm0jXp9bMDqrJZYeEWBN8RFsMssVR gglWtnp53WC6PXRe7m95Ntv1ymlySc7dyp0s8y/O5mXbFFfLYmSkwOOjhIcJPuo2rMCu T1wQW8o+VtC6Y8ljeXvSN/8nCbjjKmZbgFW/EPT+p3KLuj6/jvgUVcq/olk+e+1LFuYx 33tad3U/ZLCnQnc4Qen1Kox5kMSkb7VQO+quhzq5xAMed3I8XCJj6OkPV0icYFoDQoO6 CCJw== 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=Ab31J7iLVde64gVrGKq4u2hv8mkLA7+w+gQzHabctEo=; b=H9ND1EMvm4CBNlrAWcz4zP6LUdw6Us/7+bR1ZBq8jtuIk9iBGrZG2M5STSXMqxQT/1 ibQj76tcJmYt1FtNalcjC6j0vGenyG5ev8T6ec/xg0awTsbLpKZmNTfgiQYZy/9ckunJ 2j4obMUfWgJzf/voleCwsA8wiPoR1lAuPwkzLwEacwnapwW9MebunzkhRt9iYEw33zHh +nhXDgT6ZmBjnJv/QbbTBPy02I43SRovzi7ekxp4OFWKTL0KQAZ12bH30swhN5/zF+M+ F8c0c/jr/10qSN96TKuNknirwN1zmUtCjCLu2duqR8/iSAuerZpxq+/pgjlKh1nUt7j4 oYSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=sC1qk+e5; 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 v12si17887pgs.288.2018.02.14.12.13.40; Wed, 14 Feb 2018 12:13:55 -0800 (PST) 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=sC1qk+e5; 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 S1163036AbeBNTfW (ORCPT + 99 others); Wed, 14 Feb 2018 14:35:22 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:37134 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162917AbeBNTfU (ORCPT ); Wed, 14 Feb 2018 14:35:20 -0500 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=Ab31J7iLVde64gVrGKq4u2hv8mkLA7+w+gQzHabctEo=; b=sC1qk+e5jCTzpS3WvCcHHTYun gUk7EGUJ6C/9jyFrvjPBOSt8rrlnbRNJBXzqUNILJcPs7jT4Fx5palpcq7NuKMj+WkD6c5DG5P4AV sNL8SM4uT27/6ykwvHa1V9om6r7BvRwG3uxkTdjbnGH8nRhkSrfNa2HcfWji5Mn95ueDhmGEFLamz kMiCurzSAqQWs06Ugppint2xL3NOrkGESxL37rXlqO8xKzNI5Zrgn5Up51nwQRbks9jWSpov8cIYt INizx+IvwViHAo9916OsjvUERptp4cYl4ne5DSntwFXeSNpb5x6FevOW01TnZT1BJG8Bv41E3j75k 3J/GAUyDw==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1em2pq-0002wf-C7; Wed, 14 Feb 2018 19:35:18 +0000 Date: Wed, 14 Feb 2018 11:35:17 -0800 From: Matthew Wilcox To: Kees Cook Cc: Andrew Morton , Matthew Wilcox , Linux-MM , LKML , Kernel Hardening , Julia Lawall , cocci@systeme.lip6.fr Subject: Re: [PATCH 2/2] mm: Add kvmalloc_ab_c and kvzalloc_struct Message-ID: <20180214193517.GA20627@bombadil.infradead.org> References: <20180214182618.14627-1-willy@infradead.org> <20180214182618.14627-3-willy@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 Wed, Feb 14, 2018 at 11:22:38AM -0800, Kees Cook wrote: > > +/** > > + * kvmalloc_ab_c() - Allocate memory. > > Longer description, maybe? "Allocate a *b + c bytes of memory"? Done! > > + * @n: Number of elements. > > + * @size: Size of each element (should be constant). > > + * @c: Size of header (should be constant). > > If these should be constant, should we mark them as "const"? Or WARN > if __builtin_constant_p() isn't true? It's only less efficient if they're not const. Theoretically they could be variable ... and I've been bitten by __builtin_constant_p() recently (gcc bug 83653 which I still don't really understand). > > + * @gfp: Memory allocation flags. > > + * > > + * Use this function to allocate @n * @size + @c bytes of memory. This > > + * function is safe to use when @n is controlled from userspace; it will > > + * return %NULL if the required amount of memory cannot be allocated. > > + * Use kvfree() to free the allocated memory. > > + * > > + * The kvzalloc_hdr_arr() function is easier to use as it has typechecking > > renaming typo? Should this be "kvzalloc_struct()"? Urgh, yes. I swear I searched for it ... must've typoed my search string. Anyway, fixed, because kvzalloc_hdr_arr() wasn't a good name. > > +#define kvzalloc_ab_c(a, b, c, gfp) kvmalloc_ab_c(a, b, c, gfp | __GFP_ZERO) > > Nit: "(gfp) | __GFP_ZERO" just in case of insane usage. Fixed! > It might be nice to include another patch that replaces some of the > existing/common uses of a*b+c with the new function... Sure! I have a few examples in my tree, I just didn't want to complicate things by sending a patch that crossed dozens of maintainer trees.