From patchwork Sat Nov 26 11:43:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Huafei X-Patchwork-Id: 26214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4587352wrr; Sat, 26 Nov 2022 03:48:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6YtMUSIw8pfg7GuRde+gWSiPw7r4FELh7I9Wxbj6TTyW0KLYmKCYemFmhZVFDYeXWTvBJa X-Received: by 2002:a63:2306:0:b0:46f:918e:7339 with SMTP id j6-20020a632306000000b0046f918e7339mr19248380pgj.429.1669463283567; Sat, 26 Nov 2022 03:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669463283; cv=none; d=google.com; s=arc-20160816; b=wV6G0kvMMJ2pYLyMU+1Gp7A1S3K/Ml16kSzCU2dra8R4DVLlnfHYnyey5L9L9yZD+W xtOvo2c1+uE+PwIr1vbeND995lSbPNUOGWh+wnrNdNu0ZA7obrTgFpQGt/8BZtyxaIdy EEMU5l+LYNCnfP6MxHGY3ogfwkTaxm3Zp5Z0ihLGbf8o7Fy22KbRXdXl1ZXLN5UnzT2X oEuNAma6/CroXW1nUyzy1BDi1RawJOrdXJ9yPqNzZQp8vDb3A/hnP3EiS1KBESNEpTHX 0rORy2ImxJ8hb6PMVI1ZMo3qUE8SKc6y52+R3rlQZAWDL/8entSlX5qlD7zpJsZD3KVQ OZfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=bjZEy/fv/mHgh5Q5jAvYg55bMEPTaAYAHvkQqXuo77Y=; b=pgAe1yC/jTVDVlSQFAL4AhmaIMMoqxb4vHMgU9cf0iZptbfzBS5yM4Xn+sICBGjkz9 JvX6gg+7KSqKD9/2aFcbTKxib78gox9EGt5wAAzqFgFPxjOhqd2HIhA3yghyHl07uV0x nGZY/03ZV9Pq3nQObUdN3g0RQJ8wqkIEbTkIgnnkIlvekz+fpCdobw2KGWRAcUYpR+7x NIGvPi5KkCxCMghB3F7vvQlDgb/3m0fGH0fuEYALwq2s844gJJRGc9mQYOh8r6XdHIBa MQ88WSv44rMaeNqenqJdyrZlYSKkaPq9BZeksvORgiAKw/A2bqsppZyRVy1cZ1YaeueZ vWmA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 199-20020a6302d0000000b0047787372364si7500420pgc.363.2022.11.26.03.47.50; Sat, 26 Nov 2022 03:48:03 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbiKZLqX (ORCPT + 99 others); Sat, 26 Nov 2022 06:46:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiKZLqU (ORCPT ); Sat, 26 Nov 2022 06:46:20 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7932E1FCDB for ; Sat, 26 Nov 2022 03:46:19 -0800 (PST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NK8xG36J7zJnt8; Sat, 26 Nov 2022 19:42:58 +0800 (CST) Received: from kwepemm600010.china.huawei.com (7.193.23.86) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 26 Nov 2022 19:46:17 +0800 Received: from ubuntu1804.huawei.com (10.67.174.174) by kwepemm600010.china.huawei.com (7.193.23.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 26 Nov 2022 19:46:17 +0800 From: Li Huafei To: CC: , , , , Subject: [PATCH] kprobes: Fix check for probe enabled in kill_kprobe() Date: Sat, 26 Nov 2022 19:43:16 +0800 Message-ID: <20221126114316.201857-1-lihuafei1@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.174] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600010.china.huawei.com (7.193.23.86) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750559131791288964?= X-GMAIL-MSGID: =?utf-8?q?1750559131791288964?= In kill_kprobe(), the check whether disarm_kprobe_ftrace() needs to be called always fails. This is because before that we set the KPROBE_FLAG_GONE flag for kprobe so that "!kprobe_disabled(p)" is always false. The disarm_kprobe_ftrace() call introduced by commit: 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler") to fix the NULL pointer reference problem. When the probe is enabled, if we do not disarm it, this problem still exists. Fix it by putting the probe enabled check before setting the KPROBE_FLAG_GONE flag. Fixes: 3031313eb3d54 ("kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()") Signed-off-by: Li Huafei Acked-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/kprobes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 3050631e528d..a35074f0daa1 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2364,6 +2364,14 @@ static void kill_kprobe(struct kprobe *p) lockdep_assert_held(&kprobe_mutex); + /* + * The module is going away. We should disarm the kprobe which + * is using ftrace, because ftrace framework is still available at + * 'MODULE_STATE_GOING' notification. + */ + if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed) + disarm_kprobe_ftrace(p); + p->flags |= KPROBE_FLAG_GONE; if (kprobe_aggrprobe(p)) { /* @@ -2380,14 +2388,6 @@ static void kill_kprobe(struct kprobe *p) * the original probed function (which will be freed soon) any more. */ arch_remove_kprobe(p); - - /* - * The module is going away. We should disarm the kprobe which - * is using ftrace, because ftrace framework is still available at - * 'MODULE_STATE_GOING' notification. - */ - if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed) - disarm_kprobe_ftrace(p); } /* Disable one kprobe */