Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp220596pxb; Wed, 18 Aug 2021 20:40:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGZPrJzb+oOLf+EHcC63o4vR2kvwMB1r9mm3KlWkGif6s99lZGaOvE0USry7Hk2Mj/CsKC X-Received: by 2002:a17:906:4f97:: with SMTP id o23mr13461604eju.418.1629344407548; Wed, 18 Aug 2021 20:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629344407; cv=none; d=google.com; s=arc-20160816; b=rfTM235getFODXhK60K3kXiUZHkxEOOK1HO6ORyagkAGQJFv/7DoVOQYi0tK/xQrYs FN7eGwAcq7SqCn5JqRNjVakTh6rCv0ECDhjE/H4dEQa4P3LYOAT+VQFyjhOVbMs/uiHp 8XdcX0yILezrU5CbGv5m2OYJwMPlEPLq5CjLg0Sj4WneXnZU+qAY2rGYSPFUAj76NTGP gPASG0h803BcZszTPxoH4hPJMofUtozouM+eD2BMMgtBmMvnwbDcS0fuP6ZRIZQRruAE UH6UNHPDpwX0DvlGTSOVN76QiKCFNpCBejakcu0MdusP2Rv0/D44LQJ0BWMIK/DtrxP4 ez8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OWG8gSW9FTH/AgnNjiR6jP10S4rh/ZtmSM7TNejSBro=; b=MfH77GIWq+lVY692HWPA3C1AXNT9iR6GiOL7yk/bX60fTbmGeP2gaOSYPMVS5nT7um Hz3C9uXSMMoXpWf5BLS2XdTM+AtF/uRjqEkegzxzIgj5eaf4wZWU6Gy4UkeI9IZvN3LN nZpi/fHSlzlA6g7Wnea1OfzVdaCwAcGYkkvgmuuXvIl50sE+plxKPkL6erAEOzXaKRQt b0s2HeKrwl7lTwgUDgsrXnnvtamBfRRhEaVeO0mY6XBRgRXX1+8wglf63Yv8+EVapJ3U r4tVoDA2B+GV/+yDuonydv+bDDlk0JztAvQ46B8kmAjlL7CQOxazKJ9PfYGQcqY/g22S tK4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bf7AXXLx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si1698547edb.536.2021.08.18.20.39.44; Wed, 18 Aug 2021 20:40:07 -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; dkim=pass header.i=@chromium.org header.s=google header.b=bf7AXXLx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236599AbhHSDhg (ORCPT + 99 others); Wed, 18 Aug 2021 23:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236473AbhHSDh2 (ORCPT ); Wed, 18 Aug 2021 23:37:28 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F0F2C0613D9 for ; Wed, 18 Aug 2021 20:36:52 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d17so3085540plr.12 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=d3HHagckAJkfFXQNlq7tE8hx/xGpX1xFRVuSrOaCG6/rfFZDBA4jUQAlaNFdZ/Wu6z SXwu+r/QmmdOktcdIWYYJe9/i4R4OQjRnMGwcJnWp+nRrC/oap9XOTKffQEnrSe+tkPX hLxyRGh2Q3kljR1gcLImdX0CRSQ/ot1X11vdtIpa95JJGKrBxECdGyEs2hRUeqCxZbwR 3TFnb6AigPn7bsAZ1CrOumez2Wo5eVb61VnnKXwOKWQ8h0P0/nCbEKsPC4rg8M7GoQ38 zdS8rzgz+a7FIlbeo+tf38+45k6F6xSiiL0PYZ6gNCQu/6cehJLlAszB0zXvvTqjevlJ ZTfw== X-Gm-Message-State: AOAM5324O38Kst4ah/gCizxCHU7Z5Ghs8fA+oQRKYTq/IO/1FOtVtA+K dnwwPB0m47+5DQWS802p9EAGRw== 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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