Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4131170pxb; Mon, 8 Feb 2021 08:38:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJydGtX8lN3YbsY25w+LxT7t7w22A2xpxy2Jjs/kObYsl3cp5yJSdW22RgoSYKgiBUQsdsdp X-Received: by 2002:aa7:da17:: with SMTP id r23mr17442415eds.176.1612802326396; Mon, 08 Feb 2021 08:38:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612802326; cv=none; d=google.com; s=arc-20160816; b=dROw7WX/Y5AeBBs9Lq4JT1qmec58YM6biFYNxlrgK8hggWJB1uKpIwZs+keYtHhxvK DnnYV4pOfwU3MlSn9b6wPqM6kWENl/QjRcxcDbOv/xORdbDaTiPHuMfnN6YODP8n322t aHxcL7IBCj6i2KsM/EkesStIpMdszfqtt+SRyx/LgVnXx5jMQTEDmPAI02cS3uvY7YHy 7ltxnHA/c5LYHEoiSvEB1v+ZmlUAjwzNHN0Ruz4v2iLK2/LAVpVVVNjQHl3B/f57qJpK cr1gGp0Cs36fnHVV1mttqzTQKqP+wYN6Rf0ZKhRQjR4bt6fVJPd8bCmhVaf4Fq2MmfuW prJA== 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=FdA3ettdyQOoksqgmABhTtNZKgU1OVAkTOZbPQ4iwVw=; b=DCebegakffKN0vDz9HdO3HuAeBPbF3OIFqHma//oOTDskvR5vhcGj4rMueaKEIi/nC 8eOSZ0/9DutkCnfbnZey1cS2cQIly89Nu2mxXPsMbC+DhlyVgr4nuaAzqeQVq1tydDio SLrN8OD9vfA5NITzVBV8ll+hDDC370O1fmB+bbtviMvT4Y3ndtZ+EUxmUrLJa17Ry6ZJ ZABZrCnmp5tWXkvnukEC+x3Vtp48/hVkcQIA1/EIpWlssjMP6sAH/y5IY8u5QjRTgrNC gEHPE1HgNufGWMK43fnZVwsvc3WK8be5btTuTo0Ix60HOwtE/jOTAFPaJtm+ex/ztJ2b 5QEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zE3MvhMk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h28si1418390edj.387.2021.02.08.08.38.21; Mon, 08 Feb 2021 08:38:46 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zE3MvhMk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233358AbhBHQfQ (ORCPT + 99 others); Mon, 8 Feb 2021 11:35:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:55768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbhBHPNc (ORCPT ); Mon, 8 Feb 2021 10:13:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 451C364F01; Mon, 8 Feb 2021 15:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797032; bh=80tyYNlDjC90V3c8qAt5dQpDytLTUxx5VjyXJpQMuwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zE3MvhMkiiKjvibvh9tk0xU8/d17HWH2UlEQ9jLqiKMfZsTqmvWZFkkd5EnMueWmX 8Y35vXH32rzEv3a2A9AaB4aKo5uW7MloEF956RSIv+kGqcYEthtN9mCU1zZn+vmmUp OPvB5zD9cd/pbDtExFOCwN0hyzC/FRXBaFaVR+oE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Naveen N. Rao" , Ananth N Mavinakayanahalli , Masami Hiramatsu , Wang ShaoBo , Cheng Jian , "Steven Rostedt (VMware)" Subject: [PATCH 5.4 35/65] kretprobe: Avoid re-registration of the same kretprobe earlier Date: Mon, 8 Feb 2021 16:01:07 +0100 Message-Id: <20210208145811.587231720@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145810.230485165@linuxfoundation.org> References: <20210208145810.230485165@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang ShaoBo commit 0188b87899ffc4a1d36a0badbe77d56c92fd91dc upstream. 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. Link: https://lkml.kernel.org/r/20210128124427.2031088-1-bobo.shaobowang@huawei.com Cc: stable@vger.kernel.org Fixes: 1f0ab40976460 ("kprobes: Prevent re-registration of the same kprobe") [ The above commit should have been done for kretprobes too ] Acked-by: Naveen N. Rao Acked-by: Ananth N Mavinakayanahalli Acked-by: Masami Hiramatsu Signed-off-by: Wang ShaoBo Signed-off-by: Cheng Jian Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/kprobes.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1972,6 +1972,10 @@ int register_kretprobe(struct kretprobe 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))