Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3854490pxv; Mon, 19 Jul 2021 10:19:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHun/uY2SSWSr8u+Q/5Q1JS+n9Ik1L2ROYQN8gjIfLn4E+rCiXTelixz9RRxCnt4A8XWky X-Received: by 2002:a50:ff01:: with SMTP id a1mr35385928edu.253.1626715150388; Mon, 19 Jul 2021 10:19:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626715150; cv=none; d=google.com; s=arc-20160816; b=rlkDmu7xLiUSI5bqCirVnJi64BFwPN9DzwoBOuuaWvSlg2qw5YFi+C8PUoWFb00s64 xj8yYJPepuatn8s0egz9wt2KHJSCdT5rVj9UaTK4k9sNgQ4/DsqSRxLLzzOEGO1zWrc5 58dcVmEkDB3YN5VYBd3xH7sv1H4O/e21aZolvV1nNoGm1cv1nuIk96nLOijPg2UPTrgA mfTiqooKp2JFsOy63bXyaLVErOfGU3/031swtVD+RSubaSROQC070d15grTCgSCHtuSG GR/uBEpRN+gQDhNloHGiBE3T9mfhMyu+K6gc1SWKtenQ6dVsYD5JMZxBocvmkiYnECpC 8uJQ== 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=qh+dtqBUkV+lXNWjdkwsm4ITKZgd4zPHyJdyDWbPFMc=; b=UUmbyKuTzVzPGXarHKgZghh3DFGxz8PrL/RuRNO/aGDJsXvmYT07h/BFNH3igR826Y vE/BgTliBS9Y4acv4Lz3aaXK8YQlIJqt/neWkpadBwFsQEOgqPQAhDV3WWoevVsG7C37 h1OdmgOQ0cimIarQ8mcIBIexMv6JGJBXvx389L9S0Ly3LFXFlL7G/E8fba0xEtDNEKXu aFXje3lSFpB5g+vWMvWLdjd2JaAK2bjWMH8mFg2DgQ+/pXg0AOZF/9eYoRqwGmrLXO07 p/Dl/jil5w99eNBsa+ljmHKc1P8+1uzmwDOQGNWvYelyZN2LvVHQsolNETJ0TmFv7hEu ThGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rohONbfb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp33si8985020ejc.193.2021.07.19.10.18.47; Mon, 19 Jul 2021 10:19:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rohONbfb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355275AbhGSQgM (ORCPT + 99 others); Mon, 19 Jul 2021 12:36:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:40472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348085AbhGSPYe (ORCPT ); Mon, 19 Jul 2021 11:24:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 05ACE61422; Mon, 19 Jul 2021 16:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710488; bh=bzAJFaqA633qEJK6/CJXsDy9zhJaM2uv59iOV6xizyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rohONbfbyl2HOdYUpDkkqrWZExtBc+c7FBknZ7uUauCTiyx0OlZ9yPJ6ZxpZHRArM 51bpEwyYsrFXYt+Hrpw5sGoeLCVqG0u+gmQ5wIsJGp3KaoPrMHRn6W8fhhs2DczKRS F3tr6dwoTd+ka386N1DeDEbCh5hq6R9OA4ox/BwM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , "Peter Zijlstra (Intel)" , Ingo Molnar , Masami Hiramatsu , Sasha Levin Subject: [PATCH 5.10 237/243] jump_label: Fix jump_label_text_reserved() vs __init Date: Mon, 19 Jul 2021 16:54:26 +0200 Message-Id: <20210719144948.573397991@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ Upstream commit 9e667624c291753b8a5128f620f493d0b5226063 ] It turns out that jump_label_text_reserved() was reporting __init text as being reserved past the time when the __init text was freed and re-used. For a long time, this resulted in, at worst, not being able to kprobe text that happened to land at the re-used address. However a recent commit e7bf1ba97afd ("jump_label, x86: Emit short JMP") made it a fatal mistake because it now needs to read the instruction in order to determine the conflict -- an instruction that's no longer there. Fixes: 4c3ef6d79328 ("jump label: Add jump_label_text_reserved() to reserve jump points") Reported-by: kernel test robot Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Reviewed-by: Masami Hiramatsu Link: https://lore.kernel.org/r/20210628113045.045141693@infradead.org Signed-off-by: Sasha Levin --- kernel/jump_label.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index a0c325664190..4ae693ce71a4 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -316,14 +316,16 @@ static int addr_conflict(struct jump_entry *entry, void *start, void *end) } static int __jump_label_text_reserved(struct jump_entry *iter_start, - struct jump_entry *iter_stop, void *start, void *end) + struct jump_entry *iter_stop, void *start, void *end, bool init) { struct jump_entry *iter; iter = iter_start; while (iter < iter_stop) { - if (addr_conflict(iter, start, end)) - return 1; + if (init || !jump_entry_is_init(iter)) { + if (addr_conflict(iter, start, end)) + return 1; + } iter++; } @@ -561,7 +563,7 @@ static int __jump_label_mod_text_reserved(void *start, void *end) ret = __jump_label_text_reserved(mod->jump_entries, mod->jump_entries + mod->num_jump_entries, - start, end); + start, end, mod->state == MODULE_STATE_COMING); module_put(mod); @@ -786,8 +788,9 @@ early_initcall(jump_label_init_module); */ int jump_label_text_reserved(void *start, void *end) { + bool init = system_state < SYSTEM_RUNNING; int ret = __jump_label_text_reserved(__start___jump_table, - __stop___jump_table, start, end); + __stop___jump_table, start, end, init); if (ret) return ret; -- 2.30.2