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,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 176F3C4320E for ; Wed, 18 Aug 2021 05:08:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A53276103A for ; Wed, 18 Aug 2021 05:08:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A53276103A 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 6AC776B0074; Wed, 18 Aug 2021 01:08:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60E698D0002; Wed, 18 Aug 2021 01:08:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 465646B0073; Wed, 18 Aug 2021 01:08:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 28DEC8D0002 for ; Wed, 18 Aug 2021 01:08:46 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C38AD181555F5 for ; Wed, 18 Aug 2021 05:08:45 +0000 (UTC) X-FDA: 78487021410.04.311B5CD Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf23.hostedemail.com (Postfix) with ESMTP id 7B1F99007076 for ; Wed, 18 Aug 2021 05:08:45 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id gz13-20020a17090b0ecdb0290178c0e0ce8bso4516962pjb.1 for ; Tue, 17 Aug 2021 22:08:45 -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=ibfYg9pbryt9B5bM+TpRAt9ju/X9d6W3Gs+jxd+YtkU=; b=g4c93iNehB9VMgT8ohcQ2DTJpLbRTcPBX11gQZpAeoIJv0399CHnkPyELherSb4clp 1K/KxP5FszZ81iDLg0QVY2WZlelG+LztfsxtZ2Rkb/8pSReiRloywS6qUGybT55xP3oo Y/pu24ZALeRP4SMmrarBPMhnrqDCkEa+A5N3E= 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=ibfYg9pbryt9B5bM+TpRAt9ju/X9d6W3Gs+jxd+YtkU=; b=kcdxcSULlL2Dxgx6xmX0lCCPuvA0o5YFsCDrqgDbJ4FEckFK88NCYCx0DdvW8gALol Fvo+3pqnB7f2CDwIXZn8n3LpEMo5P7hV0rayuHwmnXpuwaRM6iWIbK7TMXt4z3LTmoa+ x9ZNI+dkUi63NiI6X1+qSooebXL6GE6zQOKZwkEhKM5yUZhZ5gP1/DKqMf/iIim6TKfP 6XTr4no7iwrclvdV5aMDKwI61uHoiwxM0v0ywQIQQT2YJAeoIFt5CRb/grTk2ywLE/gL 4gu7HDbZALXXusEOhrojKLIJRzBkczbRHiXxNWztGjEMHI9fiPL86hp42QWZ8+t2PGUS pQdQ== X-Gm-Message-State: AOAM533z/HZaLpiKWQ05SBjbyK/YvWWkOsUMv0E3fKR/NwvvIZ+Y19Fp oZnJu3OFHj3KriTj4n1rxeiY/Q== X-Google-Smtp-Source: ABdhPJyUeG6+/fDFxS9Zq+Bmi6OpbrosbvZbi/vfiZ0w8iRHjHykfuiwrP9/HatrLXYJ89g6pzdjlw== X-Received: by 2002:a17:90b:360a:: with SMTP id ml10mr7312861pjb.134.1629263324660; Tue, 17 Aug 2021 22:08:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q21sm3578775pjg.55.2021.08.17.22.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 22:08:43 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Andrew Morton , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Daniel Micay , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , 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 0/5] Add __alloc_size() for better bounds checking Date: Tue, 17 Aug 2021 22:08:36 -0700 Message-Id: <20210818050841.2226600-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=1503; h=from:subject; bh=M1Tok+LfKYfKMg3IsfepbLLdtBAUXEFJ6hNboUgrVcQ=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhHJXX4iubi2i9iuFz+LsiKuwROx1EI+5yY5ZbGOgo sK/JE9+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYRyV1wAKCRCJcvTf3G3AJpXhD/ 4z085X3Ll8rZJC6uVrygExuVDtlwKRRcu1+fsHdRvTBsNePyBe6eM7MdWyzSU6pRDGSwoPBBggFZ0F jYxajPqmHe9N5J8ZRMoRF/c+TcctzqSJjvaMxRrULJzBvM00RDUmapmE7i7gGeB8nsgMopdiuNpIFk eSzlfd5/V66zAWa2+vZ2gDFgHjWQIMrU4U7QeajbQOfbxYmzeN7nT5T7UTAtszzl4Dz29khVmFSxQK 8O8+mgv+S3HnLHpsm/X9189a9gx9FrY5CmmojA1NLFshWiMFwt0HqBWax2L0RA+QCj5YBTy5blQUve +qaLIvFS/G43o2Hr2KaK2BeROLFr9c/ridogvWg/BGM7Ohlervc/vSS9vGnrd1EAyNZ8VovR76HmA0 YceN0FYjjjrn0C2IaX1315H6wz71VTBRZMfQ3UUrzGFDzPLpqRd1jXKw0sXKQxAOJAqNIhOrdYse2U Z1DmuGpFHPFq7IWT12lvVMbY6on1GJy72xVVct1ZgUQpLTolS2BmWvpDFgTATpXlRSiiylxlEGY8dT AJEBIUkvRLFhe/ThymPuUkqCLfnMVsiTlbo3grvPI74w2D0zbBpsQXXry5IOI/9wBDD98Dczq0qdDd pwOrFTKxLBfnL6zBGq7mCyUtLzJzOTgVR+wyP4t3kuzVj/KqpTV0/LACImUQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=g4c93iNe; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf23.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.46 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Stat-Signature: 9ifo67ckpea47pjjczuh4f4o8arau61m X-Rspamd-Queue-Id: 7B1F99007076 X-Rspamd-Server: rspam05 X-HE-Tag: 1629263325-345189 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/20210818044540.1601664-1-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 Kees Cook (5): Compiler Attributes: Add __alloc_size() for better bounds checking 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 | 4 +-- include/linux/percpu.h | 6 ++-- include/linux/slab.h | 50 ++++++++++++++++++----------- include/linux/vmalloc.h | 22 ++++++------- 6 files changed, 58 insertions(+), 36 deletions(-) --=20 2.30.2