From patchwork Thu Feb 29 23:16:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13577704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB37EC48BF6 for ; Thu, 29 Feb 2024 23:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=bX35rRVbZdzIaDcnugHwtmeZTO/6R13hhEVidY+7C3k=; b=qoK3RNFfd5R4un 4sw1ibmB9BjKupa/HtFlLrakX2ecxHZ91C3Pc8134IRSe2dUYrmC1Y5fOHlAzhxBmztGdQKVxhN9B Ha05Wlsfa1LvqyqDaWMBQZpOaOOGZw87byd5qJaglbjNwbvtmdyy6ZDD06R9WB+HkNkWm4UmvFrhv AO94KhVurC/HG66w0L3X37p5hFcmHGKgyt2Eb26+AB9O9dTzQ97ybiVewRppPSk+riWtSKP3ypbDf Z3zob0zi6X64TQ9dKvzcNZa8WivEF8VM7ga6fTtY0C1gK/953cad+dfEOr2q7kK1TBheZqgu6oJVR CFCAX2nzbmYrzMmpLchg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfpe1-0000000FZIx-0zP2; Thu, 29 Feb 2024 23:16:53 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfpdy-0000000FZIQ-1n3I for linux-arm-kernel@lists.infradead.org; Thu, 29 Feb 2024 23:16:51 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-412c1d433c4so5919155e9.0 for ; Thu, 29 Feb 2024 15:16:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709248608; x=1709853408; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=67SNOCAdR0s4Rh4ZptML72F1P1c4wCYZ2HszSt1XfEo=; b=FFcul9GahYZrmkByQKsm0FNjMXFCH9YEDm9yHO44ozEWieQaPuWaBAuCRLUA2Rc2k+ +UK2bBijNgNimTHFS18WRTcx4KclCYFkPwFYYewat0qvV1Xlf4QRQTsCjw4QtbqmXLKE fY04MpTmq1yyL0x8+sNr1u/IGmi7yPorv/bmJ3NgFKgMlCMmqDyyRJ3GUE466D5yF+l/ QDErZg/aAtaXcINNEHfFM1l2buHUleqWicQnOmiRnmI49p1U0cEj9uyT2VnwIBHTj/gc cmOMRk/50mq8NY+mlqHoKNJfjsrugro0IHN67REwBlJiYwPgKYukTPY8OcdvdG7c/HeE 3lXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709248608; x=1709853408; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=67SNOCAdR0s4Rh4ZptML72F1P1c4wCYZ2HszSt1XfEo=; b=FDXa6aOp8WhHYjdmaoErVluHBfPzT6t7UszijeFJ+Z+NBVBWxfrBBBzNOt1u0GrbSR Hku8AmM3/9o0I9KLvz3vAed1o9axPNPVbpSdyBvuKmuCpOATUmfZpKlWpv6mMJgWxdKv juGbkZFmtD1Dj0l1aMdAmwiFKkKrhFxevNusL0ZyoKHrKOTEOaSoAHvGgUsRu1kAOPzC O2FpTuRQN5MIpWBxWb8ERJb4QqOBlloQHlYgO/uk04za4+DwrLN4mRE7QTyEUSSlz7Hy 44BwmFg5jOnwKP0rpsl4uAQqu4f8po812OYJqjqnpgF3AkJqNaPbdxJsOJrJy99lKUZu FCwg== X-Forwarded-Encrypted: i=1; AJvYcCVepCp3RkUXInPkqJucHbynlI6hHQ2yZbC24cSfXWtnLVeCYx1e8+tfWV3alnWY1acN55Q31PHQ7JwIajYxP3hVyJVWpvgcL2HaENicQgd+RP5/Emk= X-Gm-Message-State: AOJu0YzsZGGA8HKxGqRoaSdBHVhHjS2r619LjU1CSvnI2baYVx0pDZY0 W3jZ4+/1jkDOIagrx04hYgWP7iplHFazVe5JOOP2/Dic8AotU871zpLnqjZt0M8ocQ== X-Google-Smtp-Source: AGHT+IE45Yvom/A/j4RSMfDYF1CUEdZTkwIkyVR4ezwPFfY1flUHd2kbPJ5xKXEOW1rOccNE4mu7Qg== X-Received: by 2002:a05:600c:c8b:b0:412:85c2:db12 with SMTP id fj11-20020a05600c0c8b00b0041285c2db12mr75679wmb.2.1709248607440; Thu, 29 Feb 2024 15:16:47 -0800 (PST) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id m17-20020a05600c4f5100b00412b7456ef7sm3506412wmq.5.2024.02.29.15.16.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Feb 2024 15:16:46 -0800 (PST) From: Puranjay Mohan To: catalin.marinas@arm.com, will@kernel.org, nathan@kernel.org, mark.rutland@arm.com, broonie@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Cc: puranjay12@gmail.com Subject: [PATCH] arm64: prohibit probing on arch_kunwind_consume_entry() Date: Thu, 29 Feb 2024 23:16:20 +0000 Message-Id: <20240229231620.24846-1-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240229_151650_494974_280DA26A X-CRM114-Status: GOOD ( 14.38 ) 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 Make arch_kunwind_consume_entry() as __always_inline otherwise the compiler might not inline it and allow attaching probes to it. Without this, just probing arch_kunwind_consume_entry() via /kprobe_events will crash the kernel on arm64. The crash can be reproduced using the following compiler and kernel combination: clang version 19.0.0git (https://github.com/llvm/llvm-project.git d68d29516102252f6bf6dc23fb22cef144ca1cb3) commit 87adedeba51a ("Merge tag 'net-6.8-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net") [root@localhost ~]# echo 'p arch_kunwind_consume_entry' > /sys/kernel/debug/tracing/kprobe_events [root@localhost ~]# echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable Modules linked in: aes_ce_blk aes_ce_cipher ghash_ce sha2_ce virtio_net sha256_arm64 sha1_ce arm_smccc_trng net_failover failover virtio_mmio uio_pdrv_genirq uio sch_fq_codel dm_mod dax configfs CPU: 3 PID: 1405 Comm: bash Not tainted 6.8.0-rc6+ #14 Hardware name: linux,dummy-virt (DT) pstate: 604003c5 (nZCv DAIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : kprobe_breakpoint_handler+0x17c/0x258 lr : kprobe_breakpoint_handler+0x17c/0x258 sp : ffff800085d6ab60 x29: ffff800085d6ab60 x28: ffff0000066f0040 x27: ffff0000066f0b20 x26: ffff800081fa7b0c x25: 0000000000000002 x24: ffff00000b29bd18 x23: ffff00007904c590 x22: ffff800081fa6590 x21: ffff800081fa6588 x20: ffff00000b29bd18 x19: ffff800085d6ac40 x18: 0000000000000079 x17: 0000000000000001 x16: ffffffffffffffff x15: 0000000000000004 x14: ffff80008277a940 x13: 0000000000000003 x12: 0000000000000003 x11: 00000000fffeffff x10: c0000000fffeffff x9 : aa95616fdf80cc00 x8 : aa95616fdf80cc00 x7 : 205d343137373231 x6 : ffff800080fb48ec x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000000 x2 : 0000000000000000 x1 : ffff800085d6a910 x0 : 0000000000000079 Call trace: kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_kunwind_consume_entry, .offset = 0, .addr = arch_kunwind_consume_entry+0x0/0x40 ------------[ 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_kunwind_consume_entry, .offset = 0, .addr = arch_kunwind_consume_entry+0x0/0x40 Fixes: 1aba06e7b2b49 ("arm64: stacktrace: factor out kunwind_stack_walk()") Signed-off-by: Puranjay Mohan Reviewed-by: Mark Rutland --- arch/arm64/kernel/stacktrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 87adedeba51a822533649b143232418b9e26d08b diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 7f88028a00c0..b2a60e0bcfd2 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -247,7 +247,7 @@ struct kunwind_consume_entry_data { void *cookie; }; -static bool +static __always_inline bool arch_kunwind_consume_entry(const struct kunwind_state *state, void *cookie) { struct kunwind_consume_entry_data *data = cookie;