Skip to contentSkip to conversation

net: atm: Spectre v1 fix introduced bug in bcb964012d1b in -stable

PATCH NAK Pavel Machek 3 participants 8 messages May 20, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

# for 4.19.y
net/atm/lec.c +1 -1
index ad4f829193f0..ed279cd912f4 100644
@@ -731,7 +731,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
 		i = arg;
 	if (arg >= MAX_LEC_ITF)
 		return -EINVAL;
-	i = array_index_nospec(arg, MAX_LEC_ITF);
+	i = array_index_nospec(i, MAX_LEC_ITF);
 	if (!dev_lec[i]) {
 		int size;
 
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#1 lore raw
Quoted 12 lines · Pavel Machek

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

# for 4.19.y
net/atm/lec.c +0 -0
index ad4f829193f0..ed279cd912f4 100644

net/atm/lec.c static int lecd_attach(struct atm_vcc *vcc, int arg) · line 737

Quoted 8 lines
net/atm/lec.c +1 -1
@@ -731,7 +731,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
 		i = arg;
 	if (arg >= MAX_LEC_ITF)
 		return -EINVAL;
-	i = array_index_nospec(arg, MAX_LEC_ITF);
+	i = array_index_nospec(i, MAX_LEC_ITF);
 	if (!dev_lec[i]) {
 		int size;
 

Why is this only for 4.19.y? What is different in Linus's tree that makes this not needed there?

thanks,

greg k-h

#5 lore raw
In reply to Pavel Machek
Quoted 4 lines · Pavel Machek

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

NACK

array_index_nospec() macro returns zero if *arg* is out of bounds.

In any case, if the "bug" does not exist in mainline, what should be done is to port the code that fixed it in mainline to old kernels, not randomly add a "fix" here and there because that means we are breaking backward compatibility.

--
Gustavo

Quoted 17 lines
# for 4.19.y
net/atm/lec.c +1 -1
index ad4f829193f0..ed279cd912f4 100644
@@ -731,7 +731,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
 		i = arg;
 	if (arg >= MAX_LEC_ITF)
 		return -EINVAL;
-	i = array_index_nospec(arg, MAX_LEC_ITF);
+	i = array_index_nospec(i, MAX_LEC_ITF);
 	if (!dev_lec[i]) {
 		int size;
 
#2 lore raw
In reply to Greg KH
Quoted 8 lines · Greg KH
Quoted 7 lines · Pavel Machek

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

# for 4.19.y
Quoted 17 lines

net/atm/lec.c static int lecd_attach(struct atm_vcc *vcc, int arg) · line 737

Quoted 13 lines
net/atm/lec.c +1 -1
index ad4f829193f0..ed279cd912f4 100644
@@ -731,7 +731,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
 		i = arg;
 	if (arg >= MAX_LEC_ITF)
 		return -EINVAL;
-	i = array_index_nospec(arg, MAX_LEC_ITF);
+	i = array_index_nospec(i, MAX_LEC_ITF);
 	if (!dev_lec[i]) {
 		int size;
 

Why is this only for 4.19.y? What is different in Linus's tree that makes this not needed there?

The only difference is this clean up:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fdd1a8103a6df50bdeacd8bb04c3f6976cb9ae41

As Dan says, the code works fine, but the *i* value wasn't being used anymore, so that piece of code was a bit confusing.

Thanks
--
Gustavo

#4 lore raw
In reply to Greg KH
Quoted 8 lines · Greg KH
Quoted 7 lines · Pavel Machek

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

# for 4.19.y
Quoted 16 lines

net/atm/lec.c static int lecd_attach(struct atm_vcc *vcc, int arg) · line 737

Quoted 13 lines
net/atm/lec.c +1 -1
index ad4f829193f0..ed279cd912f4 100644
@@ -731,7 +731,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
 		i = arg;
 	if (arg >= MAX_LEC_ITF)
 		return -EINVAL;
-	i = array_index_nospec(arg, MAX_LEC_ITF);
+	i = array_index_nospec(i, MAX_LEC_ITF);
 	if (!dev_lec[i]) {
 		int size;
 

Why is this only for 4.19.y? What is different in Linus's tree that makes this not needed there?

Mainline sanitizes "arg", 4.19 copies "arg" into "i" then sanitizes it. Take a look, it is local to the function.
Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#6 lore raw
In reply to Gustavo A. R. Silva
Quoted 11 lines · Gustavo A. R. Silva
Quoted 4 lines · Pavel Machek

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

NACK

array_index_nospec() macro returns zero if *arg* is out of bounds.

No, it does not. Take a look:

#define array_index_nospec(index, size)
...

        (typeof(_i)) (_i & _mask);
})

Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#7 lore raw
Quoted 11 lines · Pavel Machek
Quoted 10 lines · Gustavo A. R. Silva
Quoted 4 lines · Pavel Machek

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

NACK

Quoted 9 lines
Quoted 1 line

array_index_nospec() macro returns zero if *arg* is out of bounds.

No, it does not. Take a look:

#define array_index_nospec(index, size)
...

        (typeof(_i)) (_i & _mask);
})

Tell me more about that _mask.

Also, don't ignore the backward compatibility; otherwise you would be forking your own kernel.

--
Gustavo

#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 29 lines · Gustavo A. R. Silva
Quoted 8 lines · Greg KH
Quoted 7 lines · Pavel Machek

In lecd_attach, if arg is < 0, it was treated as 0. Spectre v1 fix changed that. Bug does not exist in mainline AFAICT.

# for 4.19.y
Quoted 17 lines

net/atm/lec.c static int lecd_attach(struct atm_vcc *vcc, int arg) · line 737

Quoted 13 lines
net/atm/lec.c +1 -1
index ad4f829193f0..ed279cd912f4 100644
@@ -731,7 +731,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
 		i = arg;
 	if (arg >= MAX_LEC_ITF)
 		return -EINVAL;
-	i = array_index_nospec(arg, MAX_LEC_ITF);
+	i = array_index_nospec(i, MAX_LEC_ITF);
 	if (!dev_lec[i]) {
 		int size;
 

Why is this only for 4.19.y? What is different in Linus's tree that makes this not needed there?

Quoted 6 lines

The only difference is this clean up:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fdd1a8103a6df50bdeacd8bb04c3f6976cb9ae41

As Dan says, the code works fine, but the *i* value wasn't being used anymore, so that piece of code was a bit confusing.

Yep, you are right, code managed to confused me: array_index_nospec really returns 0 if it is out of bounds,

(typeof(_i)) (_i & _mask);

because _mask is always 0 or ~0.

Best regards,
Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany