Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4432053ybl; Mon, 26 Aug 2019 10:19:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyeCq7pVy3/qbIjn2NLtS7HC6CFzaMMEfzdwToZGIucpbcNpQVkiiAINVQGOHZAGiv8j2Bv X-Received: by 2002:a17:902:fe06:: with SMTP id g6mr20115437plj.265.1566839971276; Mon, 26 Aug 2019 10:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566839971; cv=none; d=google.com; s=arc-20160816; b=UYVFGtcFHm3qg7o9ntOmMWPuFLw8P4YCt7Z5PbpBoIpTHc2sPfqYi9JxozJbBtEXOo UvhP+Hv65i1STbrYZ67XLLAMJ0/EIyjOwV/ByG8yMdMI9UtsWmQjxrxSZDjI8BiPjvx9 oUe8jX2WOMaXNiemYJkAh4t61kBgiOv9TRBakpy8Przlz1ya6xuM5XHdwAJoBWZUs4Lt MxLnPXDEBCLoHlp4RJPSfrSsAhguXyNMsbskb2Jb61/YxnzSgon4yPXN+XOwkI3TF7Ec DNzTmZk7dU8TdSxvP+JQ4oD3bZS8J2geETT3ucRFs5kSMg6MEqbUuYUuIhneDMshKBDc Kegg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:robot-unsubscribe:robot-id:message-id :mime-version:references:in-reply-to:cc:subject:to:reply-to:from :date; bh=07FrqP6aT6OZ1wwX71AdNHJELXqzig+wnlHXxtsI1Hw=; b=kTYb35UZIADvtGzjsXV5TDjROQJjWOCzK6+8+lEcxI6xhD0HGIiicCqcJXIVsT5p/d xg8DTQXEMLYhFr9k+1PdxRtZHkq3D4N8a+u9hd4LxdgcgGBDQkv5EQVXw8wJiZ6J8sZn D1wWvfEPZEjAABqUmPC6D+T+w8ScSoF8O+pIXmIMQ9LnHjX5gAre4pHzMnZ8ezWCO2J3 2OSONwfW9s3QjIODHAZ69VSZdxNYSk2ricsFvc3uWX2Tne4ppIb6Cy2sqJ2fUe2eS2lI blPaJzp+U7GBe1ElBhF0G7toqPkFYpSRjz8L7IstYrHButeXY1MXn834ZAa6tLdfR6JU vEnQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v34si10601308plg.232.2019.08.26.10.19.15; Mon, 26 Aug 2019 10:19:31 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731193AbfHZOC5 (ORCPT + 99 others); Mon, 26 Aug 2019 10:02:57 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:40242 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbfHZOC4 (ORCPT ); Mon, 26 Aug 2019 10:02:56 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1i2Fa4-0005AA-H1; Mon, 26 Aug 2019 16:02:48 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id F104F1C0DAE; Mon, 26 Aug 2019 16:02:47 +0200 (CEST) Date: Mon, 26 Aug 2019 14:02:47 -0000 From: tip-bot2 for Sebastian Mayr Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] uprobes/x86: Fix detection of 32-bit user mode Cc: Sebastian Mayr , Thomas Gleixner , Masami Hiramatsu , Dmitry Safonov , Oleg Nesterov , Srikar Dronamraju , stable@vger.kernel.org, Ingo Molnar , linux-kernel@vger.kernel.org In-Reply-To: <20190728152617.7308-1-me@sam.st> References: <20190728152617.7308-1-me@sam.st> MIME-Version: 1.0 Message-ID: <156682816785.22183.13288779592609885843.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Disposition: inline X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 9212ec7d8357ea630031e89d0d399c761421c83b Gitweb: https://git.kernel.org/tip/9212ec7d8357ea630031e89d0d399c761421c83b Author: Sebastian Mayr AuthorDate: Sun, 28 Jul 2019 17:26:17 +02:00 Committer: Thomas Gleixner CommitterDate: Mon, 26 Aug 2019 15:55:09 +02:00 uprobes/x86: Fix detection of 32-bit user mode 32-bit processes running on a 64-bit kernel are not always detected correctly, causing the process to crash when uretprobes are installed. The reason for the crash is that in_ia32_syscall() is used to determine the process's mode, which only works correctly when called from a syscall. In the case of uretprobes, however, the function is called from a exception and always returns 'false' on a 64-bit kernel. In consequence this leads to corruption of the process's return address. Fix this by using user_64bit_mode() instead of in_ia32_syscall(), which is correct in any situation. [ tglx: Add a comment and the following historical info ] This should have been detected by the rename which happened in commit abfb9498ee13 ("x86/entry: Rename is_{ia32,x32}_task() to in_{ia32,x32}_syscall()") which states in the changelog: The is_ia32_task()/is_x32_task() function names are a big misnomer: they suggests that the compat-ness of a system call is a task property, which is not true, the compatness of a system call purely depends on how it was invoked through the system call layer. ..... and then it went and blindly renamed every call site. Sadly enough this was already mentioned here: 8faaed1b9f50 ("uprobes/x86: Introduce sizeof_long(), cleanup adjust_ret_addr() and arch_uretprobe_hijack_return_addr()") where the changelog says: TODO: is_ia32_task() is not what we actually want, TS_COMPAT does not necessarily mean 32bit. Fortunately syscall-like insns can't be probed so it actually works, but it would be better to rename and use is_ia32_frame(). and goes all the way back to: 0326f5a94dde ("uprobes/core: Handle breakpoint and singlestep exceptions") Oh well. 7+ years until someone actually tried a uretprobe on a 32bit process on a 64bit kernel.... Fixes: 0326f5a94dde ("uprobes/core: Handle breakpoint and singlestep exceptions") Signed-off-by: Sebastian Mayr Signed-off-by: Thomas Gleixner Cc: Masami Hiramatsu Cc: Dmitry Safonov Cc: Oleg Nesterov Cc: Srikar Dronamraju Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20190728152617.7308-1-me@sam.st --- arch/x86/kernel/uprobes.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c index d8359eb..8cd745e 100644 --- a/arch/x86/kernel/uprobes.c +++ b/arch/x86/kernel/uprobes.c @@ -508,9 +508,12 @@ struct uprobe_xol_ops { void (*abort)(struct arch_uprobe *, struct pt_regs *); }; -static inline int sizeof_long(void) +static inline int sizeof_long(struct pt_regs *regs) { - return in_ia32_syscall() ? 4 : 8; + /* + * Check registers for mode as in_xxx_syscall() does not apply here. + */ + return user_64bit_mode(regs) ? 8 : 4; } static int default_pre_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs) @@ -521,9 +524,9 @@ static int default_pre_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs) static int emulate_push_stack(struct pt_regs *regs, unsigned long val) { - unsigned long new_sp = regs->sp - sizeof_long(); + unsigned long new_sp = regs->sp - sizeof_long(regs); - if (copy_to_user((void __user *)new_sp, &val, sizeof_long())) + if (copy_to_user((void __user *)new_sp, &val, sizeof_long(regs))) return -EFAULT; regs->sp = new_sp; @@ -556,7 +559,7 @@ static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs long correction = utask->vaddr - utask->xol_vaddr; regs->ip += correction; } else if (auprobe->defparam.fixups & UPROBE_FIX_CALL) { - regs->sp += sizeof_long(); /* Pop incorrect return address */ + regs->sp += sizeof_long(regs); /* Pop incorrect return address */ if (emulate_push_stack(regs, utask->vaddr + auprobe->defparam.ilen)) return -ERESTART; } @@ -675,7 +678,7 @@ static int branch_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs) * "call" insn was executed out-of-line. Just restore ->sp and restart. * We could also restore ->ip and try to call branch_emulate_op() again. */ - regs->sp += sizeof_long(); + regs->sp += sizeof_long(regs); return -ERESTART; } @@ -1056,7 +1059,7 @@ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs) unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs) { - int rasize = sizeof_long(), nleft; + int rasize = sizeof_long(regs), nleft; unsigned long orig_ret_vaddr = 0; /* clear high bits for 32-bit apps */ if (copy_from_user(&orig_ret_vaddr, (void __user *)regs->sp, rasize))