From: David Laight <david.laight.linux@gmail.com>
To: Christian Marangi <ansuelsmth@gmail.com>
Cc: Stefan Roese <sr@denx.de>, Andi Shyti <andi.shyti@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Wolfram Sang <wsa@kernel.org>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH RESEND] i2c: mt7621: fix copying uninitialized kernel stack with reduced page_len
Date: Tue, 27 Oct 2026 13:54:43 +0000 [thread overview]
Message-ID: <20261027135443.575faff1@pumpkin> (raw)
In-Reply-To: <20261022193853.670625-1-ansuelsmth@gmail.com>
On Thu, 22 Oct 2026 21:38:51 +0200
Christian Marangi <ansuelsmth@gmail.com> wrote:
> When a page_len is less than 5 bytes in mtk_i2c_xfer, uninitialized kernel
> stack data is copied and written to REG_SM0D1_REG. Equally on the read
> part, an unnecessary read is done.
>
> Guard these extra copy/write and read for the page_len to fix leaking
> uninitialized stack memory.
>
> Fixes: d04913ec5f89 ("i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C driver")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
> drivers/i2c/busses/i2c-mt7621.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
> index 0a288c998419..9ea5e3f9a763 100644
> --- a/drivers/i2c/busses/i2c-mt7621.c
> +++ b/drivers/i2c/busses/i2c-mt7621.c
> @@ -144,7 +144,6 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> u16 addr;
> int i, j, ret, len, page_len;
> u32 cmd;
> - u32 data[2];
>
> i2c = i2c_get_adapdata(adap);
>
> @@ -186,6 +185,8 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
>
> /* transfer data */
> for (len = pmsg->len, j = 0; len > 0; len -= 8, j += 8) {
> + u32 data[2] = { };
> +
> page_len = (len >= 8) ? 8 : len;
>
> if (pmsg->flags & I2C_M_RD) {
> @@ -194,7 +195,8 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> } else {
> memcpy(data, &pmsg->buf[j], page_len);
> iowrite32(data[0], i2c->base + REG_SM0D0_REG);
> - iowrite32(data[1], i2c->base + REG_SM0D1_REG);
> + if (page_len > 4)
> + iowrite32(data[1], i2c->base + REG_SM0D1_REG);
1) Why is this using memcpy() rather then just get_unaligned_u32().
(Yes, short transfers get tricky...)
2) Have you checked whether the hardware requires both registers be
read/written for correct operation.
David
> cmd = SM0CTL1_WRITE;
> }
>
> @@ -204,7 +206,8 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
>
> if (pmsg->flags & I2C_M_RD) {
> data[0] = ioread32(i2c->base + REG_SM0D0_REG);
> - data[1] = ioread32(i2c->base + REG_SM0D1_REG);
> + if (page_len > 4)
> + data[1] = ioread32(i2c->base + REG_SM0D1_REG);
> memcpy(&pmsg->buf[j], data, page_len);
> } else {
> if (!(pmsg->flags & I2C_M_IGNORE_NAK)) {
prev parent reply other threads:[~2026-10-27 13:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 19:38 Christian Marangi
2026-10-23 16:19 ` Andi Shyti
2026-10-26 22:59 ` Andi Shyti
2026-10-26 23:03 ` Christian Marangi (Ansuel)
2026-10-27 13:54 ` David Laight [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=20261027135443.575faff1@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=andi.shyti@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=ansuelsmth@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=sr@denx.de \
--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
all inboxes | Powered by JetHome®