From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
To: Dan Carpenter <dan.carpenter@linaro.org>,
Romain Gantois <romain.gantois@bootlin.com>
Cc: Luca Ceresoli <luca.ceresoli@bootlin.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Andi Shyti <andi.shyti@kernel.org>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH next] i2c: Fix end of loop test in i2c_atr_find_mapping_by_addr()
Date: Thu, 24 Apr 2025 09:32:22 +0300 [thread overview]
Message-ID: <9cd0c3cc-9f3c-4a3e-9080-c832def8f317@ideasonboard.com> (raw)
In-Reply-To: <a22d74b9-06b1-4a4b-9c06-4b0ff7f9b6c2@stanley.mountain>
Hi,
On 23/04/2025 20:29, Dan Carpenter wrote:
> On Wed, Apr 23, 2025 at 05:25:44PM +0200, Romain Gantois wrote:
>> Hello Dan,
>>
>> On Wednesday, 23 April 2025 10:21:18 CEST Dan Carpenter wrote:
>>> When the list_for_each_entry_reverse() exits without hitting a break
>>> then the list cursor points to invalid memory. So this check for
>>> if (c2a->fixed) is checking bogus memory. Fix it by using a "found"
>>> variable to track if we found what we were looking for or not.
>>
>> IIUC the for loop ending condition in list_for_each_entry_reverse() is
>> "!list_entry_is_head(pos, head, member);", so even if the loop runs to
>> completion, the pointer should still be valid right?
>>
>
> head is &chan->alias_pairs. pos is an offset off the head. In this
> case, the offset is zero. So it's &chan->alias_pairs minus zero.
>
> So we exit the list with c2a = (void *)&chan->alias_pairs.
>
> If you look how struct i2c_atr_chan is declareted the next struct member
> after alias_pairs is:
>
> struct i2c_atr_alias_pool *alias_pool;
>
> So if (c2a->fixed) is poking around in the alias_pool pointer. It's not
> out of bounds but it's not valid either.
Maybe it's just me, but I had hard time following that explanation. So
here's mine:
The list head (i2c_atr_chan.alias_pairs) is not a full entry, it's just
a struct list_head. When the for loop runs to completion, c2a doesn't
point to a struct i2c_atr_alias_pair, so you can't access c2a->fixed.
For the patch:
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Tomi
next prev parent reply other threads:[~2025-04-24 6:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 8:21 [PATCH next] i2c: Fix end of loop test in i2c_atr_find_mapping_by_addr() Dan Carpenter
2025-04-23 15:25 ` Romain Gantois
2025-04-23 17:29 ` Dan Carpenter
2025-04-24 6:32 ` Tomi Valkeinen [this message]
2025-04-24 7:10 ` Romain Gantois
2025-04-30 12:25 ` Luca Ceresoli
2025-05-02 14:40 ` Wolfram Sang
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=9cd0c3cc-9f3c-4a3e-9080-c832def8f317@ideasonboard.com \
--to=tomi.valkeinen@ideasonboard.com \
--cc=andi.shyti@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=romain.gantois@bootlin.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