Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5592368ybl; Tue, 27 Aug 2019 07:02:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/5q2vAeW5E/mcb98O1v8SToE54vnQnyXClkJGxTuAIzczDTATCmYKqWhYmUpQgrRffC1p X-Received: by 2002:a63:2b8e:: with SMTP id r136mr21345973pgr.216.1566914535654; Tue, 27 Aug 2019 07:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566914535; cv=none; d=google.com; s=arc-20160816; b=HQJqXlauZCPRJyh01V9EOnOsUhmYK3O2AU+AyLxTciMi+BMk89lPKZcJxbXnDeoED1 Fs6wR8Sa6F4L1mqwq1Xj1UQXJvEjdBGsA1jRdq5RYT1Rn/5+X827tkYnXCUhQWq7btHi i4eWhVXKvfNkcLZ/bKUPqB/+en3zEqeuiAUTlfFcSF81+529AKwkbjRflLNQygm3tNtH X50jhbJ8VsKtn9mvxp6B9vaSoHCSYkcYQchlSpvQWHUBiGk91LwIbMb5pIsZ9/ydfXR9 GNNCyqW6ODDWHwkQx9tJoImPVpwA5+5TaFKdLQg3VE+weGWLjrlNEkd2NnGY9b2FVAIB dmxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=idlf6zz/pzuNpGs6zVa4YSMCOy3amTTchc17jimZ07Q=; b=aENB3RmYV5Hm4YPIvxutgP26UgvW6xwXLRSwwtehGQnuhIOYIizatuepHVR2TYz/VN vYCXjr1TYNioP4kqYYV7QssXfd+5NcRxt1EnF6LTfxQv/Fngg00iM+NmIKFtNtMnemkb DOjI1b2Flv1EBKIdg73XPtqM4ut6iChCqo0fQHjchzhfkeCbzOv5HKj/mMTclO6KW1d6 1ocW2YlYF4gHJmd7VHcUMVxdyQA+kNSvC7eFCtwt//2bIUs+5BqUuBTwb3kmpo+CCc72 khO54MwTyVorWibJcJ8UJlzb2myU0SL8YuQCGrHOjwAPL/YDugf0eq7U7j5grRA1ek7b 1ZWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si13650359pff.247.2019.08.27.07.01.59; Tue, 27 Aug 2019 07:02:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729128AbfH0OBA (ORCPT + 99 others); Tue, 27 Aug 2019 10:01:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39706 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfH0OA7 (ORCPT ); Tue, 27 Aug 2019 10:00:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85F9A81F19; Tue, 27 Aug 2019 14:00:59 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.63]) by smtp.corp.redhat.com (Postfix) with SMTP id E794F60BF7; Tue, 27 Aug 2019 14:00:56 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 27 Aug 2019 16:00:58 +0200 (CEST) Date: Tue, 27 Aug 2019 16:00:55 +0200 From: Oleg Nesterov To: Thomas Gleixner Cc: Sebastian Mayr , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, LKML , Masami Hiramatsu , Andy Lutomirski , Peter Zijlstra , Dmitry Safonov , Srikar Dronamraju Subject: get_unmapped_area && in_ia32_syscall (Was: [PATCH] uprobes/x86: fix detection of 32-bit user mode) Message-ID: <20190827140055.GA6291@redhat.com> References: <20190728152617.7308-1-me@sam.st> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 27 Aug 2019 14:00:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 + /* 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;