lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Zz7Kbp_XIu9f02Xj@google.com>
Date: Wed, 20 Nov 2024 21:51:42 -0800
From: Namhyung Kim <namhyung@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
	Arnaldo Carvalho de Melo <acme@...nel.org>,
	Mark Rutland <mark.rutland@....com>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
	Jiri Olsa <jolsa@...nel.org>,
	Adrian Hunter <adrian.hunter@...el.com>,
	Kan Liang <kan.liang@...ux.intel.com>,
	linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1] perf hwmon_pmu: Ensure hwmon key union is zeroed
 before use

On Tue, Nov 19, 2024 at 03:00:33PM -0800, Ian Rogers wrote:
> Non-zero values led to mismatches in testing. This was reproducible
> with -fsanitize=undefined.

It's sad the compiler didn't initialize all the members if it has
members with different size.

> 
> Reported-by: Arnaldo Carvalho de Melo <acme@...nel.org>
> Closes: https://lore.kernel.org/lkml/Zzdtj0PEWEX3ATwL@x1/
> Signed-off-by: Ian Rogers <irogers@...gle.com>

Acked-by: Namhyung Kim <namhyung@...nel.org>

Thanks,
Namhyung

> ---
>  tools/perf/util/hwmon_pmu.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c
> index ac2245acdc6d..4d9d6f405434 100644
> --- a/tools/perf/util/hwmon_pmu.c
> +++ b/tools/perf/util/hwmon_pmu.c
> @@ -274,7 +274,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
>  		int number;
>  		enum hwmon_item item;
>  		bool alarm;
> -		union hwmon_pmu_event_key key = {};
> +		union hwmon_pmu_event_key key = { .type_and_num = 0 };
>  		struct hwmon_pmu_event_value *value;
>  
>  		if (ent->d_type != DT_REG)
> @@ -560,7 +560,7 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name)
>  	struct hwmon_pmu *hwm = container_of(pmu, struct hwmon_pmu, pmu);
>  	enum hwmon_type type;
>  	int number;
> -	union hwmon_pmu_event_key key = {};
> +	union hwmon_pmu_event_key key = { .type_and_num = 0 };
>  	struct hashmap_entry *cur;
>  	size_t bkt;
>  
> @@ -623,10 +623,11 @@ static int hwmon_pmu__config_term(const struct hwmon_pmu *hwm,
>  					return -EINVAL;
>  			} else {
>  				union hwmon_pmu_event_key key = {
> -					.type = type,
> -					.num = number,
> +					.type_and_num = 0,
>  				};
>  
> +				key.type = type;
> +				key.num = number;
>  				attr->config = key.type_and_num;
>  			}
>  			return 0;
> -- 
> 2.47.0.371.ga323438b13-goog
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ