From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=178.238.236.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796335285; b=DCJlUOSILzg9zqyGJ9JeZK3TP25/YhpM6WRq3IJ6ZIrsDkQu2sY0VvOIjujyc69+mUNK EJpoYMI43cY1tZ1grYZzrQ/ZF0FG4CRKJLmsF6/bTXGXH8uo593Pfy5KBE+AxlSi6GwNQ 0WrzPFtEmY2yDkqFHCPYrzui11qL9lSYxeV2QZLJDbhPLrEzq0zIj0IZRr7316RRi8QK/ TqnTZz/06agRRt8iJuUC7jpqKk1S8TLoCK01enRmco9XE/wYledLrkxWIzIMHA9NIACs/ 8zjhx91LotE93z4y4doD9zhWAC9+N7CmJKDIDdcsT6PVrF2ngIuD9jOPcqRDcHY5xoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796335285; h=DMARC-Filter:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=asOZ3Sv2a2uYMl1tBt1Rqz4bC/5gWiPoEzxCSgWIBgE=; b=mgAWJQWdFFAW63ZWvP3t6Zm6rWoUgP+cwbbNKeKhsSkpvKC7+JY7Vy3fFbRRMvOL2x8y lMRDXV9x1G/p5HK1ze4o7kH/iKVQ8G7W1h5vSGxcFPUS/6HhzpCLqggnobr5sIq6Qd0n7 ugrdmCqt3V1wGRsnOoceBOnCCrocikACQWL1vNgF8BUVVK/ZdBzbt20v7r8CO/PY4l49X zBHkzaeq4LTPkUAxBCxKa1AXOdvOuVgWofE5Ku6zXvkMky50aaZ7HuXlVu+gipsWsZXe+ DJHYUs4iyvTy6+ehCdTHMfz8djrMXS70F75My1qpRJVDaInGs1H+HQWEHFltIdseOTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kemnade.info; spf=pass smtp.mailfrom=kemnade.info; dkim=pass header.d=kemnade.info header.i=@kemnade.info header.a=rsa-sha256 header.s=20220719 header.b=ZlzDOtQo; arc=none smtp.remote-ip=178.238.236.174 Received: from mail.andi.de1.cc (mail.andi.de1.cc [178.238.236.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 190D6606A33A; Thu, 3 Dec 2026 22:01:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 190D6606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kemnade.info Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kemnade.info Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kemnade.info header.i=@kemnade.info header.a=rsa-sha256 header.s=20220719 header.b=ZlzDOtQo DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20220719; h=References:In-Reply-To:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description; bh=asOZ3Sv2a2uYMl1tBt1Rqz4bC/5gWiPoEzxCSgWIBgE=; t=1796335284; x=1797544884; b=ZlzDOtQojEb4vXMoWEhZipfkS+OQ0hKLFQ3BAkWkPBeyG/AE4/44+7khpNOa5Q7wk/vPG+CeruH ZoBk9d/HJlFLqd8QyG3EhriWJnVhiBSHtocQGxLEIB/WWW6JwsCYXI2J3/vKzwYVQRcSUE//ErI0Q LnN9BQeta6m6Qahb3CjgZKGrrZjKKps/l19pHzaRJk4bw5avE2lqPhLgFF9vvNpR0PEs6WG9nFxnl 8qzP0L3KcRBu/2o7kHxcUQrz340bzuSyvZeSQ+iwrHreM8rmu7poVWzjGgMaGRcI71bxQmuB/dnLx dTOJY0O+RTvRxKLPcb8EtYUqNhmnhTvC4kSg==; Date: Thu, 3 Dec 2026 23:00:21 +0100 From: Andreas Kemnade To: Lee Jones Cc: Vignesh R , Aaro Koskinen , Kevin Hilman , Roger Quadros , Tony Lindgren , Janusz Krzysztofik , Andi Shyti , Imre Deak , Juha Yrjola , Syed Khasim , Nishant Menon , Wolfram Sang , Shubhrajyoti D , Felipe Balbi , linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 04/10] i2c: omap: Check buf_len before buffer accesses in data transfer helpers Message-ID: <20261203230021.17cbf5a7@kemnade.info> In-Reply-To: <20261203183214.1939736-5-lee@kernel.org> References: <20261203183214.1939736-1-lee@kernel.org> <20261203183214.1939736-5-lee@kernel.org> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.49; aarch64-unknown-linux-gnu) X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 3 Dec 2026 18:31:08 +0000 Lee Jones wrote: > omap_i2c_receive_data() and omap_i2c_transmit_data() dereference > omap->buf without checking omap->buf_len. On controllers with > OMAP_I2C_FLAG_16BIT_DATA_REG, any odd-length message reads or writes > one byte past msg->buf and underflows omap->buf_len; FIFO counts > exceeding omap->buf_len also overflow the message buffer. > The 16bit argument seems valid. But I do not get why FIFO count could exceed buf_len. I would expect the line omap->threshold = clamp(size, (u8) 1, omap->fifo_size); to guard against that. At least that seems to be the idea behind the offending patch, which removes the checks. If you can easily find any clear reasoning, it might be nice to have that in the commit message. But besides of that: Reviewed-by: Andreas Kemnade > Guard all omap->buf accesses and omap->buf_len decrements against a > zero remaining length, matching omap_i2c_omap1_isr(). > Yes, better err on the side of caution here. At least it is not totally obvious that these checks are not needed. > Fixes: dd74548ddece ("i2c: omap: resize fifos before each message") > Closes: https://sashiko.dev/#/bug/linux-288ca65a-55c7-4651-8d27-2629e158106e > Cc: stable@vger.kernel.org > Signed-off-by: Lee Jones > --- > drivers/i2c/busses/i2c-omap.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c > index 6a577db3cb64..4684e0d64cff 100644 > --- a/drivers/i2c/busses/i2c-omap.c > +++ b/drivers/i2c/busses/i2c-omap.c > @@ -1003,14 +1003,17 @@ static void omap_i2c_receive_data(struct omap_i2c_dev *omap, u8 num_bytes, > > while (num_bytes--) { > w = omap_i2c_read_reg(omap, OMAP_I2C_DATA_REG); > - *omap->buf++ = w; > - omap->buf_len--; > + if (omap->buf_len) { > + *omap->buf++ = w; > + omap->buf_len--; > + } > > /* > * Data reg in 2430, omap3 and > * omap4 is 8 bit wide > */ > - if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { > + if ((omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) && > + omap->buf_len) { BTW: Dead code in next, but not in stable, so your fix is of course needed. (of course taking the brush now is not needed) > *omap->buf++ = w >> 8; > omap->buf_len--; > } > @@ -1023,6 +1026,8 @@ static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes, > u16 w; > > while (num_bytes--) { > + if (!omap->buf_len) > + break; > w = *omap->buf++; > omap->buf_len--; > > @@ -1030,7 +1035,8 @@ static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes, > * Data reg in 2430, omap3 and > * omap4 is 8 bit wide > */ > - if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { > + if ((omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) && > + omap->buf_len) { Same here. > w |= *omap->buf++ << 8; > omap->buf_len--; > }