From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53894C433FE for ; Tue, 21 Sep 2021 23:37:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E2CA461159 for ; Tue, 21 Sep 2021 23:37:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E2CA461159 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C78BC6B006C; Tue, 21 Sep 2021 19:37:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C283C900002; Tue, 21 Sep 2021 19:37:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF1626B0072; Tue, 21 Sep 2021 19:37:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 9C9FB6B006C for ; Tue, 21 Sep 2021 19:37:31 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CFA642D3B4 for ; Tue, 21 Sep 2021 23:37:30 +0000 (UTC) X-FDA: 78613194660.03.80D073C Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 8D36A7001A05 for ; Tue, 21 Sep 2021 23:37:30 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id j14so532983plx.4 for ; Tue, 21 Sep 2021 16:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qIRPwBi35DByL5nNagL4hpGfYXpq07J7mvCHes4E2I8=; b=CagL4ypNs0iUa6oSr82NtUCcM5afk3tpeB8sZw/NJ2O4nCzEvz6X/w/zpg2BofRyva 3ouHVYLoXloUnknXzDRHbkUfL/Y2/KzBuAtgYAm5fcGpL70SKzDWkbwoKqgBSjKgKWFR 7x9f1PPXKYYZ3hHmt9RkRBRow7JIi6mipiPOI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qIRPwBi35DByL5nNagL4hpGfYXpq07J7mvCHes4E2I8=; b=Lyk2mBzlDwM7dJ53aCNc54J7OIAsgMqzzJ6xEFJvxMmAFhEb8L7OsZxoAKSP8JKVR4 dJo8P1AS6YPjG0cm3APz7xTC+sV/RCINaR2a6saJsji1ysbvu7xpZ7WXMzsQD9iJp9WY OXLBmZvRDxIY/u8EhrrDNSwAMyskOzE354I2sshb+5eRg7NZ1dgyZskd2TKVq9w4cS1j y9j0koJwbs7zqZSeAE7giQxGl5BoxpsPCKX7nmJKFJgggdqEEQ4Xr3UmkrGkXL770xB8 TsN8LWz8KjRBH/a0es3mswoD5kdDfSXXVXPgbR0M1h47ddJSWXE1Ib9dqesXaT2qVR5x q7wQ== X-Gm-Message-State: AOAM532t4pjDWPV4BxPCx4OOkQ2k+rmGqDZh1NiWJepc+xgoUszOPx9x zmvB9Yv72xtJYdO3eX1rQb6O9A== X-Google-Smtp-Source: ABdhPJxmuqnu/uYqodXX1f0kq7Os+jTCYEhXE+TvL4n6MzbS8CErhdU/aNilFR3PjarfxZ9bqn16kQ== X-Received: by 2002:a17:902:6bc1:b0:137:10b6:972f with SMTP id m1-20020a1709026bc100b0013710b6972fmr29321530plt.69.1632267449413; Tue, 21 Sep 2021 16:37:29 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id o15sm229255pfg.14.2021.09.21.16.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 16:37:28 -0700 (PDT) Date: Tue, 21 Sep 2021 16:37:27 -0700 From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Andrew Morton , apw@canonical.com, Christoph Lameter , Daniel Micay , Dennis Zhou , dwaipayanray1@gmail.com, Joonsoo Kim , Joe Perches , Linux-MM , Lukas Bulwahn , mm-commits@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Miguel Ojeda , Pekka Enberg , David Rientjes , Tejun Heo , Vlastimil Babka Subject: Re: [patch 9/9] mm/vmalloc: add __alloc_size attributes for better bounds checking Message-ID: <202109211630.2D00627@keescook> References: <20210909200948.090d4e213ca34b5ad1325a7e@linux-foundation.org> <20210910031046.G76dQvPhV%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8D36A7001A05 X-Stat-Signature: jqrrw515brcyj4jqg8djk73pjrxwaybr Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=CagL4ypN; spf=pass (imf02.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.172 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-HE-Tag: 1632267450-87154 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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... -Kees -- Kees Cook