Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp702991pxb; Thu, 30 Sep 2021 15:30:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfDJN7k0T/mrj4er1L1sd9Ejn67a5urs/0BClZQszTPeIUrzRqkJGw1WMR4v0tn0gJKQml X-Received: by 2002:a65:6158:: with SMTP id o24mr6932308pgv.141.1633041047048; Thu, 30 Sep 2021 15:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633041047; cv=none; d=google.com; s=arc-20160816; b=LhWSchyeax0r44cA14+HKDrekULYqjqGkJZDWkw+4RVAXztfFmXIpJ4kMLLT4+SXt7 /r0+aKKYall0xeJUdI3a6ls4J4u/L/jLy00SrYYq3hiVbNwH6ZaagYRBZFVcQ/SCBfmm QdT3LqmNTQGvfTOxdjERAyuQEpFOynZt7Hm9ROf41OmPsx10Pz+cA1EBwA4E7SG23Wp7 G9CRkSLHh+ZlXfquvRp+UWe9XDX4r/pDaVXNICxKP5OuzoOD238903mF8xZLr0K5kvny H+DO+p/VWpQfNfu2uDhwUHaK5nIUFTfCFdSCPUkqKTrrpDgOmifoJLwheoJfBv//bipQ 2Okw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xTdlLb7GtJ4Tj/wecFW9tRbbhL9s43+6wka+jFobq0s=; b=nwo+8COv+w5eQ/nXgcJ3EjsL1Im2S9wN62vSO1omLiPL1Z4s4yBu8UKM2738yYBxPB 3+Y5BMHDcQxxsI8jV+Ss2VAwUBy8VBYFp2mcIm078ldmnDo11QCa9q2Jgq504LA2K/od I7K9G6xqbwJFQjbN99qPjyV4Jv9WX08bjUPD2yDUhtEcSJgs6GZPGLtjsdfaQam3SvZr qgS9p8OIZ3se4Pb/Sq5PmqFYDWJH+MNWJIAVgYBLXpQ0gtbnyNDwiW81ei1wipqkIwfM XbSe00fQ/TpHEapv/k8qOmt5UYrpBshUSr/xx9N4uRPT22xYQWuDKj9CXwveXA6wVk2G yL9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M2T++KtM; 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 f12si4916386pjq.115.2021.09.30.15.30.33; Thu, 30 Sep 2021 15:30:47 -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=M2T++KtM; 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 S1349420AbhI3W3P (ORCPT + 99 others); Thu, 30 Sep 2021 18:29:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348158AbhI3W2z (ORCPT ); Thu, 30 Sep 2021 18:28:55 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9B8AC06176E for ; Thu, 30 Sep 2021 15:27:12 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id y8so6253150pfa.7 for ; Thu, 30 Sep 2021 15:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xTdlLb7GtJ4Tj/wecFW9tRbbhL9s43+6wka+jFobq0s=; b=M2T++KtM+KT2mzH+OBTryDjwFQD7Zafb7dljFTDxRRFvTMYRNqYSZO3d23H0Hp+ARh XnLRQkcyDjS13ZBcgm/XGoaUSFBG/8cz5KRpJ01GC8+dbkS+4tfJappB4jFZpL7ntoAw X4ckafKQK4lBJej4HBhFSlB3Vh+OP4N4E9W5U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xTdlLb7GtJ4Tj/wecFW9tRbbhL9s43+6wka+jFobq0s=; b=EjEky8h/+XUf1QRzs3hsSZ5Td5mgp3xw++FltVIJFTol9fGnd6QvUgEPM1yodQCWlb Np/Shzb2fWgWUIBDFNHkxhjMcEV3s8My4cEyn7K264jH9bzcwFkxsTQLZcvRC7Gjlolf ONzBF2mgkNtiWbGZnb3oLjaMgkar8D3VcJ9BUB8YW+0M+KoL+gEcqridgXQc29QBGPgY 4u8eA3Ka5qDN23lK/o1BDucDLit1SQMztOK5TmzFhtmS/bVQmZ0D39A90gHT4S8It3jV PDW/QJWa0fYvzdqUXctCiQwAzlfKXBWSQodSViMmvWdh4b8eppOFcENBdbfxelCIrJHq b4FQ== X-Gm-Message-State: AOAM532O9c8i1j93TekIKk5/Zkq0YSiShc/d7bE4DUtanO0/RG3g4WtQ KMk/M9upjWLydfgIi8dlr+/0nw== X-Received: by 2002:a63:20f:: with SMTP id 15mr6733460pgc.319.1633040832346; Thu, 30 Sep 2021 15:27:12 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x20sm3606310pjp.48.2021.09.30.15.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 15:27:09 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , 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: [PATCH v3 8/8] percpu: Add __alloc_size attributes for better bounds checking Date: Thu, 30 Sep 2021 15:27:04 -0700 Message-Id: <20210930222704.2631604-9-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210930222704.2631604-1-keescook@chromium.org> References: <20210930222704.2631604-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2486; h=from:subject; bh=9EqXOckHEyfKAa0MxxJtth0Elvb+UhJZNEFB1gjQABo=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhVjm4aUkC0jHO3VL+EQHu/RyvRmlitX3fuanr+Ryz L48wiCKJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYVY5uAAKCRCJcvTf3G3AJlTMD/ 9+Ge1+7x+F/NL44UJJEUkUcosWJRMsIVppsrgGAuv9sU+uQ4EUIlaCObfvfV8cQNsQ6mP4mW4VfHIz qmPEIPllZ1wNum6F1gGAV/KD8oEqyMXXMWBrbSbRfytOI7+SXvYiHYqBOFm/XXNklvYtz1lyFDHFUt AuMPhD6RyaLWnhEnXwBozDpbP82J42TANIyE76AFDLgdBSimeg3/NR8zMhMF+XU9kj0HP8P7kgyv2v YdPjj/Ee2gnHsydjY8nTzEyeFysOuiPmZal5y8Boj0gtOp2hLAkfizpXoSbdiKg1nG3zfW23FpzxZn gPXrPrXAn+bkDFTWB+HYm+GR29fuTj7b9z3P3PK0BjcvUcdV+phsUJ3RkAy96FW1dnKpp2M3x7wVml RitRdRvoVOsKDR0cll4kuoNbKO4G6KsF+2S6EHlFo1d/5dpcSys9CfUu5+W+aPDmtj8QQqyCLTJ9LH I7l/V0e+cL2qPK3IrqQ0Aee+DfUi3b1AZ13Lfgk9GlgKCd50Ee2dBkA7eq07PAItN4eyPZQrfvvtW4 yL3LBUFUy6u1QQh6VthSfwKccfP9tQTGi8HYX4+ylmAUpE22iEiX5zTe/fortEdfvzvng1owx9T9ts 9oZHuqVczFVK0m77+Cfv6mGvcMoLYzUJc7haSxVUqBrIcta3Q9NEyFol+T8g== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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