Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp16181pxb; Wed, 18 Aug 2021 14:42:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySe+I508NF2b4k9LyyMkl2XPTsJJcqurfvfePyMKv3HRfQHq907UZWwjXoe8F2v0IT8W5m X-Received: by 2002:a6b:fb07:: with SMTP id h7mr8584359iog.201.1629322937114; Wed, 18 Aug 2021 14:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629322937; cv=none; d=google.com; s=arc-20160816; b=WfiqaTZgJzjBDRn1UkuxJUr+FGsOrewt0icYu8j2X5AbGzIGBU3XGfDsyFsaE8WRWZ 9FQ8zdNEEKOao03z7dYjDw04veVdO+zELi0yjmEZZ7LTBOWfrtmBZyNUe4rPhyhZpCRq EM0pXMIrCJfKDmN+ldizYKPK+eDnlLhwI8tIYotKoWFCqQoGWZr5omQRWsD9Q9PO2kZi 1d/q0K7EqSVIGOkyg72y/HBjpAkHahxMXD1Mja6gfTjVXfGh3RX9aGy293PYGcbrMDIR 89fWgvK6UD8VYjZYHt19LbDT3UkfK0qQpvlM0lYOwvKdwK8wPPumUhAV2zUn9/3kaePp Togg== 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=obyCsyhTKD9ULYgdRm0xF6fBRvJ21Igqh3M9baDJkzs=; b=EPNYyCh9zsYTkaoM/SIs9locvr8maewrO8KX44rkuQpXJrKk9C15JTT18hqcrbBet0 D67dfae8dcgbyM1EKiNkpFB9o7HtLwvv6yKWDf/Fvja3NRrtWlV2zErQV32yvdZTSXXd 673uM9YL9QdZCPsgbi9BRBvQZ38qbCVDwM0SrHFZeDMSszWMviI/2xEfCsu3WYfqKfpj hxoZIgO1gY2x0nEN8GDFt600d9+8mHEwImfJnxqhI5CBe0jCsqmpmxLJRJdV7M9isl1R e8E5tfJL66HSzqb2O2YXlNa+oPnKijKjc05bu9l4vc9OSY/eC2POQLk41lnT4vAH0ZcX NPxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gfoOfwCn; 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 r8si766328jar.122.2021.08.18.14.42.06; Wed, 18 Aug 2021 14:42:17 -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=gfoOfwCn; 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 S234491AbhHRVlb (ORCPT + 99 others); Wed, 18 Aug 2021 17:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234244AbhHRVlS (ORCPT ); Wed, 18 Aug 2021 17:41:18 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ECB0C0617AF for ; Wed, 18 Aug 2021 14:40:42 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id k14so3733903pga.13 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=obyCsyhTKD9ULYgdRm0xF6fBRvJ21Igqh3M9baDJkzs=; b=gfoOfwCntAnNAJFuBtpqMhXssh75dB9pXawiBDuYUsb1knx7XpO1ULvRh4UWBQI7Bz FOhaEa6ykLVedUd4BqcLZqz1Ht+0PebP3lMGcJwf+KZNzHWuIHV+/cKUxmXqqYpMNcso Gyv2LEVmZMkaWyOxL2QsZi+qfz4ZSubt89mXs= 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=obyCsyhTKD9ULYgdRm0xF6fBRvJ21Igqh3M9baDJkzs=; b=rwFiimLFRSrysXsMf9QVN/l/LTDaG63i4ddnUfY/+jgIkvsJljYx0//51mJEf+AOKH 0d272DpWg9cCm3Cv5mEcohCGelJhLtE1/s2rcS67oiRyPU2KRPqWHltc5TT9d0W4N47L jpfMqPg5TvSkYzGl1JRgIa0ka06gcwnGC7icSIt9kkPbab3tb3W27XU6bTBuOalxHBgH sTb1euurvaJ2mA+A3e4JQ3brnacHCUQ2uLv9R5LCTfQr9z7d1VFsUR5Ybb+NLpLBn4Kd 0j9B95+9FddRavMvI0B38zEQYVI1oS5EuP5nuzoYKpscRlR12jWg5uRCKuhOXh8lgBFk Lqjw== X-Gm-Message-State: AOAM531ckWrwC3b7EHU7kTaemTyEdUixSj1rdeWR/OFLQLlsW+1DPAM6 WB756FR5KLYz21mtAhEDq+IXjQ== X-Received: by 2002:aa7:9086:0:b029:39b:6377:17c1 with SMTP id i6-20020aa790860000b029039b637717c1mr11523853pfa.11.1629322842023; Wed, 18 Aug 2021 14:40:42 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d22sm2428pjw.38.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 7/7] mm/vmalloc: Add __alloc_size attributes for better bounds checking Date: Wed, 18 Aug 2021 14:40:21 -0700 Message-Id: <20210818214021.2476230-8-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=1906; h=from:subject; bh=zZAhvg0/X2ZvejN1Ximar4dbpGivh/+QQFsXl6ok5Vw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhHX5EQcnqyfy1qEIP1S4mcozbG6+autpWOD9SsOFn +9NTZ52JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYR1+RAAKCRCJcvTf3G3AJkdcD/ 9jF1T7G8iKELXphXJtJn6dWEfa0njsQ+5w/PgRzIb8ou0ZSzyTfJxwPTEhiiS8YfBZIbgG1olvXO1/ 9jlS/Jl7O6s1zJrbjTkAG+0YryyZeUgN0ikB5brvDOQADIQKa8Qv9p0nJ8PfnTzf3Y51GwQnLYTYYm m1pgQQJWt4Me+uYokWJyi5GZRoplJ7c7nEUJ/wfR3DD9fKzuP2kDP8cxiSFG+Th587g8qd0y/jaonj m2Phd4OY38vdxSbHtXYJHgVrnV4mdjhJI0fq7+/X7e6DsXV0seK8QO6/wgQP4hqUSLSUCQIunNHA+L IB2DZ95EFj6p7mKVVqGUNsqZZtAR40ad8E60M1SkpPImENeFhkBvCxk64cZo8j2rNryfFZJPYqD0/5 fVi75RuDWLa74deb59h0nK9wYA8qe62eXlCl0SZTz0GPBhPJXbgRwD4e0gHoZA5I4nRYjc+g6SYrl+ cBJNjVlr6nOYr59zb63l3gaBmo7CjoRlYRLlhlOor0UwVo4mDt6HgFO9Ns0hm7Q+z9TfKhBgVvJfgm rUxXWyozpmm26ROVdgGw7jhw1PCulKCVaFADIaMLXfZ156UUZirAS1jaQQQ0rhFNtKOUrtoGZJsmlD SO/O279GWNlF3ovkUXiQFuJ5GbVSkbIwwuCdsVeHSk0PssdSMAWKGEHE637g== 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 vmalloc 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/vmalloc.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 2644425b6dce..1521ba38957d 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -136,20 +136,31 @@ static inline void vmalloc_init(void) static inline unsigned long vmalloc_nr_pages(void) { return 0; } #endif +__alloc_size(1) extern void *vmalloc(unsigned long size); +__alloc_size(1) extern void *vzalloc(unsigned long size); +__alloc_size(1) extern void *vmalloc_user(unsigned long size); +__alloc_size(1) extern void *vmalloc_node(unsigned long size, int node); +__alloc_size(1) extern void *vzalloc_node(unsigned long size, int node); +__alloc_size(1) extern void *vmalloc_32(unsigned long size); +__alloc_size(1) extern void *vmalloc_32_user(unsigned long size); +__alloc_size(1) extern void *__vmalloc(unsigned long size, gfp_t gfp_mask); +__alloc_size(1) extern void *__vmalloc_node_range(unsigned long size, unsigned long align, unsigned long start, unsigned long end, gfp_t gfp_mask, pgprot_t prot, unsigned long vm_flags, int node, const void *caller); +__alloc_size(1) void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask, int node, const void *caller); +__alloc_size(1) void *vmalloc_no_huge(unsigned long size); extern void vfree(const void *addr); -- 2.30.2