From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0404B377AA4 for ; Mon, 24 Aug 2026 04:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=44.202.169.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787544822; cv=none; b=NwInbPfIhuc93IHP42y2EiZq7HJP+FR+gvK+djCtFRaopHI3axHjU5t0AiwiG869rvetQig7KJEPxoW/riR5qkAjJoORzXWgd9/DWBgWyVlDPc6DgLIwT83NOgL3TUAigAAGlLv/5UHxSu1Zdu4hX1bXBCvqIEEwdqMIcCsdDvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787544822; c=relaxed/simple; bh=2435xp/9ahmNbyLQQVb83N0Lr+B9SCy1d+uEr0MAl6A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=uXmu+kYM/Sbf5hXUxi9OOTUYK/i4Pge8vEj/3FWlwiMoAY+uGau4dh9EhrBCLcyZz2oFDGoGxT4dDan0xI29LTtK0t1zTJxBD1aUxcRMcEkf2eVvOQWyzevZqN9OiXT/p4bWeC9wa/g1nas0awr058SjUhXPlL/kV35nd+beZNo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=embeddedor.com; spf=pass smtp.mailfrom=embeddedor.com; dkim=pass (2048-bit key) header.d=embeddedor.com header.i=@embeddedor.com header.b=jAGl1pjN; arc=none smtp.client-ip=44.202.169.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=embeddedor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=embeddedor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=embeddedor.com header.i=@embeddedor.com header.b="jAGl1pjN" Received: from eig-obgw-6007b.ext.cloudfilter.net ([10.0.30.166]) by cmsmtp with ESMTPS id yKNTwsp89LvgbyM3ywPZhE; Mon, 24 Aug 2026 04:13:34 +0000 Received: from gator4166.hostgator.com ([108.167.190.91]) by cmsmtp with ESMTPS id yM3xwThmtHZlayM3ywJPvc; Mon, 24 Aug 2026 04:13:34 +0000 X-Authority-Analysis: v=2.4 cv=RvbFLDmK c=1 sm=1 tr=0 ts=6a8bc4ee a=vY9Mjuda9oMEc2E4Cx1x2A==:117 a=vY9Mjuda9oMEc2E4Cx1x2A==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=7T7KSl7uo7wA:10 a=1XWaLZrsAAAA:8 a=VwQbUJbxAAAA:8 a=Z4Rwk6OoAAAA:8 a=nzuXsxulAAAA:8 a=pGLkceISAAAA:8 a=7ipKWUHlAAAA:8 a=vaJtXVxTAAAA:8 a=iox4zFpeAAAA:8 a=69EAbJreAAAA:8 a=4RBUngkUAAAA:8 a=7fLVpWw6CxgmVm_BPEcA:9 a=QEXdDO2ut3YA:10 a=HkZW87K1Qel5hWWM3VKY:22 a=Jn5cl5okm61iLnyvC_SE:22 a=gpc5p9EgBqZVLdJeV_V1:22 a=WzC6qhA0u3u7Ye7llzcV:22 a=_sbA2Q-Kp09kWB8D3iXc:22 a=2aFnImwKRvkU0tJ3nQRT:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gj4LfR3NBw51e8QVdaIwPPt1n59fzXjAnZBVB9Yaggk=; b=jAGl1pjNgmwez7x3hhwtZlfx3k 7RlOP/wGqfxdI4A6xXRGz2bfBwSMwsMus8Jf7EngqITqpXWtg9sT23M1myxsjhHUAWO6Nro4Ha19r jaNC2CWxuv6gDqqPHCDODD2Mf9NVzIJfpwyc3EvgMWXydK/RLkwByT7HC8/sIL27nPr6DnxxACfwe +IY+XABFm3r4oI1oqUoBVRRt9kD3Q+ENKxsoINBySUP5y8F9/bRHMAaS6GXZiBeCvPpL6Z1WyKr6v TyUGB4vP7YJhRsDg8/DkuBsaBxvOZ2NYWkgmtIPrbsXVmfh9ibE0brf9ftvhAvGUkst+lZi/cKQpg tzRDE9Vg==; Received: from [59.16.68.142] (port=55006 helo=[192.168.0.146]) by gator4166.hostgator.com with esmtpsa (TLS1.3) tls TLS_AES_128_GCM_SHA256 (Exim 4.99.5) (envelope-from ) id 1wyM3s-00000000NgN-0uXx; Sun, 23 Aug 2026 23:13:28 -0500 Message-ID: Date: Mon, 24 Aug 2026 13:12:35 -0600 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] stacktrace: Add __counted_by_ptr attribute to struct stack_trace To: Bill Wendling , linux-kernel@vger.kernel.org Cc: Kees Cook , "Gustavo A. R. Silva" , Andrew Morton , Brendan Higgins , David Gow , Rae Moar , Ryota Sakamoto , Kuan-Wei Chiu , Pasha Tatashin , Dmitry Antipov , Petr Mladek , Kir Chou , codemender-patching+linux@google.com, linux-hardening@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com References: <20260823123549.1120133-1-morbo@google.com> <20260823123549.1120133-2-morbo@google.com> Content-Language: en-US From: "Gustavo A. R. Silva" In-Reply-To: <20260823123549.1120133-2-morbo@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 59.16.68.142 X-Source-L: No X-Exim-ID: 1wyM3s-00000000NgN-0uXx X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.0.146]) [59.16.68.142]:55006 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfDn3vDNJnTtxV7eNPQc5vXxEysFckw4pPlVrNqSmGufxvGivFXJN78IAzLRRlw+ppoum0S/pX9fRSVCEmrUXKTu6fKSvIeFFnGBdZEjHyGr8WOMJ9LZK vPkC+R+Jt7JNQZXXSd9UlASwu6NhBRKt2b6K/sXFMAjyRPLUz2OheoPqWYbQkQ5cxTi6ASJxzEYf7SgO0pmNIyATy8t72ItguT9or8nvL0avK1dc1XTD17iN On 8/23/26 06:35, Bill Wendling wrote: > For hardening and catching out-of-bounds accesses to the 'entries' > pointer field in 'struct stack_trace', associate it with its count > field 'max_entries' using the __counted_by_ptr attribute. > > An analysis of the codebase reveals that 'struct stack_trace' is > instantiated and initialized across several entry points in > 'kernel/stacktrace.c'. In each execution path, 'trace.entries' is > assigned a buffer of size 'size', and 'trace.max_entries' is assigned > 'size' concurrently within the structure's initializer block. The > pointer is not accessed before the count is set. > > Because 'trace.entries' is always assigned at the same time as > 'trace.max_entries' during initialization and is never reallocated > or accessed beforehand, there are no uninitialized access windows. > The 'max_entries' field accurately holds the exact element count > of the buffer allocated for the 'entries' pointer, ensuring that > compiler fortification and KASAN bounds checks using __counted_by_ptr > do not trigger false-positive bounds checks or runtime panics. > > Assisted-by: Gemini Next > Signed-off-by: Bill Wendling Reviewed-by: Gustavo A. R. Silva Thanks -Gustavo > --- > Cc: Kees Cook > Cc: "Gustavo A. R. Silva" > Cc: Andrew Morton > Cc: Brendan Higgins > Cc: David Gow > Cc: Rae Moar > Cc: Ryota Sakamoto > Cc: Kuan-Wei Chiu > Cc: Pasha Tatashin > Cc: Dmitry Antipov > Cc: Petr Mladek > Cc: Kir Chou > Cc: codemender-patching+linux@google.com > Cc: linux-kernel@vger.kernel.org > Cc: linux-hardening@vger.kernel.org > Cc: linux-kselftest@vger.kernel.org > Cc: kunit-dev@googlegroups.com > Cc: linux-hardening@vger.kernel.org > --- > include/linux/stacktrace.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h > index 97455880ac41..fbb0925d8864 100644 > --- a/include/linux/stacktrace.h > +++ b/include/linux/stacktrace.h > @@ -81,7 +81,7 @@ unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries); > /* Internal interfaces. Do not use in generic code */ > struct stack_trace { > unsigned int nr_entries, max_entries; > - unsigned long *entries; > + unsigned long *entries __counted_by_ptr(max_entries); > unsigned int skip; /* input argument: How many entries to skip */ > }; >