Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3072877imu; Mon, 19 Nov 2018 10:12:25 -0800 (PST) X-Google-Smtp-Source: AJdET5c6SXy48A5TN5XYyAtql9B/Z5FDnl8uS03ldiOYzkARGDh4EsR522iEb1RHHWApeyAoFS0v X-Received: by 2002:a63:4e15:: with SMTP id c21mr21110620pgb.50.1542651145759; Mon, 19 Nov 2018 10:12:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542651145; cv=none; d=google.com; s=arc-20160816; b=a443txRKUXoF/JZ0swISiYeJo/hwXpkz1X/vjFuGT1IsBxifV2oxZTDUZhtWA0z2pg +vjsHd+VSiN1H3NrYg31xOBToJVJ13fgm/pz/v79Ma1d8LckQca8bWSgS3ewzj+WLRDO vcvAtBhikAXB25OU+8wfe/0PUAjVk/p745CoBQSZzCshe6P/jKIVERz4CKitEeY4Xom1 Q1itsRLMo/KBp8nd4e8nIyiXP3gfw6k7XAnMmTk99Hf3H08lXWbqmLKA6j58DXsB16hy JGHjnMGG63C4w+IXCfyqV4qJVwQOunrcAek1EEdtYkmiIPgSRbwHBrndWgQjTAej4z4X yeVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=V4nn47h01bpXWd6RfZ58C2laxiQmDulJ1t/2cErPv5Q=; b=UlGex/7bnITO6dg/1metCX/W/KFuBVQauMG1Ds9Ykjz7sofEKeoeyo4bhPKx/jJtko hJp35lEEE7JvrW2T2soyiMBtxFHIX7GXtFWYRL0wNA+EuQTs5/1dE8xl9aWKfL3dBumV kpj9/dahvRlhDYG0vMHBsivZXVuvrZ7b81lEbIzcteHMmBd5p2yBtcQl3AWUsnKbDVlr rKTGlZCJULT4rKfK83PdySPRHma1lO2w8xZia3EoCYzS3B7RFzyBTxMKGgCVn2JHm13L RjQ8DTCJ7+MReO209QYK6E4GHAm7N2KZMxZ5Mk9YTBBWgAkSXZvffHVLFMZUXabVdIwp SVaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JyYS5fmH; 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 d10si3349684pgf.136.2018.11.19.10.12.10; Mon, 19 Nov 2018 10:12:25 -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; dkim=pass header.i=@kernel.org header.s=default header.b=JyYS5fmH; 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 S1730093AbeKTCyk (ORCPT + 99 others); Mon, 19 Nov 2018 21:54:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:51966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730077AbeKTCyj (ORCPT ); Mon, 19 Nov 2018 21:54:39 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1340C2086A; Mon, 19 Nov 2018 16:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645031; bh=ckSfL6OmKAx5M/zisx4+j/7yivub1+kQwi66RkRrDCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JyYS5fmHlClgfCwdP72eVaagr+y/BuoD7ikOhnhxOF4rhnbtB3q5FGxid38WHTnBh 4z5Ltd1wcQQitS718bVc0zaK6EPQNH1nTNYvdnGVDPtzcM9DtEx1l9kivfkUYMV0V+ RA8EWKVX+uA4Sk69BDt1jYWw2pVB2fTXOsFvSUms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , "Steven Rostedt (VMware)" , Sasha Levin Subject: [PATCH 4.19 010/205] tracing/kprobes: Check the probe on unloaded module correctly Date: Mon, 19 Nov 2018 17:25:17 +0100 Message-Id: <20181119162618.950742558@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu [ Upstream commit 59158ec4aef7d44be51a6f3e7e17fc64c32604eb ] Current kprobe event doesn't checks correctly whether the given event is on unloaded module or not. It just checks the event has ":" in the name. That is not enough because if we define a probe on non-exist symbol on loaded module, it allows to define that (with warning message) To ensure it correctly, this searches the module name on loaded module list and only if there is not, it allows to define it. (this event will be available when the target module is loaded) Link: http://lkml.kernel.org/r/153547309528.26502.8300278470528281328.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_kprobe.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -61,9 +61,23 @@ static nokprobe_inline bool trace_kprobe return strncmp(mod->name, name, len) == 0 && name[len] == ':'; } -static nokprobe_inline bool trace_kprobe_is_on_module(struct trace_kprobe *tk) +static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) { - return !!strchr(trace_kprobe_symbol(tk), ':'); + char *p; + bool ret; + + if (!tk->symbol) + return false; + p = strchr(tk->symbol, ':'); + if (!p) + return true; + *p = '\0'; + mutex_lock(&module_mutex); + ret = !!find_module(tk->symbol); + mutex_unlock(&module_mutex); + *p = ':'; + + return ret; } static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk) @@ -554,19 +568,13 @@ static int __register_trace_kprobe(struc else ret = register_kprobe(&tk->rp.kp); - if (ret == 0) + if (ret == 0) { tk->tp.flags |= TP_FLAG_REGISTERED; - else { - if (ret == -ENOENT && trace_kprobe_is_on_module(tk)) { - pr_warn("This probe might be able to register after target module is loaded. Continue.\n"); - ret = 0; - } else if (ret == -EILSEQ) { - pr_warn("Probing address(0x%p) is not an instruction boundary.\n", - tk->rp.kp.addr); - ret = -EINVAL; - } + } else if (ret == -EILSEQ) { + pr_warn("Probing address(0x%p) is not an instruction boundary.\n", + tk->rp.kp.addr); + ret = -EINVAL; } - return ret; } @@ -629,6 +637,11 @@ static int register_trace_kprobe(struct /* Register k*probe */ ret = __register_trace_kprobe(tk); + if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) { + pr_warn("This probe might be able to register after target module is loaded. Continue.\n"); + ret = 0; + } + if (ret < 0) unregister_kprobe_event(tk); else