Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3095071rwb; Mon, 15 Aug 2022 18:00:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR67B3hYfMtiBzoQWZd0sLBmhKUopp+CepHoQA33hMxN5GrNfp8S4JQ9l3GBObR7pdleHfTn X-Received: by 2002:a05:6402:3210:b0:43d:20bc:5e4 with SMTP id g16-20020a056402321000b0043d20bc05e4mr16366126eda.276.1660611639337; Mon, 15 Aug 2022 18:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611639; cv=none; d=google.com; s=arc-20160816; b=gPlfjq0nMxmJ/Y2GgXr6pz4K0QGkXcZuNPtDmx0ddLjbAt9/OOdVGgCefUVbkmAyPh RMFU8U93a1NMT3ZJ0Qkk1pn766+nLUESxNZ/Uc0JNBPfDXqElY8R6jviwDYBtyvD6mvw 97XjOt6xwLkQOABYYnnbvX2nCM2G3hJ/VTrHt8l8UiYKhYWQPOc0OksZU1bBbSqcTpFi SKLp/ImFG/U8uIyWARDXBdG6EvqmBnd/mypQL/lz8zom/1UVJDQNzZwPHm/Qos4Tza1d TB+9tGceC6UQNfPyNSNWHZ/awk+A14o5f8XFz0g7tTmmyyS4msd9pufXd4Qq8qSlM5eP Z9PQ== 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=gI8qH+b3ifqB9jg72TxvgI3VsDKSVWczOInu+NBsQpQ=; b=WXDXQb/MgiIwHeRzm7E83/bKxl7xZCPh+8/CQtw3pSzA1b1Mor1s1spB+gAWWWLN+o ym8cdT3INqOdJf9DMzMCjKVJUQj1fJyVozB8Fyjm7zf4K1iXK2YokExXe00RzMXmH4c5 qjyCF3iTI1AIuimOYHek+L13C0FbF9AkSociO5itx+y2WIm7HTeXwEbyd2oQYtBHNH8j cepn9XSx99VucokckUi5kR97bOPB2M1GnjtoV0v8BPZb0b/LvPQ6JFUMUvjD0KXbfaGG lcLF56/pHWZl7VH9AcdVFfT12kHK5Cilr5jfc6Enk/VoOCRuYpqVjRawySbqK9pXXXig w0jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l0kZzUKo; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne28-20020a1709077b9c00b0072b8009c081si9537683ejc.245.2022.08.15.18.00.08; Mon, 15 Aug 2022 18:00:39 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=l0kZzUKo; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240599AbiHPAzI (ORCPT + 99 others); Mon, 15 Aug 2022 20:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243787AbiHPAr2 (ORCPT ); Mon, 15 Aug 2022 20:47:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7305BD8E0F; Mon, 15 Aug 2022 13:45:37 -0700 (PDT) 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 D0CE56125F; Mon, 15 Aug 2022 20:45:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBA73C433D6; Mon, 15 Aug 2022 20:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596336; bh=6rswtPHCBmofH9wCL2FhhYPwRwY21gb1uDolVJabZu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l0kZzUKovgTjiPV33wEqHNRupVFxfFugZoeRp49t7Y3zsyr0Q1sVsirtJK+F7+EiW 4Yrb7sZrLPj1w/22LliZ6yWWECFNVd98s/Q+E/5eiywptaK58+QEZ3v5LeF/xrU9J/ DNre+W2P3BhEGHJlHM/19BOYTBi3OLQlE4GdEC58= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen Zhongjin , Ingo Molnar , "Masami Hiramatsu (Google)" , Sasha Levin Subject: [PATCH 5.19 1014/1157] kprobes: Forbid probing on trampoline and BPF code areas Date: Mon, 15 Aug 2022 20:06:10 +0200 Message-Id: <20220815180520.430074264@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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,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 From: Chen Zhongjin [ Upstream commit 28f6c37a2910f565b4f5960df52b2eccae28c891 ] kernel_text_address() treats ftrace_trampoline, kprobe_insn_slot and bpf_text_address as valid kprobe addresses - which is not ideal. These text areas are removable and changeable without any notification to kprobes, and probing on them can trigger unexpected behavior: https://lkml.org/lkml/2022/7/26/1148 Considering that jump_label and static_call text are already forbiden to probe, kernel_text_address() should be replaced with core_kernel_text() and is_module_text_address() to check other text areas which are unsafe to kprobe. [ mingo: Rewrote the changelog. ] Fixes: 5b485629ba0d ("kprobes, extable: Identify kprobes trampolines as kernel text area") Fixes: 74451e66d516 ("bpf: make jited programs visible in traces") Signed-off-by: Chen Zhongjin Signed-off-by: Ingo Molnar Acked-by: Masami Hiramatsu (Google) Link: https://lore.kernel.org/r/20220801033719.228248-1-chenzhongjin@huawei.com Signed-off-by: Sasha Levin --- kernel/kprobes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index f214f8c088ed..80697e5e03e4 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1560,7 +1560,8 @@ static int check_kprobe_address_safe(struct kprobe *p, preempt_disable(); /* Ensure it is not in reserved area nor out of text */ - if (!kernel_text_address((unsigned long) p->addr) || + if (!(core_kernel_text((unsigned long) p->addr) || + is_module_text_address((unsigned long) p->addr)) || within_kprobe_blacklist((unsigned long) p->addr) || jump_label_text_reserved(p->addr, p->addr) || static_call_text_reserved(p->addr, p->addr) || -- 2.35.1