Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp71329pxb; Tue, 21 Sep 2021 19:04:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc3NWWURbHs4PRBd8+OjJDGZ9WA6rjeJ/z1H6lkydrB4cDKwmjFK1MWVjKXe9RE9EVaofL X-Received: by 2002:a05:6e02:1a8c:: with SMTP id k12mr24276648ilv.312.1632276292826; Tue, 21 Sep 2021 19:04:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632276292; cv=none; d=google.com; s=arc-20160816; b=bQYbYZshjH/+Q/2xlCoau0DsuZvnZDFEH+iK0dIiCXDKFku604HnegjyYjyO4BqZC8 Wnuufv4IUOEbctJgVH0Vc9Z/rzV5cXys2i9f/KrcweAzr9Aa4sOMfDvRb409uvqDfdy4 vnpv3a03kmtr+VgXZCzTg5IGaBLvIGX+qD8EF1vsY3BXgdouTnJbLFUM+wakFq70viv+ 82Q2Kp+a1yeTWDd2EpVy8QMxdWhtfU2HPa/TLzt6OoULjpzH6H01ZLiaGwavh2W67rRC qDodp98axNhBXTCKjzvC1EiL8689OKlFscrWMcGYOg9Rm8+dMY8XUDmyFv99HnGgfApA 6Q6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=Gas+3QPYeLf8mMsKhBDjcD8pKHTZBZNS/IChpzBP1zM=; b=d8L8owS36wNE5J8WiqtQnTJYUznjYzgKJgYfq9NOAGIFyRFzH0iVXTzwvTdlhaqgGa HUVoQGZrKVc3hbg+t7XHu/xwokFgBlGaVHkcmifUew/tKokaEzGOipbjjdjV9IEJGH+3 jZeK8sKSit3WTxHkzaYYrLVMiE3JELIMvsC6hlH6if/WzyAWnCmX17XpAFQs+tfEqpeg 99sto8ZsLEDKv8ASAwyQIwVST1AR5bfGax5wxbHOaZY/m7jwHE9XgFoZj3qOg91Yttfv 2RkUYFeOXYR8YUnsarDdCcNMLAYw/sh0a+os1osSOPdCbR+BagKdckeATzt+79s7YFYp 15nA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s17si959273ios.107.2021.09.21.19.04.41; Tue, 21 Sep 2021 19:04:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbhIUXrU (ORCPT + 99 others); Tue, 21 Sep 2021 19:47:20 -0400 Received: from smtprelay0174.hostedemail.com ([216.40.44.174]:33010 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229824AbhIUXrU (ORCPT ); Tue, 21 Sep 2021 19:47:20 -0400 Received: from omf02.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay02.hostedemail.com (Postfix) with ESMTP id 2CD3030162; Tue, 21 Sep 2021 23:45:50 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf02.hostedemail.com (Postfix) with ESMTPA id 243461D42F9; Tue, 21 Sep 2021 23:45:46 +0000 (UTC) Message-ID: Subject: Re: [patch 9/9] mm/vmalloc: add __alloc_size attributes for better bounds checking From: Joe Perches To: Kees Cook , linux-kernel@vger.kernel.org Cc: Andrew Morton , apw@canonical.com, Christoph Lameter , Daniel Micay , Dennis Zhou , dwaipayanray1@gmail.com, Joonsoo Kim , Linux-MM , Lukas Bulwahn , mm-commits@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Miguel Ojeda , Pekka Enberg , David Rientjes , Tejun Heo , Vlastimil Babka Date: Tue, 21 Sep 2021 16:45:44 -0700 In-Reply-To: <202109211630.2D00627@keescook> References: <20210909200948.090d4e213ca34b5ad1325a7e@linux-foundation.org> <20210910031046.G76dQvPhV%akpm@linux-foundation.org> <202109211630.2D00627@keescook> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamout04 X-Rspamd-Queue-Id: 243461D42F9 X-Stat-Signature: nmh4sseds13ojprfziwgjcbwyxpdkcp3 X-Spam-Status: No, score=-0.99 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18siCLeLxc9mFEyyVNoRWQi0ZSA3VAUMs8= X-HE-Tag: 1632267946-356498 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-09-21 at 16:37 -0700, Kees Cook wrote: > On Fri, Sep 10, 2021 at 10:23:48AM -0700, Linus Torvalds wrote: > > On Thu, Sep 9, 2021 at 8:10 PM Andrew Morton wrote: > > > > > > +__alloc_size(1) > > > ?extern void *vmalloc(unsigned long size); > > [...] > > > > All of these are added in the wrong place - inconsistent with the very > > compiler documentation the patches add. > > > > The function attributes are generally added _after_ the function, > > although admittedly we've been quite confused here before. > > > > But the very compiler documentation you point to in the patch that > > adds these macros gives that as the examples both for gcc and clang: > > > > + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute > > + * clang: https://clang.llvm.org/docs/AttributeReference.html#alloc-size > > > > and honestly I think that is the preferred format because this is > > about the *function*, not about the return type. > > > > Do both placements work? Yes. > > I'm cleaning this up now, and have discovered that the reason for the > before-function placement is consistency with static inlines. If I do this: > > static __always_inline void * kmalloc(size_t size, gfp_t flags) __alloc_size(1) > { > ... > } > > GCC is very angry: > > ./include/linux/slab.h:519:1: error: attributes should be specified before the declarator in a function definition > ??519 | static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __alloc_size(1) > ??????| ^~~~~~ > > It's happy if I treat it as a "return type attribute" in the ordering, > though: > > static __always_inline void * __alloc_size(1) kmalloc(size_t size, gfp_t flags) > > I'll do that unless you have a preference for somewhere else... _please_ put it before the return type on a separate line. [__attributes] [static inline const] function()