All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakob Koschel <jakobkoschel@gmail.com>
To: Li Fei1 <fei1.li@intel.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Brian Johannesmeyer <bjohannesmeyer@gmail.com>,
	Cristiano Giuffrida <c.giuffrida@vu.nl>,
	h.j.bos@vu.nl
Subject: Re: [PATCH] virt: acrn: fix invalid check past list iterator
Date: Thu, 31 Mar 2022 13:20:50 +0200	[thread overview]
Message-ID: <6E68C33F-9CBB-418C-A11D-2AD863C0B19A@gmail.com> (raw)
In-Reply-To: <20220330075742.GA22544@louislifei-OptiPlex-7050>


> On 30. Mar 2022, at 09:57, Li Fei1 <fei1.li@intel.com> wrote:
> 
> On Sat, Mar 19, 2022 at 09:38:19PM +0100, Jakob Koschel wrote:
>> The condition retry == 0 is theoretically possible even if 'client'
>> does not point to a valid element because no break was hit.
>> 
>> To only execute the dev_warn if actually a break within the loop was
>> hit, a separate variable is used that is only set if it is ensured to
>> point to a valid client struct.
>> 
> Hi Koschel
> 
> Thanks for you to help us to try to improve the code. Maybe you don't get the point.
> The dev_warn should only been called when has_pending = true && retry == 0

Maybe I don't understand but looking isolated at this function I could see a way to call
the dev_warn() with has_pending = false && retry == 0.

> 		list_for_each_entry(client, &vm->ioreq_clients, list) {
> 			has_pending = has_pending_request(client);
> 			if (has_pending)
> 		}
> 		spin_unlock_bh(&vm->ioreq_clients_lock);

imagine has_pending == false && retry == 1 here, then client will not hold a valid list entry.

> 
> 		if (has_pending)
> 			schedule_timeout_interruptible(HZ / 100);
> 	} while (has_pending && --retry > 0);

since has_pending && --retry > 0 is no longer true the loop stops.

> 	if (retry == 0)
> 		dev_warn(acrn_dev.this_device,
> 			 "%s cannot flush pending request!\n", client->name);
client->name is accessed since retry == 0 now, but client is not a valid struct ending up
in a type confusion.

> 
> If retry > 0 and has_pending is true,  we would call schedule_timeout_interruptible
> to schedule out to wait all the pending I/O requests would been completed.
> 
> Thanks.

Again, I'm not sure if this is realistically possible. I'm trying to remove
any use of the list iterator after the loop to make such potentially issues detectable
at compile time instead of relying on certain (difficult to maintain) conditions to be met
to avoid the type confusion.

Thanks,
Jakob


  reply	other threads:[~2022-03-31 11:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-19 20:38 [PATCH] virt: acrn: fix invalid check past list iterator Jakob Koschel
2022-03-30  7:57 ` Li Fei1
2022-03-31 11:20   ` Jakob Koschel [this message]
2022-04-01  1:15     ` Li Fei1
2022-04-01  3:22       ` Jakob Koschel
2022-04-01  3:57         ` Li Fei1
2022-04-01  7:16           ` Jakob Koschel
2022-04-01  7:57             ` Li Fei1
2022-04-01  8:50               ` Jakob Koschel
2022-04-01  9:05                 ` Li Fei1
2022-04-01  9:08                   ` Jakob Koschel
2022-04-01  9:12                     ` Li Fei1
2022-04-01  9:24                       ` Jakob Koschel

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=6E68C33F-9CBB-418C-A11D-2AD863C0B19A@gmail.com \
    --to=jakobkoschel@gmail.com \
    --cc=bjohannesmeyer@gmail.com \
    --cc=c.giuffrida@vu.nl \
    --cc=fei1.li@intel.com \
    --cc=h.j.bos@vu.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rppt@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 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.