From: Bill Wendling <morbo@google.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Kees Cook" <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org,
"Bill Wendling" <morbo@google.com>,
codemender-patching+linux@google.com
Subject: [PATCH v2] iio: gts-helper: add __counted_by_ptr to struct iio_gts
Date: Wed, 23 Sep 2026 19:24:50 +0000 [thread overview]
Message-ID: <20260923192450.3008671-1-morbo@google.com> (raw)
In-Reply-To: <20260923041630.2553973-1-morbo@google.com>
The compiler attribute __counted_by_ptr can be used by KASAN and UBSAN
to detect out-of-bounds accesses to pointer fields in structs where a
corresponding element count field is available.
In "struct iio_gts", there are multiple pointer fields associated with
an element count. This patch annotates these pointer fields with
"__counted_by_ptr" to improve runtime safety:
- 'hwgain_table': counted by 'num_hwgain'
- 'itime_table': counted by 'num_itime'
- 'per_time_avail_scale_tables': counted by 'num_itime'
- 'avail_all_scales_table': counted by 'num_avail_all_scales'
- 'avail_time_tables': counted by 'num_avail_time_tables'
To ensure that the count is set correctly before any pointer is
accessed or assigned, we update "iio_init_iio_gts()" to set the counts
prior to assigning the pointers.
Cc: codemender-patching+linux@google.com
Assisted-by: LLM
Signed-off-by: Bill Wendling <morbo@google.com>
Acked-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
v2: Remove reordering of assignments. It's not necessary as an assignment of
the pointer isn't an access that's checked by KASAN.
---
include/linux/iio/iio-gts-helper.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/iio/iio-gts-helper.h b/include/linux/iio/iio-gts-helper.h
index 66f830ab9b49..7e7d3396ff1a 100644
--- a/include/linux/iio/iio-gts-helper.h
+++ b/include/linux/iio/iio-gts-helper.h
@@ -58,14 +58,14 @@ struct iio_itime_sel_mul {
struct iio_gts {
u64 max_scale;
- const struct iio_gain_sel_pair *hwgain_table;
+ const struct iio_gain_sel_pair *hwgain_table __counted_by_ptr(num_hwgain);
int num_hwgain;
- const struct iio_itime_sel_mul *itime_table;
+ const struct iio_itime_sel_mul *itime_table __counted_by_ptr(num_itime);
int num_itime;
- int **per_time_avail_scale_tables;
- int *avail_all_scales_table;
+ int **per_time_avail_scale_tables __counted_by_ptr(num_itime);
+ int *avail_all_scales_table __counted_by_ptr(num_avail_all_scales);
int num_avail_all_scales;
- int *avail_time_tables;
+ int *avail_time_tables __counted_by_ptr(num_avail_time_tables);
int num_avail_time_tables;
};
--
2.56.0.rc1.310.g51773c2048-goog
prev parent reply other threads:[~2026-09-23 19:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 4:16 [PATCH] " Bill Wendling
2026-09-23 4:53 ` Matti Vaittinen
2026-09-23 5:37 ` Gustavo A. R. Silva
2026-09-23 7:26 ` Kees Cook
2026-09-23 8:13 ` Bill Wendling
2026-09-23 19:24 ` Bill Wendling [this message]
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=20260923192450.3008671-1-morbo@google.com \
--to=morbo@google.com \
--cc=andy@kernel.org \
--cc=codemender-patching+linux@google.com \
--cc=dlechner@baylibre.com \
--cc=gustavoars@kernel.org \
--cc=jic23@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.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®