All of lore.kernel.org
 help / color / mirror / Atom feed
From: namhyung at kernel.org (Namhyung Kim)
Subject: [BUGFIX PATCH v2.1] tracing: probeevent: Fix to support minus offset from symbol
Date: Fri, 23 Feb 2018 09:15:42 +0900	[thread overview]
Message-ID: <20180223001542.GA25299@sejong> (raw)
In-Reply-To: <151928550073.16058.5161938919130863384.stgit@devbox>

Hi Masami,

On Thu, Feb 22, 2018 at 04:45:01PM +0900, Masami Hiramatsu wrote:
> 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 <mhiramat at kernel.org>
> ---
>  Changes in v2.1:
>   - Fix to ensure the offset value is less than LONG_MAX.
>   - Fail if the offset is minus when traceprobe_split_symbol_offset()
>     is used for the probe address.
>   - Add Fixes tag.
> ---
>  kernel/trace/trace_kprobe.c |    4 ++--
>  kernel/trace/trace_probe.c  |   15 ++++++++++-----
>  kernel/trace/trace_probe.h  |    2 +-
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 5ce9b8cf7be3..b5b1d8aa47d6 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) {
>  			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..ec3856147fdd 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -320,21 +320,26 @@ 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)
>  {
> +	unsigned long ul;
>  	char *tmp;
>  	int ret;
>  
>  	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 = kstrtoul(tmp + 1, 0, &ul);

Why not just using kstrtol() which handles the sign correctly?

Thanks,
Namhyung


>  		if (ret)
>  			return ret;
> -
> +		if (ul > LONG_MAX)
> +			return -E2BIG;
> +		if (*tmp == '-')
> +			*offset = -ul;
> +		else
> +			*offset = ul;
>  		*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
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: namhyung@kernel.org (Namhyung Kim)
Subject: [BUGFIX PATCH v2.1] tracing: probeevent: Fix to support minus offset from symbol
Date: Fri, 23 Feb 2018 09:15:42 +0900	[thread overview]
Message-ID: <20180223001542.GA25299@sejong> (raw)
Message-ID: <20180223001542.aY89blMAlL3Q2PHkFaIWiTQOfI5Z5wdxnc91AIJD6tE@z> (raw)
In-Reply-To: <151928550073.16058.5161938919130863384.stgit@devbox>

Hi Masami,

On Thu, Feb 22, 2018@04:45:01PM +0900, Masami Hiramatsu wrote:
> 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 <mhiramat at kernel.org>
> ---
>  Changes in v2.1:
>   - Fix to ensure the offset value is less than LONG_MAX.
>   - Fail if the offset is minus when traceprobe_split_symbol_offset()
>     is used for the probe address.
>   - Add Fixes tag.
> ---
>  kernel/trace/trace_kprobe.c |    4 ++--
>  kernel/trace/trace_probe.c  |   15 ++++++++++-----
>  kernel/trace/trace_probe.h  |    2 +-
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 5ce9b8cf7be3..b5b1d8aa47d6 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) {
>  			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..ec3856147fdd 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -320,21 +320,26 @@ 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)
>  {
> +	unsigned long ul;
>  	char *tmp;
>  	int ret;
>  
>  	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 = kstrtoul(tmp + 1, 0, &ul);

Why not just using kstrtol() which handles the sign correctly?

Thanks,
Namhyung


>  		if (ret)
>  			return ret;
> -
> +		if (ul > LONG_MAX)
> +			return -E2BIG;
> +		if (*tmp == '-')
> +			*offset = -ul;
> +		else
> +			*offset = ul;
>  		*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
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Namhyung Kim <namhyung@kernel.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
	Tom Zanussi <tom.zanussi@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	linux-trace-users@vger.kernel.org,
	linux-kselftest@vger.kernel.org, shuah@kernel.org,
	kernel-team@lge.com
Subject: Re: [BUGFIX PATCH v2.1] tracing: probeevent: Fix to support minus offset from symbol
Date: Fri, 23 Feb 2018 09:15:42 +0900	[thread overview]
Message-ID: <20180223001542.GA25299@sejong> (raw)
In-Reply-To: <151928550073.16058.5161938919130863384.stgit@devbox>

Hi Masami,

On Thu, Feb 22, 2018 at 04:45:01PM +0900, Masami Hiramatsu wrote:
> 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 <mhiramat@kernel.org>
> ---
>  Changes in v2.1:
>   - Fix to ensure the offset value is less than LONG_MAX.
>   - Fail if the offset is minus when traceprobe_split_symbol_offset()
>     is used for the probe address.
>   - Add Fixes tag.
> ---
>  kernel/trace/trace_kprobe.c |    4 ++--
>  kernel/trace/trace_probe.c  |   15 ++++++++++-----
>  kernel/trace/trace_probe.h  |    2 +-
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 5ce9b8cf7be3..b5b1d8aa47d6 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) {
>  			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..ec3856147fdd 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -320,21 +320,26 @@ 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)
>  {
> +	unsigned long ul;
>  	char *tmp;
>  	int ret;
>  
>  	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 = kstrtoul(tmp + 1, 0, &ul);

Why not just using kstrtol() which handles the sign correctly?

Thanks,
Namhyung


>  		if (ret)
>  			return ret;
> -
> +		if (ul > LONG_MAX)
> +			return -E2BIG;
> +		if (*tmp == '-')
> +			*offset = -ul;
> +		else
> +			*offset = ul;
>  		*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
> 

  reply	other threads:[~2018-02-23  0:15 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-21 14:54 [PATCH v2 00/17] tracing: probeevent: Improve fetcharg features mhiramat
2018-02-21 14:54 ` Masami Hiramatsu
2018-02-21 14:54 ` Masami Hiramatsu
2018-02-21 14:54 ` [PATCH v2 01/17] tracing: probeevent: Fix to support minus offset from symbol mhiramat
2018-02-21 14:54   ` Masami Hiramatsu
2018-02-21 14:54   ` Masami Hiramatsu
2018-02-21 23:41   ` mhiramat
2018-02-21 23:41     ` Masami Hiramatsu
2018-02-21 23:41     ` Masami Hiramatsu
2018-02-22  1:53     ` rostedt
2018-02-22  1:53       ` Steven Rostedt
2018-02-22  1:53       ` Steven Rostedt
2018-02-22  6:35       ` mhiramat
2018-02-22  6:35         ` Masami Hiramatsu
2018-02-22  6:35         ` Masami Hiramatsu
2018-02-22  7:45       ` [BUGFIX PATCH v2.1] " mhiramat
2018-02-22  7:45         ` Masami Hiramatsu
2018-02-22  7:45         ` Masami Hiramatsu
2018-02-23  0:15         ` namhyung [this message]
2018-02-23  0:15           ` Namhyung Kim
2018-02-23  0:15           ` Namhyung Kim
2018-02-23  9:44           ` mhiramat
2018-02-23  9:44             ` Masami Hiramatsu
2018-02-23  9:44             ` Masami Hiramatsu
2018-02-21 14:55 ` [PATCH v2 02/17] selftests: ftrace: Add probe event argument syntax testcase mhiramat
2018-02-21 14:55   ` Masami Hiramatsu
2018-02-21 14:55   ` Masami Hiramatsu
2018-02-21 14:55 ` [PATCH v2 03/17] selftests: ftrace: Add a testcase for string type with kprobe_event mhiramat
2018-02-21 14:55   ` Masami Hiramatsu
2018-02-21 14:55   ` Masami Hiramatsu
2018-02-21 14:56 ` [PATCH v2 04/17] tracing: probeevent: Cleanup print argument functions mhiramat
2018-02-21 14:56   ` Masami Hiramatsu
2018-02-21 14:56   ` Masami Hiramatsu
2018-02-21 14:56 ` [PATCH v2 05/17] tracing: probeevent: Cleanup argument field definition mhiramat
2018-02-21 14:56   ` Masami Hiramatsu
2018-02-21 14:56   ` Masami Hiramatsu
2018-02-21 14:57 ` [PATCH v2 06/17] tracing: probeevent: Remove NOKPROBE_SYMBOL from print functions mhiramat
2018-02-21 14:57   ` Masami Hiramatsu
2018-02-21 14:57   ` Masami Hiramatsu
2018-02-21 14:57 ` [PATCH v2 07/17] tracing: probeevent: Introduce new argument fetching code mhiramat
2018-02-21 14:57   ` Masami Hiramatsu
2018-02-21 14:57   ` Masami Hiramatsu
2018-02-23  4:30   ` namhyung
2018-02-23  4:30     ` Namhyung Kim
2018-02-23  4:30     ` Namhyung Kim
2018-02-23  9:43     ` mhiramat
2018-02-23  9:43       ` Masami Hiramatsu
2018-02-23  9:43       ` Masami Hiramatsu
2018-02-21 14:58 ` [PATCH v2 08/17] tracing: probeevent: Return consumed bytes of dynamic area mhiramat
2018-02-21 14:58   ` Masami Hiramatsu
2018-02-21 14:58   ` Masami Hiramatsu
2018-02-21 14:58 ` [PATCH v2 09/17] tracing: probeevent: Append traceprobe_ for exported function mhiramat
2018-02-21 14:58   ` Masami Hiramatsu
2018-02-21 14:58   ` Masami Hiramatsu
2018-02-21 14:59 ` [PATCH v2 10/17] tracing: probeevent: Unify fetch_insn processing common part mhiramat
2018-02-21 14:59   ` Masami Hiramatsu
2018-02-21 14:59   ` Masami Hiramatsu
2018-02-21 14:59 ` [PATCH v2 11/17] tracing: probeevent: Add symbol type mhiramat
2018-02-21 14:59   ` Masami Hiramatsu
2018-02-21 14:59   ` Masami Hiramatsu
2018-02-21 15:00 ` [PATCH v2 12/17] x86: ptrace: Add function argument access API mhiramat
2018-02-21 15:00   ` Masami Hiramatsu
2018-02-21 15:00   ` Masami Hiramatsu
2018-02-21 15:00 ` [PATCH v2 13/17] tracing: probeevent: Add $argN for accessing function args mhiramat
2018-02-21 15:00   ` Masami Hiramatsu
2018-02-21 15:00   ` Masami Hiramatsu
2018-02-22  8:35   ` mhiramat
2018-02-22  8:35     ` Masami Hiramatsu
2018-02-22  8:35     ` Masami Hiramatsu
2018-02-21 15:01 ` [PATCH v2 14/17] tracing: probeevent: Add array type support mhiramat
2018-02-21 15:01   ` Masami Hiramatsu
2018-02-21 15:01   ` Masami Hiramatsu
2018-02-21 15:01 ` [PATCH v2 15/17] selftests: ftrace: Add a testcase for symbol type mhiramat
2018-02-21 15:01   ` Masami Hiramatsu
2018-02-21 15:01   ` Masami Hiramatsu
2018-02-22 11:43   ` mhiramat
2018-02-22 11:43     ` Masami Hiramatsu
2018-02-22 11:43     ` Masami Hiramatsu
2018-02-21 15:01 ` [PATCH v2 16/17] selftests: ftrace: Add a testcase for $argN with kprobe_event mhiramat
2018-02-21 15:01   ` Masami Hiramatsu
2018-02-21 15:01   ` Masami Hiramatsu
2018-02-21 15:02 ` [PATCH v2 17/17] selftests: ftrace: Add a testcase for array type " mhiramat
2018-02-21 15:02   ` Masami Hiramatsu
2018-02-21 15:02   ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180223001542.GA25299@sejong \
    --to=unknown@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.