Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4097628pxb; Mon, 8 Feb 2021 07:54:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+iWX3NEx+odYPSJuSNpies2n52mQsn3cghWDAXsR+r/JvkchjNSSisrEFxRkt68+XlUF+ X-Received: by 2002:a50:a6ce:: with SMTP id f14mr17612527edc.346.1612799684615; Mon, 08 Feb 2021 07:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612799684; cv=none; d=google.com; s=arc-20160816; b=jfGEb47hBVkzra2gzYXHUrybn9WHEcVYrps4ThIkCTIjxjnAdntDsTocvC+tX5cjtq NQHZgZKSUCtjbIUXB1AVYCiSTAnGmW2YbTpAAuXYdrxtwNBu+dnp4cBPxsVYZ4r4SAdu yqP/q17SlHKvRp8aVNCgIuwmx+7Vhl8kz+q6nvB+LoC1hA5CCX2PYikrgO5R4T95G1kI UoV3BofePzyZDPFWyHDkluAral48+GbFaaJ8T7P1MOX0YwqgRX6NpB8Lh+qL+UYwlzsC 3fgTXp/Ee5olQmEp/A7VGOEUOiOoAm7vZaO6U4uzWHxX2hr9Ml8fekb4X1JsqXkGAMR3 8y7g== 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=X1dAifVIXAPLvlS6O4qIo/+xeyJ+widfZ6qE8VNivO8=; b=Itxwyhx2WeXoTsuk0XLQNYny6oZt8/G/7WhGU7y1GEcL9/QaFU4T9YjDoyzEYzSd4s dgtsWLu+CXl12Zbc+p/xfLSnRgxs8XPKtDxuXjUwSxePnOE5zcnVpPpg106pdIXIYAAQ xRX2VkuN47Q+kM08baUWUwwnBtW5dizCbfkFeS2ZgecVheLpjHUhyoW1NTh/k3ySOacZ PzhkoxJXaMeB/ydaGfH9Wsjdzyh+W9V5lqYVvQyzy5RhqWKKdu5y8syBIuiMNsXeHkJB tVwrd8S8CS5TQzbjswJB4GXPOyJLDP4W7ZPBEUTjl/7KwoxCyxeXQc7MQCFRQshUBSDT dhvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nNOr3o9U; 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 jg13si14024128ejc.669.2021.02.08.07.54.20; Mon, 08 Feb 2021 07:54:44 -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=nNOr3o9U; 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 S232375AbhBHPvi (ORCPT + 99 others); Mon, 8 Feb 2021 10:51:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:52060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230231AbhBHPHP (ORCPT ); Mon, 8 Feb 2021 10:07:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD72264EC3; Mon, 8 Feb 2021 15:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612796743; bh=XNB5Kb6a/T3bRSttZEMsuYhm1giFt/X4+p086CTSXrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nNOr3o9UP05S8ifZZ7nEee7x/kmAD1bbC3tmI9NFncHnDyvUQF2ub0F0pjpcmy2ob 9pnFXJwyWsAoZ+ZM7ul7BPkunbXLpzqNzCz41rZdyhniu2VBKPKS8KuQvqIWZFLgsy CFk+ma5xp1aJBlmD+TePdvK4fQnT16j0SfGL/QCE= 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 4.9 29/43] kretprobe: Avoid re-registration of the same kretprobe earlier Date: Mon, 8 Feb 2021 16:00:55 +0100 Message-Id: <20210208145807.486860064@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145806.281758651@linuxfoundation.org> References: <20210208145806.281758651@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 @@ -1884,6 +1884,10 @@ int register_kretprobe(struct kretprobe int i; void *addr; + /* 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))