All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
Cc: "Dan Carpenter" <error27@gmail.com>,
	 "Harshit Mogalapalli" <harshit.m.mogalapalli@oracle.com>,
	 "Richard Weinberger" <richard@nod.at>,
	 "Vignesh Raghavendra" <vigneshr@ti.com>,
	 "Amit Kumar Mahapatra" <amit.kumar-mahapatra@amd.com>,
	<linux-mtd@lists.infradead.org>,  <linux-kernel@vger.kernel.org>,
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH] mtd: virt_concat: fix use-after-free in mtd_virt_concat_destroy_joins()
Date: Mon, 22 Jun 2026 09:32:43 +0200	[thread overview]
Message-ID: <874iiv3u90.fsf@bootlin.com> (raw)
In-Reply-To: <DJARC89F2VJR.1EDEQ27GSDAK6@bootlin.com> (Luca Ceresoli's message of "Tue, 16 Jun 2026 22:31:28 +0200")

On 16/06/2026 at 22:31:28 +02, "Luca Ceresoli" <luca.ceresoli@bootlin.com> wrote:

> On Tue Jun 16, 2026 at 12:13 PM CEST, Dan Carpenter wrote:
>> On Tue, Jun 16, 2026 at 11:51:53AM +0200, Luca Ceresoli wrote:

Yes, container_of() for issue 1 seems to be a better approach.

>>> Issue 2: in mtd_virt_concat_destroy_joins():
>>>
>>> 	list_for_each_entry_safe(item, tmp, &concat_node_list, head) {
>>> 		mtd = &item->concat->mtd; [0]
>>> 		if (item->concat) { [1]
>>>
>>> At line [0] we dereference item->concat, but at line [1] we apparently
>>> handle the case where item->concat can be NULL. Either [1] is always true
>>> and we can remove the if(), or [1] can be false, so [0] is a bug and should
>>> probably be moved to inside the if().
>>
>> That's not a dereference on line 0, it's pointer math.  So the code
>> works.  But a lot of people find the distinction confusing.
>
> Ah, indeed, you are right on both aspects: it's just pointer math (not a
> bug) + it is confusing code.
>
> So moving [0] inside the if() would be a readability improvement IMO, but
> definitely not a bugfix.

Yes!

Thanks,
Miquèl

WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
Cc: "Dan Carpenter" <error27@gmail.com>,
	 "Harshit Mogalapalli" <harshit.m.mogalapalli@oracle.com>,
	 "Richard Weinberger" <richard@nod.at>,
	 "Vignesh Raghavendra" <vigneshr@ti.com>,
	 "Amit Kumar Mahapatra" <amit.kumar-mahapatra@amd.com>,
	<linux-mtd@lists.infradead.org>,  <linux-kernel@vger.kernel.org>,
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH] mtd: virt_concat: fix use-after-free in mtd_virt_concat_destroy_joins()
Date: Mon, 22 Jun 2026 09:32:43 +0200	[thread overview]
Message-ID: <874iiv3u90.fsf@bootlin.com> (raw)
In-Reply-To: <DJARC89F2VJR.1EDEQ27GSDAK6@bootlin.com> (Luca Ceresoli's message of "Tue, 16 Jun 2026 22:31:28 +0200")

On 16/06/2026 at 22:31:28 +02, "Luca Ceresoli" <luca.ceresoli@bootlin.com> wrote:

> On Tue Jun 16, 2026 at 12:13 PM CEST, Dan Carpenter wrote:
>> On Tue, Jun 16, 2026 at 11:51:53AM +0200, Luca Ceresoli wrote:

Yes, container_of() for issue 1 seems to be a better approach.

>>> Issue 2: in mtd_virt_concat_destroy_joins():
>>>
>>> 	list_for_each_entry_safe(item, tmp, &concat_node_list, head) {
>>> 		mtd = &item->concat->mtd; [0]
>>> 		if (item->concat) { [1]
>>>
>>> At line [0] we dereference item->concat, but at line [1] we apparently
>>> handle the case where item->concat can be NULL. Either [1] is always true
>>> and we can remove the if(), or [1] can be false, so [0] is a bug and should
>>> probably be moved to inside the if().
>>
>> That's not a dereference on line 0, it's pointer math.  So the code
>> works.  But a lot of people find the distinction confusing.
>
> Ah, indeed, you are right on both aspects: it's just pointer math (not a
> bug) + it is confusing code.
>
> So moving [0] inside the if() would be a readability improvement IMO, but
> definitely not a bugfix.

Yes!

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-06-22  7:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-14  8:10 [PATCH] mtd: virt_concat: fix use-after-free in mtd_virt_concat_destroy_joins() Harshit Mogalapalli
2026-06-14  8:10 ` Harshit Mogalapalli
2026-06-16  9:51 ` Luca Ceresoli
2026-06-16  9:51   ` Luca Ceresoli
2026-06-16 10:13   ` Dan Carpenter
2026-06-16 10:13     ` Dan Carpenter
2026-06-16 20:31     ` Luca Ceresoli
2026-06-16 20:31       ` Luca Ceresoli
2026-06-22  7:32       ` Miquel Raynal [this message]
2026-06-22  7:32         ` Miquel Raynal
2026-06-16 12:25 ` Harshit Mogalapalli
2026-06-16 12:25   ` Harshit Mogalapalli

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=874iiv3u90.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=amit.kumar-mahapatra@amd.com \
    --cc=error27@gmail.com \
    --cc=harshit.m.mogalapalli@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.