From: "Ma, Hua" <hua.ma@intel.com>
To: Michael Brown <mcb30@ipxe.org>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Wang, Jian J" <jian.j.wang@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
"Bi, Dandan" <dandan.bi@intel.com>, "Ni, Ray" <ray.ni@intel.com>
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/Core/Dxe: Acquire a lock when iterating gHandleList
Date: Mon, 11 Oct 2021 14:23:34 +0000 [thread overview]
Message-ID: <SJ0PR11MB4974731CEDD350C75078B34591B59@SJ0PR11MB4974.namprd11.prod.outlook.com> (raw)
In-Reply-To: <f7575ba1-c108-e5da-db3d-7229af52526a@ipxe.org>
> -----Original Message-----
> From: Michael Brown <mcb30@ipxe.org>
> Sent: Monday, October 11, 2021 7:28 PM
> To: devel@edk2.groups.io; Ma, Hua <hua.ma@intel.com>
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Bi, Dandan <dandan.bi@intel.com>; Ni, Ray
> <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/Core/Dxe: Acquire a lock
> when iterating gHandleList
>
> On 11/10/2021 11:45, Ma, Hua wrote:
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3680
> >
> > This patch fixes the following issue:
> >
> > The global variable gHandleList is a linked list.
> > This list is locked when a entry is added or removed from the list,
> > but there is no lock when iterating this list in function
> > CoreValidateHandle().
> > It can lead to "Handle.c (76): CR has Bad Signature" assertion if the
> > iterated entry in the list is just removed by other task during iterating.
> > Locking the list when iterating can fix this issue.
>
> At a first glance, it looks as though if the caller does not already
> hold the lock, then the result from CoreValidateHandle() may be invalid
> by the time that control returns to the caller.
>
> Under what circumstances is it valid to call CoreValidateHandle() when
> the caller does not _already_ hold the lock (i.e. IsLocked==FALSE)?
>
> Thanks,
>
> Michael
Hi Michael,
Thanks for the review,
In current CoreValidateHandle implementation:
for (Link = gHandleList.BackLink; Link != &gHandleList; Link = Link->BackLink) {
Handle = CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);
if (Handle == (IHANDLE *) UserHandle) {
return EFI_SUCCESS;
}
}
Let's say, if the list have 4 entries, (A->B->C->D), and the caller is trying to validate if entry C is valid,
When caller task just set local variable Link to B, and before it calls CR() macro to validate the signature,
At this point, if other task just deletes other entry, entry B, and reset B's signature.
Then when back to caller task, There is a signature mismatch assertion for B.
But the result should be still valid for C if call CoreValidateHandle() again.
The patch is trying to fix this kind of problem.
I feel one valid kind of calling CoreValidateHandle() without holding the lock is:
when the handle is passed in as parameter, and do a parameter checking,
and later, if need, validated the handle again when use the handle.
for example in current code, in AddSortedDriverBindingProtocol, CoreConnectController,
This patch do not change where to add a handle validation.
Thank you,
Ma Hua
next prev parent reply other threads:[~2021-10-11 14:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-11 10:45 [PATCH] MdeModulePkg/Core/Dxe: Acquire a lock when iterating gHandleList Ma, Hua
2021-10-11 11:28 ` [edk2-devel] " Michael Brown
2021-10-11 14:23 ` Ma, Hua [this message]
2021-10-12 4:13 ` Dandan Bi
2021-10-12 8:37 ` Ma, Hua
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-list 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=SJ0PR11MB4974731CEDD350C75078B34591B59@SJ0PR11MB4974.namprd11.prod.outlook.com \
--to=devel@edk2.groups.io \
/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