From: Bill Wendling <morbo@google.com>
To: linux-kernel@vger.kernel.org
Cc: Bill Wendling <morbo@google.com>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <david@davidgow.net>, Rae Moar <raemoar63@gmail.com>,
Ryota Sakamoto <sakamo.ryota@gmail.com>,
Kuan-Wei Chiu <visitorckw@gmail.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Dmitry Antipov <dmantipov@yandex.ru>,
Petr Mladek <pmladek@suse.com>, Kir Chou <note351@hotmail.com>,
codemender-patching+linux@google.com,
linux-hardening@vger.kernel.org,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com
Subject: [PATCH 1/2] stacktrace: Add __counted_by_ptr attribute to struct stack_trace
Date: Sun, 23 Aug 2026 12:35:32 +0000 [thread overview]
Message-ID: <20260823123549.1120133-2-morbo@google.com> (raw)
In-Reply-To: <20260823123549.1120133-1-morbo@google.com>
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 <morbo@google.com>
---
Cc: Kees Cook <kees@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <david@davidgow.net>
Cc: Rae Moar <raemoar63@gmail.com>
Cc: Ryota Sakamoto <sakamo.ryota@gmail.com>
Cc: Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Kir Chou <note351@hotmail.com>
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 */
};
--
2.55.0.860.g4b6b3295ed-goog
next prev parent reply other threads:[~2026-08-23 12:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-23 12:35 [PATCH 0/2] " Bill Wendling
2026-08-23 12:35 ` Bill Wendling [this message]
2026-08-24 19:12 ` [PATCH 1/2] stacktrace: " Gustavo A. R. Silva
2026-08-23 12:35 ` [PATCH 2/2] lib/tests: Add KUnit test for struct stack_trace __counted_by_ptr attribute Bill Wendling
2026-08-23 15:11 ` Kuan-Wei Chiu
2026-08-24 6:41 ` Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260823123549.1120133-2-morbo@google.com \
--to=morbo@google.com \
--cc=akpm@linux-foundation.org \
--cc=brendan.higgins@linux.dev \
--cc=codemender-patching+linux@google.com \
--cc=david@davidgow.net \
--cc=dmantipov@yandex.ru \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=note351@hotmail.com \
--cc=pasha.tatashin@soleen.com \
--cc=pmladek@suse.com \
--cc=raemoar63@gmail.com \
--cc=sakamo.ryota@gmail.com \
--cc=visitorckw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®