From: Thorsten Blum <thorsten.blum@linux.dev>
To: Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] lib/string_helpers: annotate struct strarray with __counted_by_ptr
Date: Wed, 15 Apr 2026 14:25:45 +0200 [thread overview]
Message-ID: <20260415122542.370926-6-thorsten.blum@linux.dev> (raw)
In-Reply-To: <20260415122542.370926-4-thorsten.blum@linux.dev>
Add the __counted_by_ptr() compiler attribute to 'array' to improve
bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
lib/string_helpers.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 6a8db441b6fd..98d6ed0eaab7 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -805,7 +805,7 @@ void kfree_strarray(char **array, size_t n)
EXPORT_SYMBOL_GPL(kfree_strarray);
struct strarray {
- char **array;
+ char **array __counted_by_ptr(n);
size_t n;
};
@@ -824,13 +824,13 @@ char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)
if (!ptr)
return ERR_PTR(-ENOMEM);
+ ptr->n = n;
ptr->array = kasprintf_strarray(GFP_KERNEL, prefix, n);
if (!ptr->array) {
devres_free(ptr);
return ERR_PTR(-ENOMEM);
}
- ptr->n = n;
devres_add(dev, ptr);
return ptr->array;
next prev parent reply other threads:[~2026-04-15 12:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 12:25 [PATCH 1/2] lib/string_helpers: drop redundant allocation in kasprintf_strarray Thorsten Blum
2026-04-15 12:25 ` Thorsten Blum [this message]
2026-04-15 14:42 ` Andy Shevchenko
2026-04-15 15:30 ` Thorsten Blum
2026-04-16 7:48 ` Andy Shevchenko
2026-04-30 14:39 ` Thorsten Blum
2026-05-13 17:53 ` Kees Cook
2026-04-15 18:38 ` David Laight
2026-05-13 17:54 ` Kees Cook
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=20260415122542.370926-6-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.