Skip to contentSkip to conversation

Fix security issue when reading username and password

PATCH In review Javier Martinez Canillas 5 participants 10 messages Oct 18, 2019 – Oct 24, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix security issue when reading username and password

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
 	{
 	  if (cur_len)
 	    cur_len--;
grub-core/normal/auth.c +1 -1
index 6be678c0de1..c35ce972473 100644
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
 	{
 	  if (cur_len)
 	    {
Signature · 1 line
2.21.0
#1 lore raw
Quoted 35 lines · Javier Martinez Canillas

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
 	{
 	  if (cur_len)
 	    cur_len--;
grub-core/normal/auth.c +0 -0
index 6be678c0de1..c35ce972473 100644

grub-core/normal/auth.c grub_username_get (char buf[], unsigned buf_size) · line 178

Quoted 8 lines
grub-core/normal/auth.c +1 -1
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
 	{
 	  if (cur_len)
 	    {

TBH, I do not understand how this patch helps. It only delays continue execution to the next "if (!grub_isprint (key))" if cur_len == 0.

Daniel

#2 lore raw

Hello Daniel,

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so way to underflow the "cur_len" variable and therefore

I hope this helps,

Hector.

Quoted 50 lines · Daniel Kiper
Quoted 35 lines · Javier Martinez Canillas

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
 	{
 	  if (cur_len)
 	    cur_len--;
grub-core/normal/auth.c +0 -0
index 6be678c0de1..c35ce972473 100644

grub-core/normal/auth.c grub_username_get (char buf[], unsigned buf_size) · line 178

Quoted 8 lines
grub-core/normal/auth.c +1 -1
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
 	{
 	  if (cur_len)
 	    {

TBH, I do not understand how this patch helps. It only delays continue execution to the next "if (!grub_isprint (key))" if cur_len == 0.

Daniel

#3 lore raw

Hello Daniel,

Something went wrong in my last email, what I wanted to say is:

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so no way to underflow the "cur_len" variable and therefore no vulnerability.

Hector.

Quoted 63 lines · Hector Marco

Hello Daniel,

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so way to underflow the "cur_len" variable and therefore

I hope this helps,

Hector.

Quoted 50 lines · Daniel Kiper
Quoted 35 lines · Javier Martinez Canillas

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
 	{
 	  if (cur_len)
 	    cur_len--;
grub-core/normal/auth.c +0 -0
index 6be678c0de1..c35ce972473 100644

grub-core/normal/auth.c grub_username_get (char buf[], unsigned buf_size) · line 178

Quoted 8 lines
grub-core/normal/auth.c +1 -1
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
 	{
 	  if (cur_len)
 	    {

TBH, I do not understand how this patch helps. It only delays continue execution to the next "if (!grub_isprint (key))" if cur_len == 0.

Daniel

#4 lore raw

Hi Hector,

Quoted 7 lines · Hector Marco

Hello Daniel,

Something went wrong in my last email, what I wanted to say is:

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so no way to underflow the "cur_len" variable and therefore no vulnerability.

First of all cur_len is unsigned. So, it does not get negative values at all. Though even it was signed I cannot see where in the code it can get negative value. Am I missing something?

Daniel

Quoted 65 lines

Hector.

Quoted 61 lines · Hector Marco

Hello Daniel,

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so way to underflow the "cur_len" variable and therefore

I hope this helps,

Hector.

Quoted 49 lines · Daniel Kiper
Quoted 35 lines · Javier Martinez Canillas

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
 	{
 	  if (cur_len)
 	    cur_len--;
grub-core/normal/auth.c +0 -0
index 6be678c0de1..c35ce972473 100644

grub-core/normal/auth.c grub_username_get (char buf[], unsigned buf_size) · line 178

Quoted 8 lines
grub-core/normal/auth.c +1 -1
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
 	{
 	  if (cur_len)
 	    {

TBH, I do not understand how this patch helps. It only delays continue execution to the next "if (!grub_isprint (key))" if cur_len == 0.

Daniel

#5 lore raw
Quoted 7 lines · On Thu, 24 Oct 2019, 18:11 Daniel Kiper, <[email protected]> wrote:

Hi Hector,

Quoted 4 lines · Hector Marco

Hello Daniel,

Something went wrong in my last email, what I wanted to say is:

Quoted 8 lines
Quoted 3 lines

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so no way to underflow the "cur_len" variable and therefore no vulnerability.

First of all cur_len is unsigned. So, it does not get negative values at all. Though even it was signed I cannot see where in the code it can get negative value. Am I missing something?

It's an old bug that is already fixed. "Signedness" in C is irrelevant. It got negative/very large previously and overwrote some stack. But it's long since fixed

Quoted 75 lines

Daniel

Quoted 17 lines

Hector.

Quoted 13 lines · Hector Marco

Hello Daniel,

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so way to underflow the "cur_len" variable and therefore

I hope this helps,

Hector.

Quoted 1 line · Daniel Kiper

On Fri, Oct 18, 2019 at 02:39:01PM +0200, Javier Martinez Canillas

Quoted 47 lines · wrote:
Quoted 47 lines
Quoted 47 lines
Quoted 35 lines

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
    break;
  }
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
  {
    if (cur_len)
      cur_len--;
grub-core/normal/auth.c +0 -0
index 6be678c0de1..c35ce972473 100644

grub-core/normal/auth.c grub_username_get (char buf[], unsigned buf_size) · line 178

Quoted 8 lines
grub-core/normal/auth.c +1 -1
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
    break;
  }
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
  {
    if (cur_len)
      {

TBH, I do not understand how this patch helps. It only delays continue execution to the next "if (!grub_isprint (key))" if cur_len == 0.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw
In reply to Daniel Kiper

Hi Daniel,

We wrote a blog entry explaining the problem and how it can be exploited:

http://hmarco.org/bugs/CVE-2015-8370-Grub2-authentication-bypass.html

The underflow (although it is unsigned) takes effect in the function grub_memset.
The exploitation is extremely hard to do but possible, as shown in the blog.

Regards,
Ismael.

Quoted 82 lines · Daniel Kiper

Hi Hector,

Quoted 7 lines · Hector Marco

Hello Daniel,

Something went wrong in my last email, what I wanted to say is:

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so no way to underflow the "cur_len" variable and therefore no vulnerability.

First of all cur_len is unsigned. So, it does not get negative values at all. Though even it was signed I cannot see where in the code it can get negative value. Am I missing something?

Daniel

Quoted 65 lines

Hector.

Quoted 61 lines · Hector Marco

Hello Daniel,

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so way to underflow the "cur_len" variable and therefore

I hope this helps,

Hector.

Quoted 49 lines · Daniel Kiper
Quoted 35 lines · Javier Martinez Canillas

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

  grub-core/lib/crypto.c  | 2 +-
  grub-core/normal/auth.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
  	  break;
  	}
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
  	{
  	  if (cur_len)
  	    cur_len--;
grub-core/normal/auth.c +0 -0
index 6be678c0de1..c35ce972473 100644

grub-core/normal/auth.c grub_username_get (char buf[], unsigned buf_size) · line 178

Quoted 8 lines
grub-core/normal/auth.c +1 -1
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
  	  break;
  	}
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
  	{
  	  if (cur_len)
  	    {

TBH, I do not understand how this patch helps. It only delays continue execution to the next "if (!grub_isprint (key))" if cur_len == 0.

Daniel

#7 lore raw
In reply to Daniel Kiper

Hi Daniel,

Sorry I didn't pay to much attention to this. Yes, it is unsigned but the underflow is still there.

Maybe what you are missing is that this underflowed value (cur_len) is later used in grub_memset( buf + cur_len, 0, buf_size - cur_len); which results in a buffer overflow (not underflow this time).

As Ismael say, please read the entry we wrote in 2015
http://hmarco.org/bugs/CVE-2015-8370-Grub2-authentication-bypass.html

Best regards,
Hector.

Quoted 82 lines · Daniel Kiper

Hi Hector,

Quoted 7 lines · Hector Marco

Hello Daniel,

Something went wrong in my last email, what I wanted to say is:

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so no way to underflow the "cur_len" variable and therefore no vulnerability.

First of all cur_len is unsigned. So, it does not get negative values at all. Though even it was signed I cannot see where in the code it can get negative value. Am I missing something?

Daniel

Quoted 65 lines

Hector.

Quoted 61 lines · Hector Marco

Hello Daniel,

The patch prevents that "cur_len" underflows. No negative values for "cur_len" so way to underflow the "cur_len" variable and therefore

I hope this helps,

Hector.

Quoted 49 lines · Daniel Kiper
Quoted 35 lines · Javier Martinez Canillas

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
 	{
 	  if (cur_len)
 	    cur_len--;
grub-core/normal/auth.c +0 -0
index 6be678c0de1..c35ce972473 100644

grub-core/normal/auth.c grub_username_get (char buf[], unsigned buf_size) · line 178

Quoted 8 lines
grub-core/normal/auth.c +1 -1
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
 	  break;
 	}
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
 	{
 	  if (cur_len)
 	    {

TBH, I do not understand how this patch helps. It only delays continue execution to the next "if (!grub_isprint (key))" if cur_len == 0.

Daniel

#8 lore raw
In reply to Javier Martinez Canillas

This has been committed years ago:
https://git.savannah.gnu.org/cgit/grub.git/commit/grub-core/lib/crypto.c?id=451d80e52d851432e109771bb8febafca7a5f1f2
Please contact whoever you got your GRUB from

Quoted 52 lines · Javier Martinez Canillas

From: Hector Marco-Gisbert <[email protected]>

This patch fixes two integer underflows at:
* grub-core/lib/crypto.c
* grub-core/normal/auth.c

Resolves: CVE-2015-8370

---

 grub-core/lib/crypto.c  | 2 +-
 grub-core/normal/auth.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/lib/crypto.c +1 -1
index ca334d5a40e..e6c78d16d39 100644
@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size)
          break;
        }
 
-      if (key == '\b')
+      if (key == '\b' && cur_len)
        {
          if (cur_len)
            cur_len--;
grub-core/normal/auth.c +1 -2
index 6be678c0de1..c35ce972473 100644
@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size)
          break;
        }
 
-      if (key == GRUB_TERM_BACKSPACE)
+      if (key == GRUB_TERM_BACKSPACE && cur_len)
        {
          if (cur_len)
            {
--

2.21.0

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#9 lore raw

Hello Vladimir,

Quoted 4 lines · Vladimir 'phcoder' Serbinenko

This has been committed years ago:
https://git.savannah.gnu.org/cgit/grub.git/commit/grub-core/lib/crypto.c?id=451d80e52d851432e109771bb8febafca7a5f1f2
Please contact whoever you got your GRUB from

Oh I see. Since is not the same patch than the one mentioned in their post [0], I didn't realize that the fix has already landed. Thanks for pointing it out.

I'll just drop this patch then.

[0]: http://hmarco.org/bugs/patches/0001-Fix-CVE-2015-8370-Grub2-user-pass-vulnerability.patch

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat