From patchwork Thu Dec 1 14:39:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 28413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp304160wrr; Thu, 1 Dec 2022 06:53:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf6MwFp0Gc3Ng8/yFCPRt5LFgydAlTDAnh2MWouOL8z9+b0W+2l8n2WvHR/dfTiexqzT/ln1 X-Received: by 2002:a17:906:448b:b0:7ad:8bd5:b7df with SMTP id y11-20020a170906448b00b007ad8bd5b7dfmr34736165ejo.57.1669906420891; Thu, 01 Dec 2022 06:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669906420; cv=none; d=google.com; s=arc-20160816; b=vm3iRhBVgWHlk+/4vGORTozvniuDmlMPqfscab8rx9VcUnEemjEatp9H/NjbqJIDvu VAvsdY4Ftirz1XQH3lVYd6Z3BXclIObI4leK1fV2/foP3SpbKChdk/QBInR/prfkOoFu IGtLwBpsjCubyJhGa6FuYEaYIpZIgqqWmbDSkOKuROWEZeOxtcUbJFb35AHDpQrthZKW TQKKH1ekt8/yHJB5S5ohMj/TTsLgsrPniApbZAdMUNWD6x1j9MNxVsBlbaDBqen0Gl7M 4kZtEsXZjEY6EueJiNQyoTWJNXbdnS1wm+gXCIyw0GHNECHDGqrS86TPOv6fk0DKvk9e dTKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/N7S3mdC1Yu65SZ3dimiIZ8uncBm4TAvfNpmLpLEXEM=; b=1JX2rQe7sR3Fd7cZqveUiM9L4hfCip8DkonuKPnH53BzjjG9BqpKNIr1p2gwCUSLIM z2qse4nmSysJHCqce2PE/mPLNznUE7u1RFYwtji6d7qWgBJLYmv3pm+57e+YgWrlaUQX fz23wCXWKQL38uqCVuBEMPBsdfs1LSHFKNgzCLJqwSDcfMJFF4LEtmNormqFXBvXWIga ZeF1d78pPp9njpBpRWXoeNX/8bvWqVSzqJfMVL9YgdB/iiIwpeLBt0cdn/FoGQI0Z1tL kIXVgceF23U3RfRiIsyWBcN1LbItRQLMTvaMFtGopWd6wuLcPCBBd3ZmK2RBHo5NrdLZ ZBNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q2mmCU40; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020a170906975400b007ad8480304dsi4580106ejy.350.2022.12.01.06.53.17; Thu, 01 Dec 2022 06:53:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q2mmCU40; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231856AbiLAOjM (ORCPT + 99 others); Thu, 1 Dec 2022 09:39:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231851AbiLAOjK (ORCPT ); Thu, 1 Dec 2022 09:39:10 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33406A8943 for ; Thu, 1 Dec 2022 06:39:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D91BBB81F54 for ; Thu, 1 Dec 2022 14:39:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81049C43151; Thu, 1 Dec 2022 14:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669905546; bh=DsgCcdAHypRC6WE6LOjXeWdrtqezoJ6nKI9UU3nEiy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q2mmCU40nv1ThpqRBWHEKBqrN9tkNf47L+j+hfULS3VDH8XiT6/m90vxYw5cFCE1w UlncFgw+C/1elEWCXX7rDIPBONFaWgK3Fq/p8BcEobwxAGeS0+TtqkqxZKnzKCFXnZ zen4jEelxst3aZzPz14n+KtLJ+CNkaLXnj52RecGhX7qfhRHgClH0QIrHoVxHUXULk 9psIqagbN+VFQg0n8quC7CAdve+sN+fkakAgxiuC22e5Tu0yoTOCg0JfrULgYN1t7l R/8PahDQ5wTyHkAdSSbM/ftodBYiuJXzpgxtSA1gtX5ZgKP0Jl299whyi2kVzlVpA0 I57Q2iofRPa0A== From: "Masami Hiramatsu (Google)" To: Catalin Marinas , Will Deacon Cc: Mark Rutland , Mark Brown , Kalesh Singh , Masami Hiramatsu , Marc Zyngier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sandeepa Prabhu Subject: [PATCH 1/3] arm64: Prohibit probing on arch_stack_walk() Date: Thu, 1 Dec 2022 23:39:02 +0900 Message-Id: <166990554210.253128.7378208454827328942.stgit@devnote3> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <166990553243.253128.13594802750635478633.stgit@devnote3> References: <166990553243.253128.13594802750635478633.stgit@devnote3> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751023701737543962?= X-GMAIL-MSGID: =?utf-8?q?1751023795061821617?= From: Masami Hiramatsu (Google) Make arch_stack_walk() as NOKPROBE_SYMBOL and make other inline functions called from arch_stack_walk() as nokprobe_inline so that user does not put probe on it, because this function can be used from return_address() which is already NOKPROBE_SYMBOL. Without this, if the kernel built with CONFIG_LOCKDEP=y, just probing arch_stack_walk() via /kprobe_events will crash the kernel on arm64. # echo p arch_stack_walk >> ${TRACEFS}/kprobe_events # echo 1 > ${TRACEFS}/events/kprobes/enable kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 ------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 ------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! PREEMPT SMP Modules linked in: CPU: 0 PID: 17 Comm: migration/0 Tainted: G N 6.1.0-rc5+ #6 Hardware name: linux,dummy-virt (DT) Stopper: 0x0 <- 0x0 pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : kprobe_breakpoint_handler+0x178/0x17c lr : kprobe_breakpoint_handler+0x178/0x17c sp : ffff8000080d3090 x29: ffff8000080d3090 x28: ffff0df5845798c0 x27: ffffc4f59057a774 x26: ffff0df5ffbba770 x25: ffff0df58f420f18 x24: ffff49006f641000 x23: ffffc4f590579768 x22: ffff0df58f420f18 x21: ffff8000080d31c0 x20: ffffc4f590579768 x19: ffffc4f590579770 x18: 0000000000000006 x17: 5f6b636174735f68 x16: 637261203d207264 x15: 64612e202c30203d x14: 2074657366666f2e x13: 30633178302f3078 x12: 302b6b6c61775f6b x11: 636174735f686372 x10: ffffc4f590dc5bd8 x9 : ffffc4f58eb31958 x8 : 00000000ffffefff x7 : ffffc4f590dc5bd8 x6 : 80000000fffff000 x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000 x2 : 0000000000000000 x1 : ffff0df5845798c0 x0 : 0000000000000064 Call trace: kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 ------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! Fixes: 39ef362d2d45 ("arm64: Make return_address() use arch_stack_walk()") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) --- arch/arm64/kernel/stacktrace.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 634279b3b03d..b0e913f944b4 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -23,7 +23,7 @@ * * The regs must be on a stack currently owned by the calling task. */ -static inline void unwind_init_from_regs(struct unwind_state *state, +static nokprobe_inline void unwind_init_from_regs(struct unwind_state *state, struct pt_regs *regs) { unwind_init_common(state, current); @@ -40,7 +40,7 @@ static inline void unwind_init_from_regs(struct unwind_state *state, * * The function which invokes this must be noinline. */ -static __always_inline void unwind_init_from_caller(struct unwind_state *state) +static nokprobe_inline void unwind_init_from_caller(struct unwind_state *state) { unwind_init_common(state, current); @@ -58,7 +58,7 @@ static __always_inline void unwind_init_from_caller(struct unwind_state *state) * duration of the unwind, or the unwind will be bogus. It is never valid to * call this for the current task. */ -static inline void unwind_init_from_task(struct unwind_state *state, +static nokprobe_inline void unwind_init_from_task(struct unwind_state *state, struct task_struct *task) { unwind_init_common(state, task); @@ -218,3 +218,4 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, unwind(&state, consume_entry, cookie); } +NOKPROBE_SYMBOL(arch_stack_walk); From patchwork Thu Dec 1 14:39:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 28412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp303268wrr; Thu, 1 Dec 2022 06:51:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4CVkPXW3N6wztPSOWsZS765fmxz1ixgkBwwmVbO16zYogV3TE7GSoEWyBUxIsfUFi1p1xF X-Received: by 2002:a05:6402:691:b0:46b:c11:9f59 with SMTP id f17-20020a056402069100b0046b0c119f59mr20005229edy.407.1669906303057; Thu, 01 Dec 2022 06:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669906303; cv=none; d=google.com; s=arc-20160816; b=vW7r0CRe9LFaSEz9HtSp1aEqIY2FiWT+wxbChAA1VwfI2le61rGlKIvMZ+Li2u3ZBp 7FnLSpe8piFeEpjCs4DT0+hz/zOjlY6LLLO2EJdJtd6h+k0qIaG8uui82Th+jUvEdlF4 ml4bt5L8smaZqlYt1PfUpaGYsr4Ef6qHXTgmSAMOoIphNWD4mTwi2ABWLHxyuMNGOELl ZARrnJkzckraoXqiVvBRS2Q4r2N99QxTAcb8KjVAE2l6gSFzGp1gPJg6nvtE0/RUckOw szHDKoqrtyiSDuK3W02LHdJhjUrJpR6GDHJu7E0XXc821MoDihwnlaBCXZlywOO2U7AC 824w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LPh+J6ovMcRre+8qxZyrs4XIVbXmtNW1pczNetR674M=; b=LJc5ntsBARXXVvHOeXSZaB3MxEF10UIQLyNqfDYW1XqjEQwahycHJWSwW8G4s/uQBg BiAtYf5bbUhrC/Eh2D+Y2S1yxaXPZ8NubUDusfmJ0k3DH+TIEALBlyRZ/GkXMkkcDsqa O8rgEeLDS+3WQwFp8Bb1+d3xUjPWvR6hYgQQUr0j2KSWuDPS7N14Au6FtMq9YNkeMDub l78KUoa9BUM62su+iau3wFEg+gqHbd0h3asau3WG9WoADGjf6TFVvh9nGQlmqvTBarm0 ttuy6n3RAqFQ2rpn+xH7ZneNJJXt9FeD+orQECOBNirrkhW9qa5qbHDofPFAyS3ZJu6I 01rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oXecHXb0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ty12-20020a170907c70c00b007ae377adb6asi3559071ejc.628.2022.12.01.06.51.16; Thu, 01 Dec 2022 06:51:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oXecHXb0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231503AbiLAOjU (ORCPT + 99 others); Thu, 1 Dec 2022 09:39:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbiLAOjR (ORCPT ); Thu, 1 Dec 2022 09:39:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4A1EA6CE5 for ; Thu, 1 Dec 2022 06:39:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 743B962033 for ; Thu, 1 Dec 2022 14:39:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2B80C433C1; Thu, 1 Dec 2022 14:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669905555; bh=0xKyH1g6a3IOZfst9FQ+WJoEUTNNFziSOx8E0KHTQaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXecHXb04f/aEoCGGcNU1Jpa4NgqXjuULFzxWvcxe4DBU9YoPJ8PSDZhRIj/cEDL0 MKizi7jV7LHaQCIkNsekjbzQI4r2USzz/0zsChFeQjxBuOpmDFbZNLWpwMd1PO2h9N 09FqRkRqskUJD4YU4E5mjoNjItOSZh/kgj4BthWyrZuDJBd+5ChMOacc4y4K+S3kOM j5O7W1e7CPYZzHql7Fr3bfYIp3kTpwM779VVBUD+W8KXvUo4QJWrjpA2s8PypDd3MH ZGtCD91GQyNFRzZiW162WQH3NsqDbv3plhmdDcx9Jvxk3bDr9OV9IvwCgFvExIOuuG T/+LSDsl+4SIA== From: "Masami Hiramatsu (Google)" To: Catalin Marinas , Will Deacon Cc: Mark Rutland , Mark Brown , Kalesh Singh , Masami Hiramatsu , Marc Zyngier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sandeepa Prabhu Subject: [PATCH 2/3] arm64: kprobes: Let arch do_page_fault() fix up page fault in user handler Date: Thu, 1 Dec 2022 23:39:11 +0900 Message-Id: <166990555186.253128.6694458405311467597.stgit@devnote3> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <166990553243.253128.13594802750635478633.stgit@devnote3> References: <166990553243.253128.13594802750635478633.stgit@devnote3> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751023671653996234?= X-GMAIL-MSGID: =?utf-8?q?1751023671653996234?= From: Masami Hiramatsu (Google) Since arm64's do_page_fault() can handle the page fault correctly than kprobe_fault_handler() according to the context, let it handle the page fault instead of simply call fixup_exception() in the kprobe_fault_handler(). Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- arch/arm64/kernel/probes/kprobes.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index c9e4d0720285..d2ae37f89774 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -294,14 +294,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) } break; - case KPROBE_HIT_ACTIVE: - case KPROBE_HIT_SSDONE: - /* - * In case the user-specified fault handler returned - * zero, try to fix up. - */ - if (fixup_exception(regs)) - return 1; } return 0; } From patchwork Thu Dec 1 14:39:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 28415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp304201wrr; Thu, 1 Dec 2022 06:53:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf5s1EsDIrHnLq61whGkca3okW34TOzaxXpZhi0sSIMKXCjv1ZmZLauxAjGPjc5ZU8iFjQSD X-Received: by 2002:a17:906:34d2:b0:7bf:1b9d:c0a8 with SMTP id h18-20020a17090634d200b007bf1b9dc0a8mr18589992ejb.551.1669906426591; Thu, 01 Dec 2022 06:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669906426; cv=none; d=google.com; s=arc-20160816; b=BmbPVsbcnPcitPLMe46yAlSoz4kCQ7RZRVVETUy+82Vq0y/8BPj2S2OeJaPJ7zeawY J84D1PW6Ruws4BoxMRippzlN1/pUV+jcnc6S5iYrDJIfQXu3nl5zUV/ZUfF/nrACcAl3 D17OibxdJ1tDvNp/saugDkyppHxdJUALJEpRdWcVQN78sJF8/QL6y0q1/fl4ZGUCCxPl jekiVBHOfbOxVvM4phxi8LEGEFSEITwo4LnbP0QSjI75CDxjllg5PRiYVoyvpVMqcLzD kPFi8sVKEK8ADYhUWOXPYtsbQIrj5rgvvuR08+bbiXwQyvdqH773RpQCLQgpdTJ0Bm12 ZjvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aQsxL2Fwdl8CrLbO0RZzkRSQviLhgUe+EpPAqXNlAWM=; b=aJUzSKWMTsb/EUlpwn8iC8ZzQi4nJLvhZk/6ALl1AK19LXXDEqg8y1JiZZFjZgcECj dKp8d9bw6i1taLVSBqEGFpnQbOzGVM3g2gLKRje7FQ19rLNoahX8dmd+E8PcsRqTS9GN eGcCFUGOgy1Z9ZNt+kYDZmP+ZFkJdvHZfH7jhbPSUlzJMw0igEtc8nNLaw2p/hAVLH5E QP1FKVxxHYgpXmAGWxPQFLpE8DfFnps/7+vsxC82pJtwC8M1+AnHp0xJin/uwnWIw/q4 NIb/lCjMh3xNvQVTF1ucRBOyZjGHnLCbAfyRrh1TwGH7+Jp9mPpCNUgIlgCDA8BB2Sy0 BCpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JNTeI/BK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw13-20020a056402228d00b0046b2f820e6esi4031789edb.124.2022.12.01.06.53.23; Thu, 01 Dec 2022 06:53:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JNTeI/BK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231415AbiLAOjd (ORCPT + 99 others); Thu, 1 Dec 2022 09:39:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231879AbiLAOj2 (ORCPT ); Thu, 1 Dec 2022 09:39:28 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A8ECA8FE1 for ; Thu, 1 Dec 2022 06:39:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AE9FD62029 for ; Thu, 1 Dec 2022 14:39:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E6BFC433D6; Thu, 1 Dec 2022 14:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669905565; bh=s6ICiOAJJFwO6u7uP13cxjjC82jHSuTLzzoIQZoxdr0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JNTeI/BKZGk6hBCF/yAwVMC1CHBMGqNL+rxW+yTg8twEdGmtg0ijvJ405PVCnq2SJ FURQug7F6k7EfTflm0OzMHKkb36xU4UKDrQ11EhvYz3/Xw/pq1wKkF0o+Teh2oe3S4 uYl0NOVcgqoNChE4HoQ2d7TANB32cMpWsUwdR+ggmlh7ePihjB7QlczQDvz6MDsuuz 74iLg40BxdaZrMQeutfbYIKIsIdmZ4eQ8Cgh+kYjuW2hlTYRwpmNX4TKYjrBTSavgk c/tKSjHhAXSR06djwoo82kxV5GOukSHcniabmY/vep4mGiDwd8sTOtImg0rR0iHg9V 1HbrEBQ7GqGgg== From: "Masami Hiramatsu (Google)" To: Catalin Marinas , Will Deacon Cc: Mark Rutland , Mark Brown , Kalesh Singh , Masami Hiramatsu , Marc Zyngier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sandeepa Prabhu Subject: [PATCH 3/3] arm64: kprobes: Return DBG_HOOK_ERROR if kprobes can not handle a BRK Date: Thu, 1 Dec 2022 23:39:21 +0900 Message-Id: <166990556124.253128.2968612748605960211.stgit@devnote3> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <166990553243.253128.13594802750635478633.stgit@devnote3> References: <166990553243.253128.13594802750635478633.stgit@devnote3> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751023800966913610?= X-GMAIL-MSGID: =?utf-8?q?1751023800966913610?= From: Masami Hiramatsu (Google) Return DBG_HOOK_ERROR if kprobes can not handle a BRK because it fails to find a kprobe corresponding to the address. Since arm64 kprobes uses stop_machine based text patching for removing BRK, it ensures all running kprobe_break_handler() is done at that point. And after removing the BRK, it removes the kprobe from its hash list. Thus, if the kprobe_break_handler() fails to find kprobe from hash list, there is a bug. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Mark Rutland --- arch/arm64/kernel/probes/kprobes.c | 79 +++++++++++++++++------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index d2ae37f89774..ea56b22d4da8 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -298,7 +298,8 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) return 0; } -static void __kprobes kprobe_handler(struct pt_regs *regs) +static int __kprobes +kprobe_breakpoint_handler(struct pt_regs *regs, unsigned long esr) { struct kprobe *p, *cur_kprobe; struct kprobe_ctlblk *kcb; @@ -308,39 +309,45 @@ static void __kprobes kprobe_handler(struct pt_regs *regs) cur_kprobe = kprobe_running(); p = get_kprobe((kprobe_opcode_t *) addr); + if (WARN_ON_ONCE(!p)) { + /* + * Something went wrong. This must be put by kprobe, but we + * could not find corresponding kprobes. Let the kernel handle + * this error case. + */ + return DBG_HOOK_ERROR; + } - if (p) { - if (cur_kprobe) { - if (reenter_kprobe(p, regs, kcb)) - return; - } else { - /* Probe hit */ - set_current_kprobe(p); - kcb->kprobe_status = KPROBE_HIT_ACTIVE; - - /* - * If we have no pre-handler or it returned 0, we - * continue with normal processing. If we have a - * pre-handler and it returned non-zero, it will - * modify the execution path and no need to single - * stepping. Let's just reset current kprobe and exit. - */ - if (!p->pre_handler || !p->pre_handler(p, regs)) { - setup_singlestep(p, regs, kcb, 0); - } else - reset_current_kprobe(); - } + if (cur_kprobe) { + /* Hit a kprobe inside another kprobe */ + if (!reenter_kprobe(p, regs, kcb)) + return DBG_HOOK_ERROR; + } else { + /* Probe hit */ + set_current_kprobe(p); + kcb->kprobe_status = KPROBE_HIT_ACTIVE; + + /* + * If we have no pre-handler or it returned 0, we + * continue with normal processing. If we have a + * pre-handler and it returned non-zero, it will + * modify the execution path and no need to single + * stepping. Let's just reset current kprobe and exit. + */ + if (!p->pre_handler || !p->pre_handler(p, regs)) + setup_singlestep(p, regs, kcb, 0); + else + reset_current_kprobe(); } - /* - * The breakpoint instruction was removed right - * after we hit it. Another cpu has removed - * either a probepoint or a debugger breakpoint - * at this address. In either case, no further - * handling of this interrupt is appropriate. - * Return back to original instruction, and continue. - */ + + return DBG_HOOK_HANDLED; } +static struct break_hook kprobes_break_hook = { + .imm = KPROBES_BRK_IMM, + .fn = kprobe_breakpoint_handler, +}; + static int __kprobes kprobe_breakpoint_ss_handler(struct pt_regs *regs, unsigned long esr) { @@ -365,18 +372,6 @@ static struct break_hook kprobes_break_ss_hook = { .fn = kprobe_breakpoint_ss_handler, }; -static int __kprobes -kprobe_breakpoint_handler(struct pt_regs *regs, unsigned long esr) -{ - kprobe_handler(regs); - return DBG_HOOK_HANDLED; -} - -static struct break_hook kprobes_break_hook = { - .imm = KPROBES_BRK_IMM, - .fn = kprobe_breakpoint_handler, -}; - /* * Provide a blacklist of symbols identifying ranges which cannot be kprobed. * This blacklist is exposed to userspace via debugfs (kprobes/blacklist).