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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1800BC433FE for ; Wed, 6 Oct 2021 01:47:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED69860FC1 for ; Wed, 6 Oct 2021 01:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237125AbhJFBtM (ORCPT ); Tue, 5 Oct 2021 21:49:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229908AbhJFBtL (ORCPT ); Tue, 5 Oct 2021 21:49:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D00A611CC; Wed, 6 Oct 2021 01:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1633484838; bh=Xt+wZ6PkpbqGmpCET0SN48ylqvwvPAINuGHGp2TK1uY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IxA2DMOOXNCn02Sbwsru0IXmgNMs9rv4nMcyqr06+2YctzkpKzNPO6CCXPdKM1Np0 t7lmbu0FEO37bLus65CjV0G166hksDhs7XFigmUyv4IM9aFkaL9zjCRpK2rOMsWEqX EkL6cytWknEjtB//VUBv0jEX19efvyxzhNHUIrns= Date: Tue, 5 Oct 2021 18:47:17 -0700 From: Andrew Morton To: Kees Cook Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Andy Whitcroft , Dennis Zhou , Dwaipayan Ray , Joe Perches , Lukas Bulwahn , Miguel Ojeda , Nathan Chancellor , Tejun Heo , Daniel Micay , Nick Desaulniers , 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: Re: [PATCH v3 4/8] slab: Add __alloc_size attributes for better bounds checking Message-Id: <20211005184717.65c6d8eb39350395e387b71f@linux-foundation.org> In-Reply-To: <20210930222704.2631604-5-keescook@chromium.org> References: <20210930222704.2631604-1-keescook@chromium.org> <20210930222704.2631604-5-keescook@chromium.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 30 Sep 2021 15:27:00 -0700 Kees Cook wrote: > As already done in GrapheneOS, add the __alloc_size attribute for regular > kmalloc interfaces, to provide additional hinting for better bounds > checking, assisting CONFIG_FORTIFY_SOURCE and other compiler > optimizations. x86_64 allmodconfig: In file included from ./arch/x86/include/asm/preempt.h:7, from ./include/linux/preempt.h:78, from ./include/linux/spinlock.h:55, from ./include/linux/mmzone.h:8, from ./include/linux/gfp.h:6, from ./include/linux/mm.h:10, from ./include/linux/mman.h:5, from lib/test_kasan_module.c:10: In function 'check_copy_size', inlined from 'copy_user_test' at ./include/linux/uaccess.h:191:6: ./include/linux/thread_info.h:213:4: error: call to '__bad_copy_to' declared with attribute error: copy destination size is too small 213 | __bad_copy_to(); | ^~~~~~~~~~~~~~~ In function 'check_copy_size', inlined from 'copy_user_test' at ./include/linux/uaccess.h:199:6: ./include/linux/thread_info.h:211:4: error: call to '__bad_copy_from' declared with attribute error: copy source size is too small 211 | __bad_copy_from(); | ^~~~~~~~~~~~~~~~~ make[1]: *** [lib/test_kasan_module.o] Error 1 make: *** [lib] Error 2