From: Xiaomeng Zhang <zhangxiaomeng13@huawei.com>
To: <rostedt@goodmis.org>, <mhiramat@kernel.org>,
<dhowells@redhat.com>, <wsa@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-trace-kernel@vger.kernel.org>
Subject: [PATCH] i2c: Fix OOB access in trace_event_raw_event_smbus_write
Date: Thu, 21 Aug 2025 01:23:12 +0000 [thread overview]
Message-ID: <20250821012312.3591166-1-zhangxiaomeng13@huawei.com> (raw)
The smbus_write tracepoint copies __entry->len bytes into a fixed
I2C_SMBUS_BLOCK_MAX + 2 buffer. Oversized lengths (e.g., 46)
exceed the destination and over-read the source buffer, triggering
OOB warning:
memcpy: detected field-spanning write (size 48) of single field
"entry->buf" at include/trace/events/smbus.h:60 (size 34)
Clamp the copy size to I2C_SMBUS_BLOCK_MAX + 2 before memcpy().
This only affects tracing and does not change I2C transfer behavior.
Fixes: 8a325997d95d ("i2c: Add message transfer tracepoints for SMBUS [ver #2]")
Signed-off-by: Xiaomeng Zhang <zhangxiaomeng13@huawei.com>
---
include/trace/events/smbus.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/trace/events/smbus.h b/include/trace/events/smbus.h
index 71a87edfc46d..e306d8b928c3 100644
--- a/include/trace/events/smbus.h
+++ b/include/trace/events/smbus.h
@@ -57,6 +57,8 @@ TRACE_EVENT_CONDITION(smbus_write,
case I2C_SMBUS_I2C_BLOCK_DATA:
__entry->len = data->block[0] + 1;
copy:
+ if (__entry->len > I2C_SMBUS_BLOCK_MAX + 2)
+ __entry->len = I2C_SMBUS_BLOCK_MAX + 2;
memcpy(__entry->buf, data->block, __entry->len);
break;
case I2C_SMBUS_QUICK:
--
2.34.1
next reply other threads:[~2025-08-21 1:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 1:23 Xiaomeng Zhang [this message]
2025-09-02 19:49 ` [PATCH] i2c: Fix OOB access in trace_event_raw_event_smbus_write Steven Rostedt
2025-09-09 9:30 ` 回复: " zhangxiaomeng (A)
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=20250821012312.3591166-1-zhangxiaomeng13@huawei.com \
--to=zhangxiaomeng13@huawei.com \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=wsa@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox