Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp953543pxb; Thu, 28 Jan 2021 04:45:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdgFy+6PF6vRiHPtXWCzHnRFTCHxgP636wbZVqpyEm/XY5nqazbgsanjnRWJJdx+fORdtV X-Received: by 2002:a50:fd83:: with SMTP id o3mr13612805edt.359.1611837937856; Thu, 28 Jan 2021 04:45:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611837937; cv=none; d=google.com; s=arc-20160816; b=Z6KvU5hHJELy0uzf3WhuLtdJZzgo6HPyHv3GTh19oKdWklC5Wo1qt0QritXmLbpdmU yncggeWFov6yQI1Y5YcRssaRdxN1CEriXeDP1T0lJ84XP8bbr1hfzK7w5zniQKHaq2TA T38zSUHagUR664C6CnRNGIozahnQAZSojOo37ci+uK5q2uMNVOPSUac38D+SzczQJaQv xP1GgZflQWH4BplWroyw7p929DjWWE/x0i/uTXNzC0XNtGZpXf19xZy2WRmXnFgYMflf RFE+Fqf/lBn2Cs+al3g7+Otz1vtRO6wGOdrAss6VbfuYoLoppH2pujUbgh6wI4iwm6/0 gg4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from; bh=m5dG+icMGPbkpoy4CwRuvBuMz5++uogMHt3pKT3+9co=; b=YcHVyEMIdgjBrdhr2iGIo5CufuB6+RzWRxPplqb9SicQ84foz60rGCGTQ2gaIAcaUc EJmCv4Wg6V+njgLfMbn8dKA5J2OlaGDP+shT4m/DptaPKc+/1MPWE/iNDqsS41OVPTN0 I/4VIoiVgM8a5F28eWQzSk2C6eevV/b2IESoy4xfJiLW2os+a9gqZJ20fCdt7PtNqEjx 2BS677FexjQ99m4VgiUP+HVf4mdWBNb/mE6Zi/u08szduMMUz+CCCAQOw1wKMJMiq2pi gfzn4ej/+JSnuxYFYiFqnEFVdEYBxnmofnv/gQmxOMXJHmkzXFLOqP3vLWcPJV9jLwon mayQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zo20si2463092ejb.302.2021.01.28.04.45.13; Thu, 28 Jan 2021 04:45:37 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbhA1MnP (ORCPT + 99 others); Thu, 28 Jan 2021 07:43:15 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11614 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbhA1MnO (ORCPT ); Thu, 28 Jan 2021 07:43:14 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DRKpK2bSCz160Fl; Thu, 28 Jan 2021 20:41:13 +0800 (CST) Received: from huawei.com (10.175.103.91) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Thu, 28 Jan 2021 20:42:16 +0800 From: Wang ShaoBo CC: , , , , , , , , Subject: [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier Date: Thu, 28 Jan 2021 20:44:27 +0800 Message-ID: <20210128124427.2031088-1-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-CFilter-Loop: Reflected To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Our system encountered a re-init error when re-registering same kretprobe, where the kretprobe_instance in rp->free_instances is illegally accessed after re-init. Implementation to avoid re-registration has been introduced for kprobe before, but lags for register_kretprobe(). We must check if kprobe has been re-registered before re-initializing kretprobe, otherwise it will destroy the data struct of kretprobe registered, which can lead to memory leak, system crash, also some unexpected behaviors. We use check_kprobe_rereg() to check if kprobe has been re-registered before running register_kretprobe()'s body, for giving a warning message and terminate registration process. Signed-off-by: Wang ShaoBo Signed-off-by: Cheng Jian --- kernel/kprobes.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index f7fb5d135930..5c4a884953e9 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1978,6 +1978,10 @@ int register_kretprobe(struct kretprobe *rp) if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset)) return -EINVAL; + /* If only rp->kp.addr is specified, check reregistering kprobes */ + if (rp->kp.addr && check_kprobe_rereg(&rp->kp)) + return -EINVAL; + if (kretprobe_blacklist_size) { addr = kprobe_addr(&rp->kp); if (IS_ERR(addr)) -- 2.25.1