Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp172273pxp; Tue, 8 Mar 2022 23:58:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJyq4Z3R1x+YR8hhQvRczUD92TG1n2q6KleM0qTE9IrQbxZ06bdOFwWRHvobQtvxE+99ahXw X-Received: by 2002:a05:6a00:1705:b0:4e1:5a1:c626 with SMTP id h5-20020a056a00170500b004e105a1c626mr22278223pfc.1.1646812725873; Tue, 08 Mar 2022 23:58:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646812725; cv=none; d=google.com; s=arc-20160816; b=PvWb/TBFLAK+KCtMkJX6lH2H05l9snLCUS49nqMIR6cFOtNnxzBPQSsclRd9xE0IGG xC6iYp1umL4RB8diKs6w+ujZNZnYeYjP9QyJ3Cfs0RE5waVx3LHrGOBjvftfk7ZSedn9 RZ2IM6DDrmk0p321Jex0tzdN6ZMHqH0nCajrHCmwnkD7q3+pLf/7fetZ8wSKiEoOxBf5 naNyX7s6YE3Wx7Sz4qlVJWZZwauad+vDfI1QvDP9YCFnBKSr1IB7g1SJRCMzmyLQnYAH 7V7Q7myn872huXYfJGo2Y7wNgU/X43Bz1D/BYi9edCCllv2ekCpkKT9YuFG3Y0pkCedR uHUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=QfrLJvrzYft2T/XZ3bEwCogezzozBssPIQEQBlmGwaA=; b=gEJP0rZcB0eoP/769kg/4S0ZO2+Glp6+o7gGWzgClKc6ibTDtVjachcRS9MChQNqJe 1dxGbbTR6kC3sTEszTq6XZKlqF4T/s0zJwI/TYPZ3FX5lEvHKNCV14UwyDIl8eMW4J/J 0eSRwDUKKYnmrnOHRdDFMm/Tto1QfjX8WG/A0WmlWXajDhp89r8l2CarMqZ+yyHy5wZw l4gcXiNJ8WPPP6eyks/EQJUo8lQ55YHzmK5odOW/iYW6ZzEnToPritkvJAwuGDgK62Rn 1cj6OA/8A6thq8t5e3A0v2f0aGqTJjQDhRpFRdnENI+cW7t6Tl7hlFR9442z4AWDfk6F 84cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3QrE67++; dkim=neutral (no key) header.i=@linutronix.de header.b=0Eatodh3; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u189-20020a6385c6000000b0038031fd9eeasi1129183pgd.600.2022.03.08.23.58.31; Tue, 08 Mar 2022 23:58:45 -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=@linutronix.de header.s=2020 header.b=3QrE67++; dkim=neutral (no key) header.i=@linutronix.de header.b=0Eatodh3; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbiCIH5H (ORCPT + 99 others); Wed, 9 Mar 2022 02:57:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbiCIH41 (ORCPT ); Wed, 9 Mar 2022 02:56:27 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA314164D21; Tue, 8 Mar 2022 23:55:04 -0800 (PST) Date: Wed, 09 Mar 2022 07:55:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646812503; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QfrLJvrzYft2T/XZ3bEwCogezzozBssPIQEQBlmGwaA=; b=3QrE67++G6uzzcrGVXdBltfvQsmeBtdEq9au49d5lK4Ss4A9rnWWrOFp9eyWGdM1PpoG16 MFfHdObv3EhfOYYYd7PXpSHizTxrMAwFoUZEDDe2LSKygEFVy41ds4aJq8WxBVfCPCL+Ly 22yIrdpv3VhyRFFgEwIe8WNxN6M5O+WHVjZNXDWyKaFadNIwKfXFB+5cqRemrX7bPjh0jb OOwcrl7FVbocLlRd+Mepf8ZQA8Nu3zzPMfODuKY7p506Au5aEQSskWunxL0l1JbnmmnOnG bfPDEi8RrebO3B2GFbf2mIVBEX21lOoAQa6QcoMmGNOUyuQVwhmVNjWyKcN6jQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646812503; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QfrLJvrzYft2T/XZ3bEwCogezzozBssPIQEQBlmGwaA=; b=0Eatodh3DbaDIkRvke/VyB1apXTOQSbOnvL/K/OXvx7WNrQTTZq87talhI2tVX95S8AjNu GoxzqmfoTUP50LDw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86/livepatch: Validate __fentry__ location Cc: Josh Poimboeuf , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220308154318.285971256@infradead.org> References: <20220308154318.285971256@infradead.org> MIME-Version: 1.0 Message-ID: <164681250198.16921.8901861440480788939.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The following commit has been merged into the x86/core branch of tip: Commit-ID: a557abfd1a16072e4d25bdf226e3b761e6f10741 Gitweb: https://git.kernel.org/tip/a557abfd1a16072e4d25bdf226e3b761e6f10741 Author: Peter Zijlstra AuthorDate: Tue, 08 Mar 2022 16:30:30 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 08 Mar 2022 23:53:31 +01:00 x86/livepatch: Validate __fentry__ location Currently livepatch assumes __fentry__ lives at func+0, which is most likely untrue with IBT on. Instead make it use ftrace_location() by default which both validates and finds the actual ip if there is any in the same symbol. Suggested-by: Josh Poimboeuf Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20220308154318.285971256@infradead.org --- arch/powerpc/include/asm/livepatch.h | 10 ---------- kernel/livepatch/patch.c | 19 ++----------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/arch/powerpc/include/asm/livepatch.h b/arch/powerpc/include/asm/livepatch.h index 4fe018c..7b9dcd5 100644 --- a/arch/powerpc/include/asm/livepatch.h +++ b/arch/powerpc/include/asm/livepatch.h @@ -19,16 +19,6 @@ static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned long ip) regs_set_return_ip(regs, ip); } -#define klp_get_ftrace_location klp_get_ftrace_location -static inline unsigned long klp_get_ftrace_location(unsigned long faddr) -{ - /* - * Live patch works only with -mprofile-kernel on PPC. In this case, - * the ftrace location is always within the first 16 bytes. - */ - return ftrace_location_range(faddr, faddr + 16); -} - static inline void klp_init_thread_info(struct task_struct *p) { /* + 1 to account for STACK_END_MAGIC */ diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c index fe316c0..c172bf9 100644 --- a/kernel/livepatch/patch.c +++ b/kernel/livepatch/patch.c @@ -124,19 +124,6 @@ unlock: ftrace_test_recursion_unlock(bit); } -/* - * Convert a function address into the appropriate ftrace location. - * - * Usually this is just the address of the function, but on some architectures - * it's more complicated so allow them to provide a custom behaviour. - */ -#ifndef klp_get_ftrace_location -static unsigned long klp_get_ftrace_location(unsigned long faddr) -{ - return faddr; -} -#endif - static void klp_unpatch_func(struct klp_func *func) { struct klp_ops *ops; @@ -153,8 +140,7 @@ static void klp_unpatch_func(struct klp_func *func) if (list_is_singular(&ops->func_stack)) { unsigned long ftrace_loc; - ftrace_loc = - klp_get_ftrace_location((unsigned long)func->old_func); + ftrace_loc = ftrace_location((unsigned long)func->old_func); if (WARN_ON(!ftrace_loc)) return; @@ -186,8 +172,7 @@ static int klp_patch_func(struct klp_func *func) if (!ops) { unsigned long ftrace_loc; - ftrace_loc = - klp_get_ftrace_location((unsigned long)func->old_func); + ftrace_loc = ftrace_location((unsigned long)func->old_func); if (!ftrace_loc) { pr_err("failed to find location for function '%s'\n", func->old_name);