public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Abhinav Ananthu <abhinav.ogl@gmail.com>
To: wsa+renesas@sang-engineering.com
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+0a36c1fec090c67a9885@syzkaller.appspotmail.com,
	abhinav.ogl@gmail.com
Subject: [PATCH] i2c: core: Fix uninit-value in i2c_smbus_xfer_emulated
Date: Thu, 29 May 2025 23:45:35 +0530	[thread overview]
Message-ID: <20250529181535.15220-1-abhinav.ogl@gmail.com> (raw)

BUG: KMSAN: uninit-value in i2c_smbus_xfer_emulated drivers/i2c/i2c-core-smbus.c:481 [inline]
BUG: KMSAN: uninit-value in __i2c_smbus_xfer+0x23e7/0x2f60

KMSAN reported an uninitialized value access in i2c_smbus_xfer_emulated at
drivers/i2c/i2c-core-smbus.c:481, triggered during an SMBus transfer via
i2cdev_ioctl_smbus. The issue occurs because the local buffers msgbuf0 and
msgbuf1 are not initialized before use, leading to potential undefined
behavior when their contents are accessed.

Initialize msgbuf0 and msgbuf1 with zeros using memset to ensure all buffer
contents are defined before they are used in the SMBus transfer. This
prevents the uninitialized value access reported by KMSAN.

Reported-by: syzbot+0a36c1fec090c67a9885@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0a36c1fec090c67a9885
Fixes: 02ddfb981de8 ("KMSAN : Fix uninit-value in i2c_smbus_xfer_emulated")
Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com>
---
 drivers/i2c/i2c-core-smbus.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index e73afbefe222..a3ee30b72f75 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -332,6 +332,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
 	 */
 	unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
 	unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
+	memset(msgbuf0, 0, sizeof(msgbuf0));
+	memset(msgbuf1, 0, sizeof(msgbuf1));
 	int nmsgs = read_write == I2C_SMBUS_READ ? 2 : 1;
 	u8 partial_pec = 0;
 	int status;
-- 
2.34.1


             reply	other threads:[~2025-05-29 18:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-29 18:15 Abhinav Ananthu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-06-09  5:35 [PATCH] i2c: core: Fix uninit-value in i2c_smbus_xfer_emulated Abhinav Ananthu

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=20250529181535.15220-1-abhinav.ogl@gmail.com \
    --to=abhinav.ogl@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+0a36c1fec090c67a9885@syzkaller.appspotmail.com \
    --cc=wsa+renesas@sang-engineering.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