stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod
@ 2021-08-26 10:23 Pavel Machek
  2021-08-26 11:06 ` Thadeu Lima de Souza Cascardo
  2021-08-30 18:38 ` Thadeu Lima de Souza Cascardo
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel Machek @ 2021-08-26 10:23 UTC (permalink / raw)
  To: stable, kernel list, daniel, john.fastabend, ast

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

Hi!

As far as I can tell, CVE-2021-3600 is still a problem for 4.14 and
4.19.

Unfortunately, those kernels lack BPF_JMP32 support, and that support
is too big and intrusive to backport.

So I tried to come up with solution without JMP32 support... only to
end up with not seeing the bug in the affected code.

Changelog says:

    bpf: Fix 32 bit src register truncation on div/mod
    
    While reviewing a different fix, John and I noticed an oddity in one of the
    BPF program dumps that stood out, for example:
    
      # bpftool p d x i 13
       0: (b7) r0 = 808464450
       1: (b4) w4 = 808464432
       2: (bc) w0 = w0
       3: (15) if r0 == 0x0 goto pc+1
       4: (9c) w4 %= w0
      [...]
    
    In line 2 we noticed that the mov32 would 32 bit truncate the original src
    register for the div/mod operation. While for the two operations the dst
    register is typically marked unknown e.g. from adjust_scalar_min_max_vals()
    the src register is not, and thus verifier keeps tracking original bounds,
    simplified:

So this explains "mov32 w0, w0" is problematic, and fixes the bug by
replacing it with jmp32. Unfortunately, I can't do that in 4.19; plus
I don't really see how the bug is solved -- we avoided adding mov32
sequence that triggers the problem, but the problematic sequence could
still be produced by the userspace, no?

Does adjust_scalar_min_max_vals still need fixing?

Do you have any hints how to solve this in 4.19?

Best regards,
								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod
  2021-08-26 10:23 CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod Pavel Machek
@ 2021-08-26 11:06 ` Thadeu Lima de Souza Cascardo
  2021-08-30 18:38 ` Thadeu Lima de Souza Cascardo
  1 sibling, 0 replies; 4+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2021-08-26 11:06 UTC (permalink / raw)
  To: Pavel Machek; +Cc: stable, kernel list, daniel, john.fastabend, ast, carnil

On Thu, Aug 26, 2021 at 12:23:37PM +0200, Pavel Machek wrote:
> Hi!
> 
> As far as I can tell, CVE-2021-3600 is still a problem for 4.14 and
> 4.19.
> 
> Unfortunately, those kernels lack BPF_JMP32 support, and that support
> is too big and intrusive to backport.
> 
> So I tried to come up with solution without JMP32 support... only to
> end up with not seeing the bug in the affected code.
> 
> Changelog says:
> 
>     bpf: Fix 32 bit src register truncation on div/mod
>     
>     While reviewing a different fix, John and I noticed an oddity in one of the
>     BPF program dumps that stood out, for example:
>     
>       # bpftool p d x i 13
>        0: (b7) r0 = 808464450
>        1: (b4) w4 = 808464432
>        2: (bc) w0 = w0
>        3: (15) if r0 == 0x0 goto pc+1
>        4: (9c) w4 %= w0
>       [...]
>     
>     In line 2 we noticed that the mov32 would 32 bit truncate the original src
>     register for the div/mod operation. While for the two operations the dst
>     register is typically marked unknown e.g. from adjust_scalar_min_max_vals()
>     the src register is not, and thus verifier keeps tracking original bounds,
>     simplified:
> 
> So this explains "mov32 w0, w0" is problematic, and fixes the bug by
> replacing it with jmp32. Unfortunately, I can't do that in 4.19; plus
> I don't really see how the bug is solved -- we avoided adding mov32
> sequence that triggers the problem, but the problematic sequence could
> still be produced by the userspace, no?
> 
> Does adjust_scalar_min_max_vals still need fixing?
> 
> Do you have any hints how to solve this in 4.19?
> 
> Best regards,
> 								Pavel
> -- 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Hi, Pavel.

We have fixed this in our 4.15 kernels with help from Daniel, John, Alexei and
Salvatore. I am a little busy right now, but will make time to work on the
commits we had for 4.19. 4.19 is also affected by CVE-2021-3444, IIRC.

When I get back to it, I may try to answer some of your questions.

Cascardo.

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

* Re: CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod
  2021-08-26 10:23 CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod Pavel Machek
  2021-08-26 11:06 ` Thadeu Lima de Souza Cascardo
@ 2021-08-30 18:38 ` Thadeu Lima de Souza Cascardo
  2021-08-31 13:30   ` Pavel Machek
  1 sibling, 1 reply; 4+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2021-08-30 18:38 UTC (permalink / raw)
  To: Pavel Machek; +Cc: stable, kernel list, daniel, john.fastabend, ast

On Thu, Aug 26, 2021 at 12:23:37PM +0200, Pavel Machek wrote:
> Hi!
> 
> As far as I can tell, CVE-2021-3600 is still a problem for 4.14 and
> 4.19.
> 
> Unfortunately, those kernels lack BPF_JMP32 support, and that support
> is too big and intrusive to backport.
> 
> So I tried to come up with solution without JMP32 support... only to
> end up with not seeing the bug in the affected code.
> 
> Changelog says:
> 
>     bpf: Fix 32 bit src register truncation on div/mod
>     
>     While reviewing a different fix, John and I noticed an oddity in one of the
>     BPF program dumps that stood out, for example:
>     
>       # bpftool p d x i 13
>        0: (b7) r0 = 808464450
>        1: (b4) w4 = 808464432
>        2: (bc) w0 = w0
>        3: (15) if r0 == 0x0 goto pc+1
>        4: (9c) w4 %= w0
>       [...]
>     
>     In line 2 we noticed that the mov32 would 32 bit truncate the original src
>     register for the div/mod operation. While for the two operations the dst
>     register is typically marked unknown e.g. from adjust_scalar_min_max_vals()
>     the src register is not, and thus verifier keeps tracking original bounds,
>     simplified:
> 
> So this explains "mov32 w0, w0" is problematic, and fixes the bug by
> replacing it with jmp32. Unfortunately, I can't do that in 4.19; plus
> I don't really see how the bug is solved -- we avoided adding mov32
> sequence that triggers the problem, but the problematic sequence could
> still be produced by the userspace, no?
> 
> Does adjust_scalar_min_max_vals still need fixing?
> 
> Do you have any hints how to solve this in 4.19?
> 
> Best regards,
> 								Pavel
> -- 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Hi, Pavel.

I have just sent the fixes for 4.14. I sent fixes for 4.19 last Friday.

The problem here is that the verifier assumes the source register has a given
value, but the fixups change that value to something else when it is truncated.

The fixups run after the verifier, so a similar sequence produced by userspace
will be correctly verified, so no fixes are necessary on adjust_scalar_min_max
for this specific issue. The fixed-up code is not verified again.

The challenge in providing those fixes to 4.14 and 4.19 is the absence of JMP32
in those kernels. So, AX was taken as a temporary, so it would still work on
JITs.

Cascardo.

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

* Re: CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod
  2021-08-30 18:38 ` Thadeu Lima de Souza Cascardo
@ 2021-08-31 13:30   ` Pavel Machek
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2021-08-31 13:30 UTC (permalink / raw)
  To: Thadeu Lima de Souza Cascardo
  Cc: Pavel Machek, stable, kernel list, daniel, john.fastabend, ast

[-- Attachment #1: Type: text/plain, Size: 1454 bytes --]

Hi!

> > So this explains "mov32 w0, w0" is problematic, and fixes the bug by
> > replacing it with jmp32. Unfortunately, I can't do that in 4.19; plus
> > I don't really see how the bug is solved -- we avoided adding mov32
> > sequence that triggers the problem, but the problematic sequence could
> > still be produced by the userspace, no?
> > 
> > Does adjust_scalar_min_max_vals still need fixing?
> > 
> > Do you have any hints how to solve this in 4.19?

> I have just sent the fixes for 4.14. I sent fixes for 4.19 last Friday.
> 
> The problem here is that the verifier assumes the source register has a given
> value, but the fixups change that value to something else when it is truncated.
> 
> The fixups run after the verifier, so a similar sequence produced by userspace
> will be correctly verified, so no fixes are necessary on adjust_scalar_min_max
> for this specific issue. The fixed-up code is not verified again.

Thanks, understood.

> The challenge in providing those fixes to 4.14 and 4.19 is the absence of JMP32
> in those kernels. So, AX was taken as a temporary, so it would still work on
> JITs.

Yes, I got that far. I have seen the patches for 4.19 and 4.14, and
they should fix my problems. Thanks a lot for them.

Best regards,
								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

end of thread, other threads:[~2021-08-31 13:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 10:23 CVE-2021-3600 aka bpf: Fix 32 bit src register truncation on div/mod Pavel Machek
2021-08-26 11:06 ` Thadeu Lima de Souza Cascardo
2021-08-30 18:38 ` Thadeu Lima de Souza Cascardo
2021-08-31 13:30   ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).