From: Oleg Nesterov <oleg@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Sebastian Mayr <me@sam.st>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, LKML <linux-kernel@vger.kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Dmitry Safonov <dsafonov@virtuozzo.com>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Subject: get_unmapped_area && in_ia32_syscall (Was: [PATCH] uprobes/x86: fix detection of 32-bit user mode)
Date: Tue, 27 Aug 2019 16:00:55 +0200 [thread overview]
Message-ID: <20190827140055.GA6291@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1908232343470.1939@nanos.tec.linutronix.de>
Sorry for delay, vacation.
On 08/24, Thomas Gleixner wrote:
>
> And sadly this was already mentioned here:
>
> 8faaed1b9f50 ("uprobes/x86: Introduce sizeof_long(), cleanup adjust_ret_addr() and arch_uretprobe_hijack_return_addr()")
Yes, and I even posted a similar fix but forgot to send it officially ...
Thanks Sebastian! I am sure it was not easy to debug this problem.
But to remind, there is another problem with in_ia32_syscall() && uprobes.
get_unmapped_area() paths use in_ia32_syscall() and this is wrong in case
when the caller is xol_add_vma(), in this case TS_COMPAT won't be set.
Usually the addr = TASK_SIZE - PAGE_SIZE passed to get_unmapped_area() should
work, mm->get_unmapped_area() won't be even called. But if this addr is already
occupied get_area() can return addr > TASK_SIZE.
Test-case:
#include <sys/mman.h>
void func(void)
{
}
int main(void)
{
// 0xffffd000 == TASK_SIZE - PAGE_SIZE
mmap((void*)0xffffd000, 4096, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1,0);
func();
return 0;
}
$ cc -m32 -Wall -g T.c -o ./t
$ perf probe -x ./t func+1 # +1 to avoid push_emulate_op()
$ perf record -e probe_t:func -aR ./t
perf-record "hangs" because ./t endlessly restarts the probed insn while
get_xol_area() can't succeed.
I verified that the "patch" below fixes the problem, any idea how to fix
it properly?
Oleg.
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1387,6 +1387,8 @@ void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned lon
set_bit(MMF_RECALC_UPROBES, &vma->vm_mm->flags);
}
+#include <asm/mmu_context.h>
+
/* Slot allocation for XOL */
static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
{
@@ -1402,9 +1404,13 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
}
if (!area->vaddr) {
+ if(!is_64bit_mm(mm))
+ current_thread_info()->status |= TS_COMPAT;
/* Try to map as high as possible, this is only a hint. */
area->vaddr = get_unmapped_area(NULL, TASK_SIZE - PAGE_SIZE,
PAGE_SIZE, 0, 0);
+ if(!is_64bit_mm(mm))
+ current_thread_info()->status &= ~TS_COMPAT;;
if (area->vaddr & ~PAGE_MASK) {
ret = area->vaddr;
goto fail;
next prev parent reply other threads:[~2019-08-27 14:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-28 15:26 [PATCH] uprobes/x86: fix detection of 32-bit user mode Sebastian Mayr
2019-08-19 18:40 ` Sebastian Mayr
2019-08-19 18:43 ` Thomas Gleixner
2019-08-23 23:30 ` Thomas Gleixner
2019-08-23 23:44 ` Thomas Gleixner
2019-08-23 23:57 ` Andy Lutomirski
2019-08-24 0:00 ` Thomas Gleixner
2019-08-24 0:03 ` Thomas Gleixner
2019-08-24 0:13 ` Andy Lutomirski
2019-08-24 0:20 ` Thomas Gleixner
2019-08-26 13:48 ` Thomas Gleixner
2019-08-27 14:00 ` Oleg Nesterov [this message]
2019-08-27 17:03 ` get_unmapped_area && in_ia32_syscall (Was: [PATCH] uprobes/x86: fix detection of 32-bit user mode) Dmitry Safonov
2019-08-27 23:40 ` Dmitry Safonov
2019-08-28 11:37 ` Oleg Nesterov
2019-08-26 14:02 ` [tip: x86/urgent] uprobes/x86: Fix detection of 32-bit user mode tip-bot2 for Sebastian Mayr
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=20190827140055.GA6291@redhat.com \
--to=oleg@redhat.com \
--cc=bp@alien8.de \
--cc=dsafonov@virtuozzo.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=me@sam.st \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=x86@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