Received: by 10.213.65.68 with SMTP id h4csp332661imn; Sat, 17 Mar 2018 05:40:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELsl+V1xO34RtkYkE8AgW+vHCriaDHV5xT/sLJ01IaCcZnGo50lDY/cGl/kqVyYJOCGpvh+l X-Received: by 10.101.82.69 with SMTP id q5mr4237819pgp.259.1521290412334; Sat, 17 Mar 2018 05:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521290412; cv=none; d=google.com; s=arc-20160816; b=FFDagszaZiPRIrcH116SYQKSsGO0aVUFhxiVILJDS2vIqBrcbfdPedTH2/vdKwRZZc UyhFnvOm6/7hcZ4rl6sQncvYhs3xPquCOkqFFNEcZh6tQiuRhbdw05yyCAT6DzZGyp9j 6FBvITzFOHa5llnFbgohUxQKcevhNp5toTPMur6M5MUji5YevaZQ94Zvr6FVaTe3TjS1 97mgJXjQq1q6Oyl3CT2Ko1hzcLgASGt9Cj45EJYds53SMa2wDy6ztmPSMXeInhrwugKx bORE1oXMBVBoUpKDrlWUxSQWUS1G+Hd/Ybm/zK5hxjDSI0ByosUvwWg3ufo/gh8rzSq8 gvHQ== 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:dmarc-filter:arc-authentication-results; bh=YRP/Gq0Umr/XhvjQtL8wEGS5Ghd+sfMxectkBVoP3fU=; b=nHNU9DNFbRwFcMsu0QVJH/jzJttZUVUfymzN83MSUv2BqvATlQFFzwtaCqFsH55fQd EG+bs0pfonm4+jHq0lOvxdEGKe7VMJ6PCC4li1GBk4s+qDuCWA3FCJb00O2HCufAhxMQ TLO8TTHN5/EEsTakIlLX/aad9Iov77nCNwQPtsk1qbbN3z+KPWLwFyOW1286Fj6boJMk rULkzX2DB3DC08uQXQuUTaTwlInFS6rQwpPUK00wi/O0wvleLQtUaPxB4t2jxW/CC4Kc BKCfTPGU26sSkGNjwWI/uXN9CLg+6TNA2WNrzh/5Dt8Ei6aSaJJ4XLl0Jnzk0Do/UTsz 2u7w== ARC-Authentication-Results: i=1; mx.google.com; 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 z8-v6si8045716plh.379.2018.03.17.05.39.58; Sat, 17 Mar 2018 05:40:12 -0700 (PDT) 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; 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 S1752790AbeCQMi5 (ORCPT + 99 others); Sat, 17 Mar 2018 08:38:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:50036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752191AbeCQMi4 (ORCPT ); Sat, 17 Mar 2018 08:38:56 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 D6F2421748; Sat, 17 Mar 2018 12:38:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6F2421748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mhiramat@kernel.org From: Masami Hiramatsu To: Steven Rostedt , linux-kernel@vger.kernel.org Cc: mhiramat@kernel.org, Ingo Molnar , Namhyung Kim , Tom Zanussi , Arnaldo Carvalho de Melo , linux-trace-users@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org, Ravi Bangoria Subject: [PATCH v6 01/21] [BUGFIX] tracing: probeevent: Fix to support minus offset from symbol Date: Sat, 17 Mar 2018 21:38:10 +0900 Message-Id: <152129028983.31874.13419301530285775521.stgit@devbox> X-Mailer: git-send-email 2.13.6 In-Reply-To: <152129024033.31874.15800253385376959274.stgit@devbox> References: <152129024033.31874.15800253385376959274.stgit@devbox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In Documentation/trace/kprobetrace.txt, it says @SYM[+|-offs] : Fetch memory at SYM +|- offs (SYM should be a data symbol) However, the parser doesn't parse minus offset correctly, since commit 2fba0c8867af ("tracing/kprobes: Fix probe offset to be unsigned") drops minus ("-") offset support for kprobe probe address usage. This fixes the traceprobe_split_symbol_offset() to parse minus offset again with checking the offset range, and add a minus offset check in kprobe probe address usage. Fixes: 2fba0c8867af ("tracing/kprobes: Fix probe offset to be unsigned") Signed-off-by: Masami Hiramatsu Acked-by: Namhyung Kim --- Changes in v3: - Use kstrtol instead of kstrtoul. (Thanks Namhyung!) Changes in v4: - Fix to decode sign. (Thanks Namhyung!) - Fix to check UINT_MAX for kprobe offset. --- kernel/trace/trace_kprobe.c | 4 ++-- kernel/trace/trace_probe.c | 8 +++----- kernel/trace/trace_probe.h | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 5ce9b8cf7be3..1cd3fb4d70f8 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -667,7 +667,7 @@ static int create_trace_kprobe(int argc, char **argv) char *symbol = NULL, *event = NULL, *group = NULL; int maxactive = 0; char *arg; - unsigned long offset = 0; + long offset = 0; void *addr = NULL; char buf[MAX_EVENT_NAME_LEN]; @@ -755,7 +755,7 @@ static int create_trace_kprobe(int argc, char **argv) symbol = argv[1]; /* TODO: support .init module functions */ ret = traceprobe_split_symbol_offset(symbol, &offset); - if (ret) { + if (ret || offset < 0 || offset > UINT_MAX) { pr_info("Failed to parse either an address or a symbol.\n"); return ret; } diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index d59357308677..daf54bda4dc8 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -320,7 +320,7 @@ static fetch_func_t get_fetch_size_function(const struct fetch_type *type, } /* Split symbol and offset. */ -int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset) +int traceprobe_split_symbol_offset(char *symbol, long *offset) { char *tmp; int ret; @@ -328,13 +328,11 @@ int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset) if (!offset) return -EINVAL; - tmp = strchr(symbol, '+'); + tmp = strpbrk(symbol, "+-"); if (tmp) { - /* skip sign because kstrtoul doesn't accept '+' */ - ret = kstrtoul(tmp + 1, 0, offset); + ret = kstrtol(tmp, 0, offset); if (ret) return ret; - *tmp = '\0'; } else *offset = 0; diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index 0745f895f780..75daff22ccea 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -365,7 +365,7 @@ extern int traceprobe_conflict_field_name(const char *name, extern void traceprobe_update_arg(struct probe_arg *arg); extern void traceprobe_free_probe_arg(struct probe_arg *arg); -extern int traceprobe_split_symbol_offset(char *symbol, unsigned long *offset); +extern int traceprobe_split_symbol_offset(char *symbol, long *offset); /* Sum up total data length for dynamic arraies (strings) */ static nokprobe_inline int