From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EB683CB8E2 for ; Sun, 23 Aug 2026 12:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787488560; cv=none; b=RGqYH0RRelC8bCBUXlN1MV8/BYSsMX5JwAHeHaqbHERTbzS4uGcZVgkwJw1YRSnQx9mS8Fq6CWFt+lqO8HLHtU/vWOv55a7yEAlHU5tG2IVwfdAXQtf2PiDFAiG0zUZeuV5NGUDIpXk2y1apSiVKsxkjgq2j1jtmAvfHCYnfPbU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787488560; c=relaxed/simple; bh=yWZFWInH1rLjyv8+mSonhwyX1ShwC2bCnUBa5J/c4L8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WaUUOKxIxpS+SwmjuqG23644zc0TCprcaLdEx5kJMpgEVbag/B4I1gf51wXl69YxIDJqg/X2S+gYFEm7HdMY9eCiqs0qPwfIQ+f9t43MXjlIuD6FyGV1We9/NVlqLyNz7XyeyL5eI1Ho9oZswF6Gtw9V/PaQTPZnf5aWz2llOmw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--morbo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TgK7Bhw7; arc=none smtp.client-ip=209.85.214.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--morbo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TgK7Bhw7" Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2cc86a9ef97so48164785ad.3 for ; Sun, 23 Aug 2026 05:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787488558; x=1788093358; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=c6pl/FAkhJGdRW7xNY1Vo7P4vt1vAKgIpkL7cBZjl4I=; b=TgK7Bhw7L0dLYKOLtqXS928Q5WdXacnro0wu+Pts0iBvvn/b7crp28K1AfrCBgu6HG R/vEc2+Up+d7Zwotbt4CRllsoW67Cwd/xMb7uMyjK3GkQ/XkAgl8iugsNoQc4K1yg9Am j877Q+3a0LgQSQaeiKGCOUXHe2eYepbQTt4dfKGuHEDQVXmt9sxg7gAuWa/s9i7kktTZ NanKuxooawhCp9yiWydnwyEMb02zhKTHbSsdKYset4NE+wVwlwl1eR1MXgP8zAGegi64 uRk/JJQDqFb1Z/0ddLy+iC7340mSZGl0Z4dmX/xvLqTWDHFSmRL4qvqG5mcofe3buyKK d1Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787488558; x=1788093358; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=c6pl/FAkhJGdRW7xNY1Vo7P4vt1vAKgIpkL7cBZjl4I=; b=kyMIXrc8QISAtHoLaPc3fys3W+TFbEIJzvxDSRvbaoa9p85sISXSEHAJPu+qa1Vo68 l8QctjU92M7V7ErKE47kQHi+QC36UzS2oZAetjAyQ5IHie3QKugrcECNuhFZkCY93pyL DtSEo9ngPqIEXfop7fMiomsTMD7zERAQxGLcQf3+Ei4YBgWZ8gcoHf9JS6CqEp18YltX evtM/5CdLCH5ZExD9TBIch9NsYJxwH/OPLJKe4bAXcwbEWgg9C8jRuhewlqIqGffBpII X05fTVNoL3VSha3WltmoP826iHPnBMENl7M9DHmSf1t2FaGPI0shVBTbNQmy2aj3yUfE /OSA== X-Gm-Message-State: AFuF++lJygJtPxfGpwVoJo95sMgpphD5Qf3g+MiVwKIgZ6oI21npZ+Fp CxIcX67Fkajw8SlCV/GhvXMi+DwaaIOHngCum5KQ35Wtyr1fLh3XCkztcVxpa+TmZ2Kmeu+1gtW zfQYhUucVD+jWEMrdobTAv3CvkW2smr34Raq78o8GcjabynkUU3SMRpbgwaBipwYEnb3PSQVtTV /leAbj8UHkOhiKP93DcurtfJO9k3g9Yalvju1Mpg== X-Received: from plhi12.prod.google.com ([2002:a17:903:2ecc:b0:2c7:ebed:f6e8]) (user=morbo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:390d:b0:2c9:fb11:1bf4 with SMTP id d9443c01a7336-2d64af4eea9mr368056955ad.7.1787488558140; Sun, 23 Aug 2026 05:35:58 -0700 (PDT) Date: Sun, 23 Aug 2026 12:35:32 +0000 In-Reply-To: <20260823123549.1120133-1-morbo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260823123549.1120133-1-morbo@google.com> X-Mailer: git-send-email 2.55.0.860.g4b6b3295ed-goog Message-ID: <20260823123549.1120133-2-morbo@google.com> Subject: [PATCH 1/2] stacktrace: Add __counted_by_ptr attribute to struct stack_trace From: Bill Wendling To: linux-kernel@vger.kernel.org Cc: Bill Wendling , 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 Content-Type: text/plain; charset="UTF-8" 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 --- 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 */ }; -- 2.55.0.860.g4b6b3295ed-goog