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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 4E950C4320E for ; Thu, 19 Aug 2021 03:36:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB50361100 for ; Thu, 19 Aug 2021 03:36:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EB50361100 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 330B36B006C; Wed, 18 Aug 2021 23:36:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E0848D0001; Wed, 18 Aug 2021 23:36:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A92D6B0072; Wed, 18 Aug 2021 23:36:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id F24F46B006C for ; Wed, 18 Aug 2021 23:36:53 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 843FC8245571 for ; Thu, 19 Aug 2021 03:36:53 +0000 (UTC) X-FDA: 78490418706.34.89A9D5F Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf21.hostedemail.com (Postfix) with ESMTP id 313C4D00F595 for ; Thu, 19 Aug 2021 03:36:53 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id 28-20020a17090a031cb0290178dcd8a4d1so6465920pje.0 for ; Wed, 18 Aug 2021 20:36:52 -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=OWG8gSW9FTH/AgnNjiR6jP10S4rh/ZtmSM7TNejSBro=; b=bf7AXXLxLTv0CmXBn58RWmQBZ9LcpPYWlDQy1fNAeZxT8k+tgPLMbTJRZoV7+TJLqA D0YMfmBS5GGXVxU0KTGqEuvI+CEu5kNnqcVLDWTAvxbYGPt9ZraQM+QErigXfLpgJBNu W9zs3o59Wfdjd+g/h9ljZvX4U1YJVbddLGkoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=OWG8gSW9FTH/AgnNjiR6jP10S4rh/ZtmSM7TNejSBro=; b=dEASqOyF5S2JeznpJxW8EK1GwllGVR26itPMHDWP+8uUG97icbndzO5NttPEXkWxjZ yjwHvUYc5WnED1YO/sdpa8co4zq8q+ZG0EgVY7+baxWfZAzbdKxJhZs0IbVkcVSCYqTW v7BgC6EALzsFpd/dCUpuKoUXYok9vXzRD0O/dDsrPuCDm2BWZ/op5z7snjlE1nQjFUm0 fqMGaDk2iMgLtpQP1POtV7JzQBbmosKYFgQrjPlMuJ+DF1hZN9oix4B1unatJfmxMdIt tvK9vTZfZoUjRqsaf4K0o7H0rEzrxsN2/he6fgHvCUZdvBv3V3PQtsbiUqmUiq1uQ5hF gCDQ== X-Gm-Message-State: AOAM531iVHPYYY/v7qn9FojzdbaAzNJczcl8i9Gmt4pNbU2md/VRm+ce MzvfaEhFB1Mexs99tL8w8KuFsQ== X-Google-Smtp-Source: ABdhPJyhy0+a4fDGJXB6BO9R+BMhAU0XGAPV4/WUygffKCQlZpUdChD3xai7iJvGVEwQjN9BPChIEg== X-Received: by 2002:a17:902:b593:b0:12d:7aa5:de2d with SMTP id a19-20020a170902b59300b0012d7aa5de2dmr10093375pls.31.1629344212131; Wed, 18 Aug 2021 20:36:52 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y12sm1476515pgl.65.2021.08.18.20.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 20:36:51 -0700 (PDT) Date: Wed, 18 Aug 2021 20:36:50 -0700 From: Kees Cook To: Dennis Zhou Cc: linux-kernel@vger.kernel.org, Daniel Micay , Tejun Heo , Christoph Lameter , linux-mm@kvack.org, Joe Perches , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Masahiro Yamada , Michal Marek , clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 6/7] percpu: Add __alloc_size attributes for better bounds checking Message-ID: <202108182018.6DA03EA818@keescook> References: <20210818214021.2476230-1-keescook@chromium.org> <20210818214021.2476230-7-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bf7AXXLx; spf=pass (imf21.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.41 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 313C4D00F595 X-Stat-Signature: npgsgnuok715yobtx4hqqfap3oaxwfwe X-HE-Tag: 1629344212-75151 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 Wed, Aug 18, 2021 at 08:42:59PM -0400, Dennis Zhou wrote: > On Wed, Aug 18, 2021 at 02:40:20PM -0700, Kees Cook wrote: > > As already done in GrapheneOS, add the __alloc_size attribute for > > appropriate percpu allocator interfaces, to provide additional hinting > > for better bounds checking, assisting CONFIG_FORTIFY_SOURCE and other > > compiler optimizations. > > Can you elaborate a little bit for me how this works for percpu? In any > case that's not uniprocessor, any modification is done through address > accessors and not on the returned percpu pointer. Is the metadata kept > by gcc/clang able to transpire the percpu pointer accessors? That's an excellent point. :P I haven't tested it through the accessors, but I guess it's possible that this is only useful for UP, and even then, only where the access is very close to the "allocation", maybe like: char __percpu *test_buf; char *buf; test_var = __alloc_percpu(16, __alignof__(char)); buf = per_cpu_ptr(test_buf, get_cpu()); ... buf[20] = '!'; -Kees > > Thanks, > Dennis > > > > > Co-developed-by: Daniel Micay > > Signed-off-by: Daniel Micay > > Cc: Dennis Zhou > > Cc: Tejun Heo > > Cc: Christoph Lameter > > Cc: linux-mm@kvack.org > > Signed-off-by: Kees Cook > > --- > > include/linux/percpu.h | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/include/linux/percpu.h b/include/linux/percpu.h > > index 5e76af742c80..119f41815b32 100644 > > --- a/include/linux/percpu.h > > +++ b/include/linux/percpu.h > > @@ -123,6 +123,7 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size, > > pcpu_fc_populate_pte_fn_t populate_pte_fn); > > #endif > > > > +__alloc_size(1) > > extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align); > > extern bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr); > > extern bool is_kernel_percpu_address(unsigned long addr); > > @@ -131,7 +132,9 @@ extern bool is_kernel_percpu_address(unsigned long addr); > > extern void __init setup_per_cpu_areas(void); > > #endif > > > > +__alloc_size(1) > > extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp); > > +__alloc_size(1) > > extern void __percpu *__alloc_percpu(size_t size, size_t align); > > extern void free_percpu(void __percpu *__pdata); > > extern phys_addr_t per_cpu_ptr_to_phys(void *addr); > > -- > > 2.30.2 > > -- Kees Cook