Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp181256ybh; Fri, 6 Mar 2020 19:03:07 -0800 (PST) X-Google-Smtp-Source: ADFU+vvmr6roWaM63EfJ4o8SMM+EKPJuN5l9YA1SRe8f8Vaq4VFiGHNVjLZPdtj0YrNy+LZGjQHQ X-Received: by 2002:aca:4183:: with SMTP id o125mr4601668oia.125.1583550187500; Fri, 06 Mar 2020 19:03:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583550187; cv=none; d=google.com; s=arc-20160816; b=NPnfAi0MDcR9knUHgz7myB08H9Kcbpaa+MoAlmT7KuS2mDjWQU8B7HW+SfCvXBUdqk PK3pwSr8PzmD71vzYAt8DJqoGwN8HyBSSWIAxUNb5YLGqy0cL7ol1aADzK4P806wkIDs 0p2KSiPDhzmcbxTB69uFJicO3yQQlofp8ZFjBAFsRxT+AAVSwrdV6AX2ae/oo+Du1m1S bArs0YiTtuwTpULngTorH6q8n43EOj1+orbNEZzPZTGlRr8iuXVMbQ9JJO0LOtaWyz3+ o7zMX/R3Jq9Z4QFvPcTewQUPQeYRJ2oXVEoaNreiHr1rEYZ4ijjXpsc8VQ0iHtjC0d8t ESWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:message-id:date:subject:cc:to:from:dkim-signature; bh=QL+TSWIk48qhQ1tpFRK+ElgI+8P4DMWhow+LjdFrwYE=; b=voPdjmJB7tWPriHFo2Sb2d34Lhx3lIAK25BhFdRMMbsQkRvCc9R09Xr0gXdOELV8zE MzPC/Wx/U8pclrrM4D4Gsn5b0jIGmnlQqsD6mi56ckImX42zX3ROcYBpSvRwY27xcjMH z21pqPYlPqPZeEUYT2G9UMxaC193JkrecA3DAstU/tSu96Qrtrc0sMuwl360vxwWs3qN 1vuqVDhr76+WJvXE5ChJ2QOo/7JumZGQXEF0wcXWYs1sX4lKeGbPd2/6/KqiOK9IegV/ eeyFGYgEETexHg16lZXJkhLLKmg2xVuMROj2jg0C8yQyDlJS9akYMY6gnDrmrB55TG8J TiUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s1k85rJa; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g24si2839354otn.296.2020.03.06.19.02.53; Fri, 06 Mar 2020 19:03:07 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=s1k85rJa; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbgCGDCS (ORCPT + 99 others); Fri, 6 Mar 2020 22:02:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:37666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726259AbgCGDCS (ORCPT ); Fri, 6 Mar 2020 22:02:18 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CA446206D5; Sat, 7 Mar 2020 03:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583550137; bh=KL3/2VYI5+pqT4gg3RT6fC0ThurhRFfSREX6XD1ck8M=; h=From:To:Cc:Subject:Date:From; b=s1k85rJaTFgjUN+9IAXMvRBHC/mhxX2vWHqatKWCKGV6Tau+hnGQYbL9Fml4yBK9Y iRtC9UAUpE+RxmQ7ZOjqcfNi1JrGgKZu+y85+g1TDux+UtjT1GpbExKN1Xo3Lt2HIx Al80lRySL7x4jXDyn+LQS/Y3tTNqCpHQdEZ2vDJU= From: Masami Hiramatsu To: Ingo Molnar Cc: "Paul E . McKenney" , Peter Zijlstra , Joel Fernandes , Steven Rostedt , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, gregkh@linuxfoundation.org, gustavo@embeddedor.com, tglx@linutronix.de, josh@joshtriplett.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, stable@vger.kernel.org Subject: [PATCH] x86/kprobes: Prohibit probing on rcu_nmi_exit() and ist_exit() Date: Sat, 7 Mar 2020 12:02:12 +0900 Message-Id: <158355013189.14191.9105069890402942867.stgit@devnote2> X-Mailer: git-send-email 2.20.1 User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prohibit probing on rcu_nmi_exit() and ist_exit() which are called from do_int3()'s kprobe path after kprobe_int3_handler(). The commit c13324a505c7 ("x86/kprobes: Prohibit probing on functions before kprobe_int3_handler()") tried to fix similar issue, but it only marks the functions before kprobe_int3_handler() in do_int3(). If we put a kprobe on rcu_nmi_exit() or ist_exit(), the kprobes will detect reentrance. However, it only skips the kprobe handler, exits from do_int3() and hits ist_exit() and rcu_nmi_exit() again. Thus, it causes another int3 exception and finally we will get the kernel panic with "Unrecoverable kprobe detected." error message. This is reproducible by the following commands. / # echo 0 > /proc/sys/debug/kprobes-optimization / # echo p vfs_read > /sys/kernel/debug/tracing/kprobe_events / # echo p rcu_nmi_exit >> /sys/kernel/debug/tracing/kprobe_events / # echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable Fixes: c13324a505c7 ("x86/kprobes: Prohibit probing on functions before kprobe_int3_handler()") Signed-off-by: Masami Hiramatsu Cc: stable@vger.kernel.org --- arch/x86/kernel/traps.c | 1 + kernel/rcu/tree.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 6ef00eb6fbb9..c63fb7697794 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -115,6 +115,7 @@ void ist_exit(struct pt_regs *regs) if (!user_mode(regs)) rcu_nmi_exit(); } +NOKPROBE_SYMBOL(ist_exit); /** * ist_begin_non_atomic() - begin a non-atomic section in an IST exception diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index d91c9156fab2..c49ea0e919f9 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -670,6 +670,7 @@ void rcu_nmi_exit(void) { rcu_nmi_exit_common(false); } +NOKPROBE_SYMBOL(rcu_nmi_exit); /** * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle