From: David Hildenbrand <david@redhat.com>
To: Muchun Song <songmuchun@bytedance.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
cheloha@linux.vnet.ibm.com, Michal Hocko <mhocko@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Nathan Lynch <nathanl@linux.ibm.com>,
LKML <linux-kernel@vger.kernel.org>,
linux- stable <stable@vger.kernel.org>
Subject: Re: [PATCH] mm: memory_hotplug: fix memory error handling
Date: Mon, 30 May 2022 09:10:27 +0200 [thread overview]
Message-ID: <1bbbe572-5aa3-18d1-35f0-3e089942b4cf@redhat.com> (raw)
In-Reply-To: <CAMZfGtUMfNjOGJ3j4tgha6SxFymNGDo3CW5NO73ZsMby42BPjg@mail.gmail.com>
On 30.05.22 09:08, Muchun Song wrote:
> On Mon, May 30, 2022 at 2:56 PM David Hildenbrand <david@redhat.com> wrote:
>>
>> On 30.05.22 07:33, Muchun Song wrote:
>>> The device_unregister() is supposed to be used to unregister devices if
>>> device_register() has succeed. And device_unregister() will put device.
>>> The caller should not do it again, otherwise, the first call of
>>> put_device() will drop the last reference count, then the next call
>>> of device_unregister() will UAF on device.
>>>
>>> Fixes: 4fb6eabf1037 ("drivers/base/memory.c: cache memory blocks in xarray to accelerate lookup")
>>> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
>>> Cc: <stable@vger.kernel.org>
>>> ---
>>> drivers/base/memory.c | 5 ++---
>>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
>>> index 7222ff9b5e05..084d67fd55cc 100644
>>> --- a/drivers/base/memory.c
>>> +++ b/drivers/base/memory.c
>>> @@ -636,10 +636,9 @@ static int __add_memory_block(struct memory_block *memory)
>>> }
>>> ret = xa_err(xa_store(&memory_blocks, memory->dev.id, memory,
>>> GFP_KERNEL));
>>> - if (ret) {
>>> - put_device(&memory->dev);
>>> + if (ret)
>>> device_unregister(&memory->dev);
>>> - }
>>> +
>>> return ret;
>>> }
>>>
>>
>> See
>>
>> https://lkml.kernel.org/r/d44c63d78affe844f020dc02ad6af29abc448fc4.1650611702.git.christophe.jaillet@wanadoo.fr
>>
>
> I see. Good job by Christophe. Thanks David.
>
I'm curious how both of you found that issue? Just by staring at that
code? :)
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2022-05-30 7:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 5:33 Muchun Song
2022-05-30 6:55 ` David Hildenbrand
2022-05-30 7:08 ` Muchun Song
2022-05-30 7:10 ` David Hildenbrand [this message]
2022-05-30 7:16 ` Muchun Song
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=1bbbe572-5aa3-18d1-35f0-3e089942b4cf@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=cheloha@linux.vnet.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=nathanl@linux.ibm.com \
--cc=rafael@kernel.org \
--cc=songmuchun@bytedance.com \
--cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®