Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp16630pxb; Wed, 18 Aug 2021 14:43:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7/aUxbepMV6921DEVJUDSIuzx9y75z0MvKcan4F/bVTPg3XYDybC0zBbVwRZix3fl9NuP X-Received: by 2002:a5e:8812:: with SMTP id l18mr9067818ioj.157.1629322986015; Wed, 18 Aug 2021 14:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629322986; cv=none; d=google.com; s=arc-20160816; b=PsQrBzHNhMyFUXilbtGJl42+0U6RAT6IGiaaqbbN8I3S4xCifBMgCwCXNLlRYbYlps PnA9SBDQ1GAGlQfWu64HNXTRj95KZTPYSPZ80k3+VGfY7/dr7lDCRTx8l57Rwl9dklLt gAzJqsHan2RgSuWxPD9vTlhEb64AH5p2OKK8nc5zNqE8U/gG3oCn5nW/kM1+3HQ/kMJn DA594Kx/znTGMMDA93tJCt53nvNagYmatzFzOXrUhJKeUEsxx8pyf5J77zK2tTEbXk6Z HQvikOcxj41nZT9r4Y+/wgTLy4DbCssSYunpzpHrN+Co32WEkMLPpm4eg2rFVM9ZulfU +B/Q== 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=gkpL6W5wADmlyNHUFZldG5mVI9okFbona7uNlwuA1mU=; b=RjIvvwMPMNdI9entyJPnfD7RSEiviuBtk3Ptcr3YW2WPv8bWhceNKaiQlu2+Gtlv9J K1BCDMZgZ7LyuIWb/Js7dlJdeL0yQ2APcTbj6BQHK42BM+UVzg6DRnzjE0VQ6lgYGgsr 3Pj/43E2/wLG1aNwzB2ROEhMhFNFikGaN7/wRC6TSu1zjL3obdbUKQ2pPy5IES+O7xs4 qP+x6NbtDKbup5Vqk2rjFbScVvHTFm5Hklu1tsjiTUseX6SDWnOfZXmjoZbjWMmSNoHR tucukBN9ZyT1WVQAR+sCoyK3O9L9DbNjU7IQtXCrY3wKMIRbX7tLWTXSvqUs7yM2ANiV xeoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Qy6If4qc; 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 o13si878982jat.13.2021.08.18.14.42.55; Wed, 18 Aug 2021 14:43:05 -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=Qy6If4qc; 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 S234432AbhHRVl1 (ORCPT + 99 others); Wed, 18 Aug 2021 17:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234131AbhHRVlR (ORCPT ); Wed, 18 Aug 2021 17:41:17 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13E44C0617A8 for ; Wed, 18 Aug 2021 14:40:42 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id bo18so3637973pjb.0 for ; Wed, 18 Aug 2021 14:40:42 -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=gkpL6W5wADmlyNHUFZldG5mVI9okFbona7uNlwuA1mU=; b=Qy6If4qcKtJkUwTqjP8yxEzl81jcjqu3HXxxHD0WGo85OKcGnfjztCysIKYYXPN72G SnwjhDp/FioXSHi9fY1oM+99u51Sf23nMV3pdTq5lcrcYFl/uGbHH0LYNFERH/McPKxz NnpyYsr58PmrgdH74qwoLj/U42/4DaqEYdHIc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gkpL6W5wADmlyNHUFZldG5mVI9okFbona7uNlwuA1mU=; b=PtNlu9epRmFaIs+MtBZD5YtaiDqzhxiSpq/4pGQdDnfB/YzM+leC/NMmmJP+6CMq/S Cmv39t4IHKr2sjTGcFfMPsbwpUUTYKg3M4s8pI0AeotaZsfEkqUPMdI7FINZktwhm2Jn GyPINHljXWwGDlXRfqdahkQGTT8rTWEfGxfpIVfa1i/UzAZfDQ9wBbLZYpWxJqLFdDdf 6ktAIKQQO7YBrr84rsph0jPeK301mscC0GYZAPLrgGpsU5gbFq+8GT0102Hxx1zN55kP rFr5uBzXfkB5Pe3cfC+xd8jHcxBjCPFjYy1VTve+Suf1Y0Kfd9vjKkiRQFCKw+YI+UXq yKPg== X-Gm-Message-State: AOAM531Idekr19+IQnjWWXOZuAgV/hZM6p/JdhH1qxOaoo2HJTiyHyT7 ngKO4vqjTlyPRSyRsc/2vem9uw== X-Received: by 2002:a17:90b:fd3:: with SMTP id gd19mr9573234pjb.76.1629322841706; Wed, 18 Aug 2021 14:40:41 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x19sm834704pgk.37.2021.08.18.14.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 14:40:39 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Daniel Micay , Andrew Morton , linux-mm@kvack.org, Joe Perches , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Dennis Zhou , Tejun Heo , Masahiro Yamada , Michal Marek , clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2 5/7] mm/page_alloc: Add __alloc_size attributes for better bounds checking Date: Wed, 18 Aug 2021 14:40:19 -0700 Message-Id: <20210818214021.2476230-6-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210818214021.2476230-1-keescook@chromium.org> References: <20210818214021.2476230-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1190; h=from:subject; bh=W6Cb28S2qXmrTKUD2DPqGU+sVI4WS8pidViY5hBWcNE=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhHX5ERWo0fTNGYg6mwSKLViBT93/C8jzcI2r2WUjP LwkFmOOJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYR1+RAAKCRCJcvTf3G3AJu5UD/ 9yIUyrMR9IxHlxKAanhzIsME7zxx04n6zWRtwcafigdh/kVuzrzuRYMif8CdvvgBvmz8HJwZdDcdQE 82qUSTku6Uc0adci2vK6LHAWS+sDWZ3y83xb61th6T9qdLd8fcpin+QnJYegrBY56S1DOI4ipiyEXa w68LROW++aDn1Yb0oS+5DBCusLj0DqNdO63YohcPDDjtXNNamr5A6kjzJLbtUDeFJDxp65/gisJEo6 oV/morkS6bYX73qMpvcGnt1dXWLw6irYepPYWiyYPa29OL4bzmjo8TVNFj6869tivAN6s2p8BxyeHM 5hpfLWXwu1dC1GqLFGMxENpbegEsaqkzhn/KFG3dPkm8DFSCbTzB14kZ7wr1vqD65b1FQoZhlghJEW PWciluNwgNnwlQKgC3uvfsvBPMJvWN5974DLE/OCwJWr4P8y6OGFjeAg3GFD4ds+UgtkXb9nEwEVij SojHGWi6tife8OuVdpiyAaAousPkkz02htMpPDwG8SSxJJO1Fw9CwRWGDF0sEkOHwCCosUKhVTp8Vu UivVUOYfr/LVdMW5lpya4iiJDoBoL8ww5GKz0SAGrRpmPpbLtWALZA9bu9NmpyoloQ9lKFEAACF+dJ Fq0C6qVNHPMSUlCr0vhM7/JSbua0QjaQtTxhpC+iz25WikK4frNDFwJKbcnw== 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 page allocator interfaces, to provide additional hinting for better bounds checking, assisting CONFIG_FORTIFY_SOURCE and other compiler optimizations. Co-developed-by: Daniel Micay Signed-off-by: Daniel Micay Cc: Andrew Morton Cc: linux-mm@kvack.org Signed-off-by: Kees Cook --- include/linux/gfp.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 3745efd21cf6..897538d5ffd2 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -618,8 +618,10 @@ static inline struct folio *folio_alloc(gfp_t gfp, unsigned int order) extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order); extern unsigned long get_zeroed_page(gfp_t gfp_mask); +__alloc_size(1) void *alloc_pages_exact(size_t size, gfp_t gfp_mask); void free_pages_exact(void *virt, size_t size); +__alloc_size(1) void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask); #define __get_free_page(gfp_mask) \ -- 2.30.2