From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Russell Currey <ruscur@russell.cc>,
linuxppc-dev@lists.ozlabs.org,
Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: Re: [PATCH] powerpc/eeh: Avoid use after free in eeh_handle_special_event()
Date: Mon, 6 Mar 2017 10:22:46 +1100 [thread overview]
Message-ID: <20170305232246.GA14744@gwshan> (raw)
In-Reply-To: <2ac7b7d0-c04f-1c33-4661-d2e4f9a0e054@ozlabs.ru>
On Fri, Mar 03, 2017 at 04:59:11PM +1100, Alexey Kardashevskiy wrote:
>On 03/03/17 15:47, Russell Currey wrote:
>> eeh_handle_special_event() is called when an EEH event is detected but
>> can't be narrowed down to a specific PE. This function looks through
>> every PE to find one in an erroneous state, then calls the regular event
>> handler eeh_handle_normal_event() once it knows which PE has an error.
>>
>> However, if eeh_handle_normal_event() found that the PE cannot possibly
>> be recovered, it will remove the PE and associated devices. This leads
>> to a use after free in eeh_handle_special_event() as it attempts to clear
>> the "recovering" state on the PE after eeh_handle_normal_event() returns.
>>
>> Thus, make sure the PE is valid when attempting to clear state in
>> eeh_handle_special_event().
>>
>> Cc: <stable@vger.kernel.org> #3.10+
>> Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> Signed-off-by: Russell Currey <ruscur@russell.cc>
>> ---
>> arch/powerpc/kernel/eeh_driver.c | 13 +++++++++++++
>> 1 file changed, 13 insertions(+)
>>
>> diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
>> index b94887165a10..492397298a2a 100644
>> --- a/arch/powerpc/kernel/eeh_driver.c
>> +++ b/arch/powerpc/kernel/eeh_driver.c
>> @@ -983,6 +983,19 @@ static void eeh_handle_special_event(void)
>> if (rc == EEH_NEXT_ERR_FROZEN_PE ||
>> rc == EEH_NEXT_ERR_FENCED_PHB) {
>> eeh_handle_normal_event(pe);
>> +
>> + /*
>> + * eeh_handle_normal_event() can free the PE if it
>> + * determines that the PE cannot possibly be recovered.
>> + * Make sure the PE still exists before changing its
>> + * state.
>> + */
>> + if (!pe || (pe->type & EEH_PE_INVALID)
>> + || (pe->state & EEH_PE_REMOVED)) {
>
>
>The bug is that pe becomes stale after eeh_handle_normal_event() returned
>and dereferencing it afterwards is broken.
>
Correct, it won't cause a kernel crash as @pe is deferencing linear mapped
area whose address is always valid. I think the proper fix would be to use
eeh_handle_normal_event() to indicate the @pe has been released and don't
access it any more.
>
>
>> + pr_warn("EEH: not clearing state on bad PE\n");
The message like this isn't meaningful, no need to have it. The messages that
have prefix "EEH:" is informative messages. We definitely needn't this here.
However, the message might be not needed in next revision.
>> + continue;
>> + }
>> +
>> eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
>> } else {
>> pci_lock_rescan_remove();
>>
Thanks,
Gavin
next prev parent reply other threads:[~2017-03-05 23:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 4:47 [PATCH] powerpc/eeh: Avoid use after free in eeh_handle_special_event() Russell Currey
2017-03-03 5:55 ` Gavin Shan
2017-03-03 6:05 ` Alexey Kardashevskiy
2017-03-03 5:59 ` Alexey Kardashevskiy
2017-03-05 23:22 ` Gavin Shan [this message]
2017-03-06 1:54 ` Alexey Kardashevskiy
2017-04-07 3:28 ` Alexey Kardashevskiy
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=20170305232246.GA14744@gwshan \
--to=gwshan@linux.vnet.ibm.com \
--cc=aik@ozlabs.ru \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=ruscur@russell.cc \
/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;
as well as URLs for NNTP newsgroup(s).