Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1353639pxb; Fri, 1 Oct 2021 08:54:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx/Gs+O9Hv93W+x3kBSEsp1QWnyMeBc+dGwUMylMnbA4GZ58q5VIEYf+E7EBstfHYmQqIt X-Received: by 2002:a63:4717:: with SMTP id u23mr10210460pga.359.1633103650671; Fri, 01 Oct 2021 08:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633103650; cv=none; d=google.com; s=arc-20160816; b=PMxjqknEGamyt5v60vy7pTOraaM1tsqVHWzG7gSS+MTxMfvE/wUmO8/UPjx42+qtqb hseLEYbhZh+PXnN91MJbhaVfcU0VGKDkvjxh4E64TvuICGXFY6cuG1hJtL0qjAiwLgro DPFn89Iy/ye0uh8NXU/obvrVVBDPt6RPqKEdRVb6bNdCfCpW4YC6ZQlitNw+pn8PhJ/6 NNgHYxhPQlCIg2Stq3KsxKwFyZA/c4fQfcWMLn0dp++06NGoi4Yv8vZLpjlPo9+e5JWz OxtI0U05oGKm+lmZpxqtwIzf0VdKPiYa1axV/zSgrmteshg+Jyjy2J+MbBtWx9vmYKHm E+ug== 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; bh=QVjZB2U1LiPX5N7VS+BV6iC3aFCiEGYAbe9Pf/bwPeM=; b=AZYT9MPmYjgFMqNrUgWekok7U/lxG3zj5o9HcCRajzbvg3FpStjkSYsIEngctHwlF3 y2HGNk+8uoUwUVD+RynLInZJUrYzfN8KHEJwtIaUIffWXeZdNhUT85E+6Vdu/CU3wSOs aOVN6xuvMNfyM640/iTR8Ert6AtseZlRFfU/WlKMqTIFxn65dV5EQwKuN40bnAeXmuJX FT3xHSTmdna/uFTNxPE0ILjynsi4WaSOVAiSDWzOjxwbWP9gIxVaCNdZYtLxf6VXR3dh JmA5RoJsOJkav7sQD+Bf4iSPSWbDMkZI21ogVY1DzRzIKPy5aiVHQ9HtxrJOIHWIEipO x0kg== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si8138059pgj.73.2021.10.01.08.53.57; Fri, 01 Oct 2021 08:54:10 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbhJAORl (ORCPT + 99 others); Fri, 1 Oct 2021 10:17:41 -0400 Received: from mail-qv1-f50.google.com ([209.85.219.50]:45973 "EHLO mail-qv1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231702AbhJAORk (ORCPT ); Fri, 1 Oct 2021 10:17:40 -0400 Received: by mail-qv1-f50.google.com with SMTP id x9so5605799qvn.12; Fri, 01 Oct 2021 07:15:56 -0700 (PDT) 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=QVjZB2U1LiPX5N7VS+BV6iC3aFCiEGYAbe9Pf/bwPeM=; b=vqwf25kVpnYE2kXFeCVs/rZtjFrAGuR6P0EWW9wmS4EC0zSp2qn7MsxhZ23MKrNFWX Rvh8g7JiW83mBhr67VxJ6H6WTolCu0wpYNPJFCeViEjkvSPyxAA0WdsonrAg9UlsI8+h gVpPt53Kv9ERiMNLW9pH1f+yz2uArQPi8gysMIJ02LcpsH+CdPcHmsvd9XZJAQYdrZln vsoA+rWOAw1OkysNg3G+xFClPoK24uRagfEfAd5gjK6Wv6CA2UHi01VRYdcmagcrPUEP laRRX1e9bgc2WL2ru9XQUC/wqD+pxW+RafeKF38VjlS8zXl0PwsSGjhsMnf93mh96CSm FKXw== X-Gm-Message-State: AOAM531aZLa6xF+1NvmuJiODLkbJB39/aI/L9Gn50v2I5OyApuSgIoLx IcUVFUQP4KtrziX4SLlQ5Fw= X-Received: by 2002:ad4:5bad:: with SMTP id 13mr9283552qvq.52.1633097755709; Fri, 01 Oct 2021 07:15:55 -0700 (PDT) Received: from fedora (pool-173-68-57-129.nycmny.fios.verizon.net. [173.68.57.129]) by smtp.gmail.com with ESMTPSA id y27sm126180qkj.64.2021.10.01.07.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 07:15:55 -0700 (PDT) Date: Fri, 1 Oct 2021 10:15:52 -0400 From: Dennis Zhou To: Kees Cook Cc: Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Andy Whitcroft , David Rientjes , Dwaipayan Ray , Joe Perches , Joonsoo Kim , Lukas Bulwahn , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Pekka Enberg , Vlastimil Babka , Daniel Micay , Masahiro Yamada , Michal Marek , clang-built-linux@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v3 8/8] percpu: Add __alloc_size attributes for better bounds checking Message-ID: References: <20210930222704.2631604-1-keescook@chromium.org> <20210930222704.2631604-9-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210930222704.2631604-9-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Sep 30, 2021 at 03:27:04PM -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. > > Note that due to the implementation of the percpu API, this is unlikely > to ever actually provide compile-time checking beyond very simple non-SMP > builds. But, since they are technically allocators, mark them as such. > > Cc: Dennis Zhou > Cc: Tejun Heo > Cc: Christoph Lameter > Cc: Andy Whitcroft > Cc: David Rientjes > Cc: Dwaipayan Ray > Cc: Joe Perches > Cc: Joonsoo Kim > Cc: Lukas Bulwahn > Cc: Miguel Ojeda > Cc: Nathan Chancellor > Cc: Nick Desaulniers > Cc: Pekka Enberg > Cc: Vlastimil Babka > Co-developed-by: Daniel Micay > Signed-off-by: Daniel Micay > Signed-off-by: Kees Cook Thanks for updating the commit log. Acked-by: Dennis Zhou Thanks, Dennis > --- > include/linux/percpu.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/percpu.h b/include/linux/percpu.h > index 5e76af742c80..98a9371133f8 100644 > --- a/include/linux/percpu.h > +++ b/include/linux/percpu.h > @@ -123,7 +123,7 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size, > pcpu_fc_populate_pte_fn_t populate_pte_fn); > #endif > > -extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align); > +extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align) __alloc_size(1); > extern bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr); > extern bool is_kernel_percpu_address(unsigned long addr); > > @@ -131,8 +131,8 @@ extern bool is_kernel_percpu_address(unsigned long addr); > extern void __init setup_per_cpu_areas(void); > #endif > > -extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp); > -extern void __percpu *__alloc_percpu(size_t size, size_t align); > +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) __alloc_size(1); > extern void free_percpu(void __percpu *__pdata); > extern phys_addr_t per_cpu_ptr_to_phys(void *addr); > > -- > 2.30.2 >