Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6634904ybf; Fri, 6 Mar 2020 01:28:34 -0800 (PST) X-Google-Smtp-Source: ADFU+vtoP2A+lIKAem3cX7bOB+6hCa4jQN+fb3WqY27fY/DXNFCFDjgVt9S/zsd+arLYyOVOusJS X-Received: by 2002:a9d:4787:: with SMTP id b7mr1750124otf.323.1583486914369; Fri, 06 Mar 2020 01:28:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583486914; cv=none; d=google.com; s=arc-20160816; b=Ju2KAbSgXANCrFFjdJwQUEATaJCvJzRNKG7FssPvFkyge3LClfflOPGYbPjaKHuPOG 6CZJvDPsueKUeFaXewigG/Wt1COhLz8+jSILqwwk2sGsaYVEFj+DrsLS8OU7WWTYY9fY m09lFCdEHpJYN2+/W1ynNlwxDr1nqpODwehPNdFeqkamDJ849DXgjjxE8IXtLV5LHQ2y KndFeTWlf2ih6RLwZHm81b1jMcPV+bhJVyVSIo2schX9mRWE83Iv6ZZo7FiAqJovLuTP fetHgLm/6LIpdfq+b45sKNTNf61cDbCUMKqVe8rXsgHNS/xH5ppcIscN/GGlLsujEvNV awsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=5aFiGpqTgTs2AmQ7zuIuIUi70+ZioygP1tPKdR15P24=; b=lmR8iTXmc7AFxq/Sf//bddG9qqG5ok+prrBxPgaRg+GATSPIi/wb0vNJK1791GQYVl hY14l1rr4/BxCq7NIPllIIjYdrhx2xKHejMEqY0kRea/3yDeDU/pa9JL+6Y5LzNMtToh wazjmqi0jJcAJInmxby+U11q3SJazaAfBSJutY8dvwbMoL7lKQXi7rTZUiP1Ja0rfn6r sM11YaX/0XhP3xZsq38Y7sLhtHS6G95X+Z8NNyDuiU/185pRaNJvBeh6h154YNoOaMGx UJfGPzASNBw5kdPy+kBHjJHPXdbkEcc3drsf4igZWCPafAiKEy7n0DxKyA1qUjl1n0AM o1yw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3si1056143otn.286.2020.03.06.01.28.22; Fri, 06 Mar 2020 01:28:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbgCFJ2B (ORCPT + 99 others); Fri, 6 Mar 2020 04:28:01 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:34148 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726054AbgCFJ2B (ORCPT ); Fri, 6 Mar 2020 04:28:01 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 531A4C252A699F9FD0B1; Fri, 6 Mar 2020 17:27:58 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Fri, 6 Mar 2020 17:27:52 +0800 From: Cheng Jian To: CC: , , , , , , , Subject: [PATCH] kretprobe: check re-registration of the same kretprobe earlier Date: Fri, 6 Mar 2020 17:35:06 +0800 Message-ID: <1583487306-81985-1-git-send-email-cj.chengjian@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Our system encountered a use-after-free when re-register a same kretprobe. it access the hlist node in rp->free_instances which has been released already. Prevent re-registration has been implemented for kprobe before, but it's too late for kretprobe. We must check the re-registration before re-initializing the kretprobe, otherwise it will destroy the data and struct of the kretprobe registered, it can lead to memory leak and use-after-free. Signed-off-by: Cheng Jian --- kernel/kprobes.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2625c24..f1fc921 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1946,6 +1946,11 @@ int register_kretprobe(struct kretprobe *rp) } } + /* Return error if it's being re-registered */ + ret = check_kprobe_rereg(&rp->kp); + if (ret) + return ret; + rp->kp.pre_handler = pre_handler_kretprobe; rp->kp.post_handler = NULL; rp->kp.fault_handler = NULL; -- 2.7.4