From patchwork Wed Mar 3 07:10:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaobo Huang X-Patchwork-Id: 12114241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F804C433E0 for ; Wed, 3 Mar 2021 21:05:46 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C243364EF8 for ; Wed, 3 Mar 2021 21:05:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C243364EF8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=So95yhkiXBLsjsTCRJleaffTxvAPFv31K5WNx/PYV8E=; b=QY8LVDvgX0Usmqmk0C0fuiAIXY Lu3Y/V7nAnntgxPVt4dHNSoytJumpoAQBkNBaYlpj4bnf1jjna9wElUIR4tQ00ZcPUKRJcahlECKt 1zJsDW3MGosUUZ29UFVRyFze+ivowNFyBHcl++oxZsopyCaOqz/OZai6fptjvqBpayDnGwiJtWyPf 8xz0M51jNXO8qNm0hRpGvEB8Jxk1ZGGNyTctv0eOf9IdJOVdnFVoGwnvStEyqCQlRSQ8/RVZjdGcg 0tyGxooJUtyKICvLnvrOXaX+V6o7FFwaDbTWLb+f0mFMqtemas5WJhI67TizbuAV2F/D31kgXa3OJ HYCyVTsQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHYc4-006WKd-7b; Wed, 03 Mar 2021 21:00:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHT7Y-005JST-EW for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:09:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-ID: Content-Description:In-Reply-To:References; bh=fJhxIWZK34X35CsCHY0uPzSIIBgOIug+VnqoD1nyLPY=; b=h/4ZzvtsIpGe3F893I74wCZMI2 y/KsJZ8Qt5wlvR8fYqlXct9Rrf90rOt9EJy8wTb3HPWbkIyCz1HkcYSv1KU27aIaAHeqe6W64sn90 Sk6+pERHIFVgshxp993H0QrV5sriojiyz3sAMExvNKDxVin76pcm1FoyJ+SJeAOvd58BU3MR6LcxT UpTRusOwigKb5Lofr7crB8eXuoc+0Dh5D5xqTdSTjlk3jn7BJ8VUp5kP1gaq3U4t7GRl4Abw9RYBH SjglheiHSAnqeLFwmvo6fPBybnI20HAQA/e2tc7r1l31wCbPzztZUiS2EP9ulI2uwY0hEAiAG/Ud7 396vl0Nw==; Received: from szxga07-in.huawei.com ([45.249.212.35]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHLfW-001dAN-K8 for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 07:11:41 +0000 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Dr4qx4bHcz7rgP; Wed, 3 Mar 2021 15:09:33 +0800 (CST) Received: from DESKTOP-E0KHRBE.china.huawei.com (10.67.103.82) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Wed, 3 Mar 2021 15:11:06 +0800 From: ShaoBo Huang To: , , , , , , CC: , , , , , , Subject: [PATCH 4.9.y] arm: kprobes: Allow to handle reentered kprobe on single-stepping Date: Wed, 3 Mar 2021 15:10:52 +0800 Message-ID: <20210303071052.33740-1-huangshaobo6@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.67.103.82] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210303_071141_308417_367F75D7 X-CRM114-Status: UNSURE ( 8.18 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Masami Hiramatsu commit f3fbd7ec62dec1528fb8044034e2885f2b257941 upstream This is arm port of commit 6a5022a56ac3 ("kprobes/x86: Allow to handle reentered kprobe on single-stepping") Since the FIQ handlers can interrupt in the single stepping (or preparing the single stepping, do_debug etc.), we should consider a kprobe is hit in the NMI handler. Even in that case, the kprobe is allowed to be reentered as same as the kprobes hit in kprobe handlers (KPROBE_HIT_ACTIVE or KPROBE_HIT_SSDONE). The real issue will happen when a kprobe hit while another reentered kprobe is processing (KPROBE_REENTER), because we already consumed a saved-area for the previous kprobe. Signed-off-by: Masami Hiramatsu Signed-off-by: Jon Medhurst Fixes: 24ba613c9d6c ("ARM kprobes: core code") Cc: stable@vger.kernel.org #v2.6.25~v4.11 Signed-off-by: huangshaobo --- arch/arm/probes/kprobes/core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/probes/kprobes/core.c b/arch/arm/probes/kprobes/core.c index 3eb018fa1a1f..c3362ddd6c4c 100644 --- a/arch/arm/probes/kprobes/core.c +++ b/arch/arm/probes/kprobes/core.c @@ -270,6 +270,7 @@ void __kprobes kprobe_handler(struct pt_regs *regs) switch (kcb->kprobe_status) { case KPROBE_HIT_ACTIVE: case KPROBE_HIT_SSDONE: + case KPROBE_HIT_SS: /* A pre- or post-handler probe got us here. */ kprobes_inc_nmissed_count(p); save_previous_kprobe(kcb); @@ -278,6 +279,11 @@ void __kprobes kprobe_handler(struct pt_regs *regs) singlestep(p, regs, kcb); restore_previous_kprobe(kcb); break; + case KPROBE_REENTER: + /* A nested probe was hit in FIQ, it is a BUG */ + pr_warn("Unrecoverable kprobe detected at %p.\n", + p->addr); + /* fall through */ default: /* impossible cases */ BUG();