All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tools/perf/util: null-terminate version char array upon error
@ 2019-05-14 11:01 Donald Yandt
  2019-05-14 13:36 ` Arnaldo Carvalho de Melo
  2019-05-18  8:59 ` [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error tip-bot for Donald Yandt
  0 siblings, 2 replies; 3+ messages in thread
From: Donald Yandt @ 2019-05-14 11:01 UTC (permalink / raw)
  To: peterz; +Cc: mingo, acme, alexander.shishkin, jolsa, linux-kernel,
	Donald Yandt

If fgets fails due to any other error besides end-of-file, the version char array may not even be null-terminated.

Signed-off-by: Donald Yandt <donald.yandt@gmail.com>
---
 tools/perf/util/machine.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3c520baa1..28a9541c4 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1234,8 +1234,9 @@ static char *get_kernel_version(const char *root_dir)
 	if (!file)
 		return NULL;

-	version[0] = '\0';
 	tmp = fgets(version, sizeof(version), file);
+	if (!tmp)
+		*version = '\0';
 	fclose(file);

 	name = strstr(version, prefix);
--
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tools/perf/util: null-terminate version char array upon error
  2019-05-14 11:01 [PATCH v2] tools/perf/util: null-terminate version char array upon error Donald Yandt
@ 2019-05-14 13:36 ` Arnaldo Carvalho de Melo
  2019-05-18  8:59 ` [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error tip-bot for Donald Yandt
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-05-14 13:36 UTC (permalink / raw)
  To: Donald Yandt
  Cc: Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
	linux-kernel, Yanmin Zhang

Em Tue, May 14, 2019 at 07:01:00AM -0400, Donald Yandt escreveu:
> If fgets fails due to any other error besides end-of-file, the version char array may not even be null-terminated.

Thanks, but out of curiosity, was this found just by visual inspection?
Some static analysis tool? An actual problem you stumbled when
processing some /proc/version in a custom kernel?

Also please consider adding a:

Fixes: a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host")

So that we can get this picked up by the stable kernel trees. I'm adding
it now.

Thanks!

- Arnaldo
 
> Signed-off-by: Donald Yandt <donald.yandt@gmail.com>
> ---
>  tools/perf/util/machine.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 3c520baa1..28a9541c4 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -1234,8 +1234,9 @@ static char *get_kernel_version(const char *root_dir)
>  	if (!file)
>  		return NULL;
> 
> -	version[0] = '\0';
>  	tmp = fgets(version, sizeof(version), file);
> +	if (!tmp)
> +		*version = '\0';
>  	fclose(file);
> 
>  	name = strstr(version, prefix);
> --
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error
  2019-05-14 11:01 [PATCH v2] tools/perf/util: null-terminate version char array upon error Donald Yandt
  2019-05-14 13:36 ` Arnaldo Carvalho de Melo
@ 2019-05-18  8:59 ` tip-bot for Donald Yandt
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Donald Yandt @ 2019-05-18  8:59 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, mingo, linux-kernel, peterz, hpa,
	yanmin_zhang, acme, jolsa, tglx, donald.yandt, avi

Commit-ID:  30ba5b0e66c872faa416a458d32cc3956ecb548a
Gitweb:     https://git.kernel.org/tip/30ba5b0e66c872faa416a458d32cc3956ecb548a
Author:     Donald Yandt <donald.yandt@gmail.com>
AuthorDate: Tue, 14 May 2019 07:01:00 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 15 May 2019 16:36:47 -0300

perf machine: Null-terminate version char array upon fgets(/proc/version) error

If fgets() fails due to any other error besides end-of-file, the version
char array may not even be null-terminated.

Signed-off-by: Donald Yandt <donald.yandt@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Avi Kivity <avi@scylladb.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com>
Fixes: a1645ce12adb ("perf: 'perf kvm' tool for monitoring guest performance from host")
Link: http://lkml.kernel.org/r/20190514110100.22019-1-donald.yandt@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3c520baa198c..28a9541c4835 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1234,8 +1234,9 @@ static char *get_kernel_version(const char *root_dir)
 	if (!file)
 		return NULL;
 
-	version[0] = '\0';
 	tmp = fgets(version, sizeof(version), file);
+	if (!tmp)
+		*version = '\0';
 	fclose(file);
 
 	name = strstr(version, prefix);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-18  8:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-14 11:01 [PATCH v2] tools/perf/util: null-terminate version char array upon error Donald Yandt
2019-05-14 13:36 ` Arnaldo Carvalho de Melo
2019-05-18  8:59 ` [tip:perf/core] perf machine: Null-terminate version char array upon fgets(/proc/version) error tip-bot for Donald Yandt

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.