[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <yt9d8qw99j6y.fsf@linux.ibm.com>
Date: Tue, 03 Sep 2024 11:32:05 +0200
From: Sven Schnelle <svens@...ux.ibm.com>
To: Oleg Nesterov <oleg@...hat.com>
Cc: Michael Ellerman <mpe@...erman.id.au>,
Masami Hiramatsu
<mhiramat@...nel.org>,
Peter Zijlstra <peterz@...radead.org>, Ingo
Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa
<jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
Adrian Hunter
<adrian.hunter@...el.com>,
"Liang, Kan" <kan.liang@...ux.intel.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org
Subject: Re: [PATCH] uprobes: use vm_special_mapping close() functionality
Oleg Nesterov <oleg@...hat.com> writes:
> On 09/03, Sven Schnelle wrote:
>>
>> [ 44.505448] ================================================================== 20:37:27 [3421/145075]
>> [ 44.505455] BUG: KASAN: slab-use-after-free in special_mapping_close+0x9c/0xc8
>> [ 44.505471] Read of size 8 at addr 00000000868dac48 by task sh/1384
>> [ 44.505479]
>> [ 44.505486] CPU: 51 UID: 0 PID: 1384 Comm: sh Not tainted 6.11.0-rc6-next-20240902-dirty #1496
>> [ 44.505503] Hardware name: IBM 3931 A01 704 (z/VM 7.3.0)
>> [ 44.505508] Call Trace:
>> [ 44.505511] [<000b0324d2f78080>] dump_stack_lvl+0xd0/0x108
>> [ 44.505521] [<000b0324d2f5435c>] print_address_description.constprop.0+0x34/0x2e0
>> [ 44.505529] [<000b0324d2f5464c>] print_report+0x44/0x138
>> [ 44.505536] [<000b0324d1383192>] kasan_report+0xc2/0x140
>> [ 44.505543] [<000b0324d2f52904>] special_mapping_close+0x9c/0xc8
> ^^^^^^^^^^^^^^^^^^^^^
> Caused by
>
> [PATCH v2 1/4] mm: Add optional close() to struct vm_special_mapping
> https://lore.kernel.org/all/20240812082605.743814-1-mpe@ellerman.id.au/
>
> ?
>
>> +static void uprobe_clear_state(const struct vm_special_mapping *sm, struct vm_area_struct *vma)
>> +{
>> + struct xol_area *area = container_of(vma->vm_private_data, struct xol_area, xol_mapping);
>> +
>> + mutex_lock(&delayed_uprobe_lock);
>> + delayed_uprobe_remove(NULL, vma->vm_mm);
>> + mutex_unlock(&delayed_uprobe_lock);
>> +
>> + if (!area)
>> + return;
>> +
>> + put_page(area->pages[0]);
>> + kfree(area->bitmap);
>> + kfree(area);
>> +}
>> +
>> static struct xol_area *__create_xol_area(unsigned long vaddr)
>> {
>> struct mm_struct *mm = current->mm;
>> @@ -1481,6 +1500,7 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
>>
>> area->xol_mapping.name = "[uprobes]";
>> area->xol_mapping.fault = NULL;
>> + area->xol_mapping.close = uprobe_clear_state;
>
> LGTM.
>
> but with or without this fix __create_xol_area() also needs
>
> area->xol_mapping.mremap = NULL;
>
> ?
I think the code should just use kzalloc() instead of kmalloc() so all
members are cleared. I noticed that when looking into the issue because
the new close member of xol_mapping wasn't initialized. My plan was to
send that change as a separate patch - because it's not related to this
issue.
Powered by blists - more mailing lists