All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] derivers/autotune: Fix UBSAN warnings
@ 2019-07-26 15:01 Jan Kiszka
  2019-07-26 15:20 ` Philippe Gerum
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2019-07-26 15:01 UTC (permalink / raw)
  To: Xenomai, Philippe Gerum

The calculations in add_sample can overflow into undefined behavior - or
even generate wrong results. Address that by giving related fields in
tuner_state more space.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 kernel/drivers/autotune/autotune.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/drivers/autotune/autotune.c b/kernel/drivers/autotune/autotune.c
index 2629bf9d47..9728ad6ff1 100644
--- a/kernel/drivers/autotune/autotune.c
+++ b/kernel/drivers/autotune/autotune.c
@@ -56,9 +56,9 @@ struct tuner_state {
 	xnticks_t step;
 	int min_lat;
 	int max_lat;
-	int prev_mean;
-	int prev_sqs;
-	int cur_sqs;
+	long prev_mean;
+	long prev_sqs;
+	long cur_sqs;
 	unsigned int sum;
 	unsigned int cur_samples;
 	unsigned int max_samples;
-- 
2.16.4


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

* Re: [PATCH] derivers/autotune: Fix UBSAN warnings
  2019-07-26 15:01 [PATCH] derivers/autotune: Fix UBSAN warnings Jan Kiszka
@ 2019-07-26 15:20 ` Philippe Gerum
  2019-07-26 15:21   ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Gerum @ 2019-07-26 15:20 UTC (permalink / raw)
  To: Jan Kiszka, Xenomai

On 7/26/19 5:01 PM, Jan Kiszka wrote:
> The calculations in add_sample can overflow into undefined behavior - or
> even generate wrong results. Address that by giving related fields in
> tuner_state more space.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  kernel/drivers/autotune/autotune.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/drivers/autotune/autotune.c b/kernel/drivers/autotune/autotune.c
> index 2629bf9d47..9728ad6ff1 100644
> --- a/kernel/drivers/autotune/autotune.c
> +++ b/kernel/drivers/autotune/autotune.c
> @@ -56,9 +56,9 @@ struct tuner_state {
>  	xnticks_t step;
>  	int min_lat;
>  	int max_lat;
> -	int prev_mean;
> -	int prev_sqs;
> -	int cur_sqs;
> +	long prev_mean;
> +	long prev_sqs;
> +	long cur_sqs;
>  	unsigned int sum;
>  	unsigned int cur_samples;
>  	unsigned int max_samples;
> 

s64/long long to enable the fix for 32bit archs too?

-- 
Philippe.


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

* Re: [PATCH] derivers/autotune: Fix UBSAN warnings
  2019-07-26 15:20 ` Philippe Gerum
@ 2019-07-26 15:21   ` Jan Kiszka
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2019-07-26 15:21 UTC (permalink / raw)
  To: Philippe Gerum, Xenomai

On 26.07.19 17:20, Philippe Gerum wrote:
> On 7/26/19 5:01 PM, Jan Kiszka wrote:
>> The calculations in add_sample can overflow into undefined behavior - or
>> even generate wrong results. Address that by giving related fields in
>> tuner_state more space.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>  kernel/drivers/autotune/autotune.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/drivers/autotune/autotune.c b/kernel/drivers/autotune/autotune.c
>> index 2629bf9d47..9728ad6ff1 100644
>> --- a/kernel/drivers/autotune/autotune.c
>> +++ b/kernel/drivers/autotune/autotune.c
>> @@ -56,9 +56,9 @@ struct tuner_state {
>>  	xnticks_t step;
>>  	int min_lat;
>>  	int max_lat;
>> -	int prev_mean;
>> -	int prev_sqs;
>> -	int cur_sqs;
>> +	long prev_mean;
>> +	long prev_sqs;
>> +	long cur_sqs;
>>  	unsigned int sum;
>>  	unsigned int cur_samples;
>>  	unsigned int max_samples;
>>
> 
> s64/long long to enable the fix for 32bit archs too?
> 

Yeah, indeed. v2 follows.

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


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

end of thread, other threads:[~2019-07-26 15:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26 15:01 [PATCH] derivers/autotune: Fix UBSAN warnings Jan Kiszka
2019-07-26 15:20 ` Philippe Gerum
2019-07-26 15:21   ` Jan Kiszka

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.