[PATCH OLK-6.6] i2c: Fix stack-out-of-bounds in trace_event_raw_event_smbus_write

maillist inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICVPHP Reference: https://lore.kernel.org/all/20250821012312.3591166-1-zhangxiaomeng13@huawei.... -------------------------------- 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

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17948 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/JYV... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/17948 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/JYV...
participants (2)
-
patchwork bot
-
Xiaomeng Zhang