Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1977917pxu; Tue, 24 Nov 2020 13:42:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5Lhacud2LVHYMBY95U3UMxmGGciJ2ZuZ+krGVQobvgXKfbVB4Laqj1eInguiiFc2DKcU0 X-Received: by 2002:a17:906:5945:: with SMTP id g5mr361905ejr.553.1606254127375; Tue, 24 Nov 2020 13:42:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606254127; cv=none; d=google.com; s=arc-20160816; b=gzjgwt+t1lKvGVPzungXinOoKTcLQ0FzuET5AlnfvFOrW/eQzuDOODLLgBPJeFzQSH nB+Exe/iR+awBUWVLnCcHpOraaLvm7NZlzcVG7QTXyjT0sJK1w3mpSTgaO0ppLs9pRkY kUTVsSsFaWgCLe1ofPWQ86cVcg6KVwQZamL1J8spDQVyvbaz7d1W2iryWM7xa6cbbilr p7+IhAvXlgOuB4CJ74eLCJJII0AfpUQIkuc2kLxeG+AAxn5jrMz3WcBQo7BZ6Aohj0Zu CSybfS1VT1AW3SUO2HyKoQMa3iS3yW8kj2aEZCweGW91/ziQxHO5+iGM19m3kXZB5JXP yteg== 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=ntnvjA81CYOnldssSXse4E6/KecYzdv+u8rHeVLKLmA=; b=j3bSB5hqwASyvl7N4b76La+AmcOqmkxMpWY2eqXXud6IsZkzk0cF+0QRTuO0rtwjw0 bbQrh4eOM72R1imRcnKEjzKvPM58pJ+U3NOJG4Uep3MmZFduBlYG9a3EcZ068c0rGbIh pMhuF9c154AHcBu/hqYR5EBJ5M9CX3LBSlDZpgs1bbGRkoJVHayQ5KxVF1TquPgoSFBW JHjBkU+PRubuee/0srdrAmPUcBZxXTu8rWZpDMpTETfu30ejmhGJq54auEqp6RaOJSTr FQgwsuu+vY/Zp6CnItG8zO+SNK9SmgpX8sy+78umPxsci3hJwp7I3w8l6IPaW0qqBnkQ smQQ== 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 pg1si87874ejb.96.2020.11.24.13.41.43; Tue, 24 Nov 2020 13:42:07 -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 S1733175AbgKXL5e (ORCPT + 99 others); Tue, 24 Nov 2020 06:57:34 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8398 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732852AbgKXL5e (ORCPT ); Tue, 24 Nov 2020 06:57:34 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CgMvV6254z71pC; Tue, 24 Nov 2020 19:57:10 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 24 Nov 2020 19:57:23 +0800 From: Wang ShaoBo To: CC: , , , , , Subject: [PATCH] kretprobe: avoid re-registration of the same kretprobe earlier Date: Tue, 24 Nov 2020 19:57:19 +0800 Message-ID: <20201124115719.11799-1-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected 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 calling register_kretprobe(), for giving a warning message and terminate registration process. Signed-off-by: Wang ShaoBo Signed-off-by: Cheng Jian --- kernel/kprobes.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 41fdbb7953c6..7f54a70136f3 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2117,6 +2117,14 @@ int register_kretprobe(struct kretprobe *rp) } } + /* + * Return error if it's being re-registered, + * also give a warning message to the developer. + */ + ret = check_kprobe_rereg(&rp->kp); + if (WARN_ON(ret)) + return ret; + rp->kp.pre_handler = pre_handler_kretprobe; rp->kp.post_handler = NULL; rp->kp.fault_handler = NULL; -- 2.17.1