Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1860844rwb; Fri, 19 Aug 2022 10:35:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR6YJoQZn1Byaaq1x1snYfEME7V0J9QidUO6UqSHrhC816PC7imTROBfGr7KfQbZwL8Z7mD3 X-Received: by 2002:a65:4608:0:b0:41d:d4ea:4fc4 with SMTP id v8-20020a654608000000b0041dd4ea4fc4mr6973923pgq.186.1660930538142; Fri, 19 Aug 2022 10:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930538; cv=none; d=google.com; s=arc-20160816; b=oHaxUccNpNOitWrtg9rPrzyAnyEgZADX8RnKONgdGhq1CD3mdxSGLXuFM+5rV1bA5v 2E0bzH9VuybakXygFZWcIcmiPIlctAXzQ5QhM/OGjrgVabxLbM+lIbryDiYIA8a3o6mT rg8aKfiIzOCAEqEamxvHu501UauK4qJ4p9DTR6+7B3obuXdOSXA391tDvlGGVoGH/yRs z+jkHkXwMWnPhaT6Cg0xX4Rjq0a6oAHmpwBEavqVVMEfj9RbvwR3aHYLcCVmmX0Ad9yp c7kQuWiGmbCknlKmpgOIyGPDQSEx7+2ovw8eqSwbX0T5HHcW8Wj+cLq/T1P+q2Jwyi5X pOug== 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=cw2Hlm8BMDGIUsWa4j7k22lYVkWxH8UrgnmW9IFWG+I=; b=PdCQBv+Mj4Wsn6v6aFipPZGE8uQmHDk/etI0vJytP5wO6ZCAd4miE+ZGDXyYOT0Uq4 DFq0bkGK/kkxP3waEmH5tce3UliIXuAqTGPPWszb3Zr0vqj2M26rBHjjW2d6WSc/NsWB T2fqUu84wUj/O3QR7yYunWD8zW3TehPf9pD9NXjX2g1mLpTsQF0G3KJCwel3LqotY9vJ JK7HuJrdbliK4BGBEm3d+Zj2onMf7HngyCk8s2PReGEMOLyOp205u0OfHv7KX17Aof7z hvQTldv9RN5zUz0OZx7C7rYbskApnvMAJrkq/J+lUj1RyHdBUQafKPWEouS7tsVbVWoW pbvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J8mkCf4k; 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 v14-20020a17090a898e00b001f51ade030csi4529395pjn.162.2022.08.19.10.35.27; Fri, 19 Aug 2022 10:35:38 -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=J8mkCf4k; 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 S1353509AbiHSQiI (ORCPT + 99 others); Fri, 19 Aug 2022 12:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353403AbiHSQfm (ORCPT ); Fri, 19 Aug 2022 12:35:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09C0910445C; Fri, 19 Aug 2022 09:07:19 -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 ams.source.kernel.org (Postfix) with ESMTPS id BD16AB82812; Fri, 19 Aug 2022 16:07:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2399BC43470; Fri, 19 Aug 2022 16:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925227; bh=11/Dr3LRJ6C8AUMn8I/rOmXtkk74gmNURapeKT1lers=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J8mkCf4kWeuWttQCz9xs/6vKhwOOP4rWvAlW/KnLsBU693IMKyu6vhC7ppqVBt6qR 2rl3+/hI/wJqj5T5pwxrAA4tqEyuZLNc4R5boIr2T/1eDF+j7hN7MVZEXaYeiqZRTE nQa9ZVzYloerD3xm3ud+TJUnoRgVd/UHqzsRv+KY= 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.10 425/545] kprobes: Forbid probing on trampoline and BPF code areas Date: Fri, 19 Aug 2022 17:43:15 +0200 Message-Id: <20220819153848.437327403@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 cdea59acd66b..a397042e4660 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1640,7 +1640,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