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=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 5F955C4338F for ; Wed, 18 Aug 2021 21:40:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0FB5061101 for ; Wed, 18 Aug 2021 21:40:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0FB5061101 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 AB4C28D0002; Wed, 18 Aug 2021 17:40:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3D656B0071; Wed, 18 Aug 2021 17:40:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8421B8D0002; Wed, 18 Aug 2021 17:40:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 52F7E6B006C for ; Wed, 18 Aug 2021 17:40:39 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F2D3180757AA for ; Wed, 18 Aug 2021 21:40:38 +0000 (UTC) X-FDA: 78489520998.03.A873C6C Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf20.hostedemail.com (Postfix) with ESMTP id BCF6DD0027BA for ; Wed, 18 Aug 2021 21:40:38 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id gz13-20020a17090b0ecdb0290178c0e0ce8bso5975538pjb.1 for ; Wed, 18 Aug 2021 14:40:38 -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:mime-version :content-transfer-encoding; bh=akAmUlIHVyMCnIAEIuPla2RgaGumEDghjwfRk7fePO8=; b=a8rtLFTutCVX8kAVFQBoCFVIFF3XhbHoHk315ZS95VwdPVZZOWozYUV6xXg1LFhzmR b97DOY2X4uTQmBQ0MoV3QYP9jiCOqetKVeS7PzpRs7el0f/9EWLG13/qyjRg3eYOrqle PHl8LB4eQdIb4RU1oDqKh+w1JuI0NlIdvBCg0= 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:mime-version :content-transfer-encoding; bh=akAmUlIHVyMCnIAEIuPla2RgaGumEDghjwfRk7fePO8=; b=HC19WqVKafcQcxfN2z321pd8PCNGfpdiOMhlxq3yOJvq+rc5P9dKNllSQZZspAZg97 mpzLad3iTC39MVii1lBKvok/TZ+xiKHZOHwVNN4g8ngnNwqvtH8U+zxcjOu168B1WmQ0 mkCTsCaY//5P3Lq7gOwCp+CNJuym94NtKMRj28Q4tMQl9+Xm2tMlw/p9Ql8PM/jr6sbp +glR1DYuV/+6y3uf44yPWNXhlOz4ZGU0aN2kz0yP9zdwbabjasDDGarHqWFB8KUvR0vo 49KuEFrDGMySEjkvyYuIndidxXZoGt5cIiJxlNVWuMa14aKeHewntNbKRGJyduabK0+p 9p/Q== X-Gm-Message-State: AOAM530g5b7pgGbUsxznx1LKRhgKx5ZjQ8L1Cr1XzYRRM9ITz2R9/p5m Q/qR+Q06D14L7VX7KxdwncDHzw== X-Google-Smtp-Source: ABdhPJxlfTcGT5J/BnXQskI5QEMAEBFE/p6siy3ePLuxLeCum7fhGWFhGAhEGkJ746Sknz1WraR08Q== X-Received: by 2002:a17:90a:c7cc:: with SMTP id gf12mr11236442pjb.152.1629322837839; Wed, 18 Aug 2021 14:40:37 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u16sm833047pgh.53.2021.08.18.14.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 14:40:36 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Joe Perches , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Daniel Micay , Dennis Zhou , Tejun Heo , Masahiro Yamada , Michal Marek , clang-built-linux@googlegroups.com, linux-mm@kvack.org, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2 0/7] Add __alloc_size() for better bounds checking Date: Wed, 18 Aug 2021 14:40:14 -0700 Message-Id: <20210818214021.2476230-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1862; h=from:subject; bh=rsMgLXm/8j8zp3cC9QOAG2syHyng6bO/WmNVEexJxdo=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhHX5CJ/SlNYpWE0Ykxq+PzeUKRG1gC/093Z7fxOqZ wEYXCCiJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYR1+QgAKCRCJcvTf3G3AJo3AEA CRpUXhzKUXa83bU08HMYk8w3CI0lPzuD6WVd7f8zuaswtTFfH/Hhf0jvPMTmoC6K5Pd8AE87/wBmUH movYpOXkti6rw/ORur3peVR7FtzjxTcbY+KfjktIU9xbLcdj1GyKNr/ZnXqH4tiGuIYzl7+QIgC1pl Z26pG54aUxZVwgdaBgr3YBwyn9zwNcNlth7UdxDilgHrFB6xeEGdbCwSirgpnboJrVjpve3lDgwjH4 Q6zPPWan82zmnP0HbY/T6brScwp5MpHW3UhTzdcfUfBNxmjfhIQHAhoVcXGlJUyBbHnrINSOv75H3y 6F0wiCpckheLpTgrio85Ydq4S0Et/JtOpejeclbEYhrqe/2D6urk8FEqBKHf7rC7uFlINsuc8z11PS S6WF29dvRToPp4kvE45ge5eIdj24peW4NzGhCGDXPhraGd8tFxLV4F9Vq8g4F2UdbnqkGhN6HNs5OG Te+aSJseJhr+FaAANM8fvXBQzTjM4RGQeFtDwvcWU2zPq5bx3bJCaNTOHnyjGZ/KNS0rxGw8JeqBHF CO8EYPvzIhHVVUT0lebK+o9O0vanvKwUKcy1h1eR8DRx4bK7g8c91Hm59872I8zDPjw1ovaybRAzrv 7Nul/uQgIzzglOXzFM5EZix4zg1+ua3rV5n79ekbMFaagG9uz9kIWkTK2sGA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=a8rtLFTu; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf20.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.52 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Stat-Signature: 8xsdiupyo3pgon8wm1sw7p8nhz53ofb8 X-Rspamd-Queue-Id: BCF6DD0027BA X-Rspamd-Server: rspam05 X-HE-Tag: 1629322838-478022 Content-Transfer-Encoding: quoted-printable 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: Hi, GCC and Clang both use the "alloc_size" attribute to assist with bounds checking around the use of allocation functions. Add the attribute, adjust the Makefile to silence needless warnings, and add the hints to the allocators where possible. These changes have been in use for a while now in GrapheneOS. To build without warnings, this series needs a couple small fixes for allmodconfig, which I sent separately: https://lore.kernel.org/lkml/20210818174855.2307828-5-keescook@chromium.o= rg/ https://lore.kernel.org/lkml/20210818044252.1533634-1-keescook@chromium.o= rg/ https://lore.kernel.org/lkml/20210818043912.1466447-1-keescook@chromium.o= rg/ I figure I can take this via my "overflow" series, or it could go via -mm? -Kees v2: - clean up slab function declarations (joe) - update checkpatch.pl attribute regex (joe) - explain the Makefile changes better (ojeda, nathan) v1: https://lore.kernel.org/lkml/20210818050841.2226600-1-keescook@chromi= um.org Kees Cook (7): Compiler Attributes: Add __alloc_size() for better bounds checking checkpatch: Add __alloc_size() to known $Attribute slab: Clean up function declarations slab: Add __alloc_size attributes for better bounds checking mm/page_alloc: Add __alloc_size attributes for better bounds checking percpu: Add __alloc_size attributes for better bounds checking mm/vmalloc: Add __alloc_size attributes for better bounds checking Makefile | 6 ++- include/linux/compiler_attributes.h | 6 +++ include/linux/gfp.h | 2 + include/linux/percpu.h | 3 ++ include/linux/slab.h | 84 +++++++++++++++++------------ include/linux/vmalloc.h | 11 ++++ scripts/checkpatch.pl | 3 +- 7 files changed, 80 insertions(+), 35 deletions(-) --=20 2.30.2