Skip to contentSkip to conversation

ls: prevent double open

PATCH Superseded Eric Snowberg 4 participants 11 messages Oct 16, 2017 – Nov 13, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ls: prevent double open

Prevent a double open. This can cause problems with some ieee1275 devices, causing the system to hang. The double open can occur as follows:

grub_ls_list_files (char *dirname, int longlist, int all, int human)

       dev = grub_device_open (device_name);
       dev remains open while:
       grub_normal_print_device_info (device_name);
                dev = grub_device_open (name);
---
 grub-core/commands/ls.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
grub-core/commands/ls.c +2 -0
index 0eaf836..a7318ab 100644
@@ -201,6 +201,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
       if (grub_errno == GRUB_ERR_UNKNOWN_FS)
 	grub_errno = GRUB_ERR_NONE;
 
+      grub_device_close (dev);
+      dev = NULL;
       grub_normal_print_device_info (device_name);
     }
   else if (fs)
Signature · 1 line
1.7.1
#1 lore raw
Quoted 11 lines · Eric Snowberg

Prevent a double open. This can cause problems with some ieee1275 devices, causing the system to hang. The double open can occur as follows:

grub_ls_list_files (char *dirname, int longlist, int all, int human)

       dev = grub_device_open (device_name);
       dev remains open while:
       grub_normal_print_device_info (device_name);
                dev = grub_device_open (name);

In general LGTM. One nitpick...

Quoted 9 lines
---
 grub-core/commands/ls.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
grub-core/commands/ls.c +0 -0
index 0eaf836..a7318ab 100644

grub-core/commands/ls.c grub_ls_list_files (char *dirname, int longlist, int all, int human) · line 205

Quoted 5 lines
grub-core/commands/ls.c +2 -0
@@ -201,6 +201,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
       if (grub_errno == GRUB_ERR_UNKNOWN_FS)
 	grub_errno = GRUB_ERR_NONE;
 
+      grub_device_close (dev);
+      dev = NULL;

I would put a comment before why it is needed.

Thanks,

Daniel

#2 lore raw
Quoted 30 lines · Daniel Kiper
Quoted 11 lines · Eric Snowberg

Prevent a double open. This can cause problems with some ieee1275 devices, causing the system to hang. The double open can occur as follows:

grub_ls_list_files (char *dirname, int longlist, int all, int human)

      dev = grub_device_open (device_name);
      dev remains open while:
      grub_normal_print_device_info (device_name);
               dev = grub_device_open (name);

In general LGTM. One nitpick...

Quoted 12 lines

---
grub-core/commands/ls.c | 2 ++

1 files changed, 2 insertions(+), 0 deletions(-)
grub-core/commands/ls.c +0 -0
index 0eaf836..a7318ab 100644
@@ -201,6 +201,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
      if (grub_errno == GRUB_ERR_UNKNOWN_FS)
 	grub_errno = GRUB_ERR_NONE;
 
Quoted 5 lines

grub-core/commands/ls.c grub_ls_list_files (char *dirname, int longlist, int all, int human) · line 205

Quoted 2 lines
grub-core/commands/ls.c +2 -0
+      grub_device_close (dev);
+      dev = NULL;

I would put a comment before why it is needed.

Ok, I’ll add a comment and submit a V2.

#3 lore raw
Quoted 28 lines · Eric Snowberg
Quoted 28 lines · Daniel Kiper
Quoted 11 lines · Eric Snowberg

Prevent a double open. This can cause problems with some ieee1275 devices, causing the system to hang. The double open can occur as follows:

grub_ls_list_files (char *dirname, int longlist, int all, int human)

      dev = grub_device_open (device_name);
      dev remains open while:
      grub_normal_print_device_info (device_name);
               dev = grub_device_open (name);

In general LGTM. One nitpick...

Quoted 12 lines

---
grub-core/commands/ls.c | 2 ++

1 files changed, 2 insertions(+), 0 deletions(-)
grub-core/commands/ls.c +0 -0
index 0eaf836..a7318ab 100644
@@ -201,6 +201,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
      if (grub_errno == GRUB_ERR_UNKNOWN_FS)
 	grub_errno = GRUB_ERR_NONE;
 
Quoted 7 lines
Quoted 5 lines

grub-core/commands/ls.c grub_ls_list_files (char *dirname, int longlist, int all, int human) · line 205

Quoted 2 lines
grub-core/commands/ls.c +2 -0
+      grub_device_close (dev);
+      dev = NULL;

I would put a comment before why it is needed.

Ok, I’ll add a comment and submit a V2.

I was going to apply this today but have not found v2... :-((( If you post it I will apply it immediately.

Daniel

#4 lore raw
Quoted 4 lines · Daniel Kiper
Quoted 1 line

Ok, I’ll add a comment and submit a V2.

I was going to apply this today but have not found v2... :-((( If you post it I will apply it immediately.

I think Eric didn't send a V2 patch yet. But since the only difference would be adding an additional explanatory comment, why not apply his patch and then add the comment in another commit?

Or just apply his patch, add a comment and then commit it?

@Eric: What's your opinion?

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#5 lore raw
In reply to Eric Snowberg
Quoted 4 lines · On Mon, Oct 16, 2017, 22:11 Eric Snowberg <[email protected]> wrote:

Prevent a double open. This can cause problems with some ieee1275 devices, causing the system to hang. The double open can occur as follows:

Why does it? Underlying firmware device should not be aware of how many times grub device is open. If it is and it causes bugs, then it's a bug in device driver

Quoted 30 lines

grub_ls_list_files (char *dirname, int longlist, int all, int human)

       dev = grub_device_open (device_name);
       dev remains open while:
       grub_normal_print_device_info (device_name);
                dev = grub_device_open (name);
---
 grub-core/commands/ls.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
grub-core/commands/ls.c +2 -0
index 0eaf836..a7318ab 100644
@@ -201,6 +201,8 @@ grub_ls_list_files (char *dirname, int longlist, int
 all, int human)
       if (grub_errno == GRUB_ERR_UNKNOWN_FS)
        grub_errno = GRUB_ERR_NONE;
 
+      grub_device_close (dev);
+      dev = NULL;
       grub_normal_print_device_info (device_name);
     }

else if (fs)
--
1.7.1

#6 lore raw
Quoted 10 lines · Vladimir 'phcoder' Serbinenko

On Mon, Oct 16, 2017, 22:11 Eric Snowberg <[email protected]> wrote:
Prevent a double open. This can cause problems with some ieee1275
devices, causing the system to hang. The double open can occur
as follows:
Why does it? Underlying firmware device should not be aware of how many times grub device is open. If it is and it causes bugs, then it's a bug in device driver

Which device driver are you referring to? The one in GRUB or Open Firmware?

#7 lore raw
Quoted 12 lines · On Wed, Oct 18, 2017, 19:02 Eric Snowberg <[email protected]> wrote:
Quoted 2 lines

On Oct 18, 2017, at 10:32 AM, Vladimir 'phcoder' Serbinenko <

Quoted 4 lines · [email protected]> wrote:

On Mon, Oct 16, 2017, 22:11 Eric Snowberg <[email protected]>

Quoted 4 lines · wrote:

Prevent a double open. This can cause problems with some ieee1275 devices, causing the system to hang. The double open can occur as follows:
Why does it? Underlying firmware device should not be aware of how many

Quoted 6 lines

times grub device is open. If it is and it causes bugs, then it's a bug in device driver

Which device driver are you referring to? The one in GRUB or Open Firmware?

In GRUB

Quoted 3 lines
#8 lore raw
Quoted 11 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · On Wed, Oct 18, 2017, 19:02 Eric Snowberg <[email protected]> wrote:

On Oct 18, 2017, at 10:32 AM, Vladimir 'phcoder' Serbinenko <[email protected]> wrote:

Quoted 10 lines
Quoted 5 lines · On Mon, Oct 16, 2017, 22:11 Eric Snowberg <[email protected]> wrote:

Prevent a double open. This can cause problems with some ieee1275
devices, causing the system to hang. The double open can occur
as follows:
Why does it? Underlying firmware device should not be aware of how many times grub device is open. If it is and it causes bugs, then it's a bug in device driver

Which device driver are you referring to? The one in GRUB or Open Firmware? In GRUB

I would agree with that. There are many problems with the ofdisk driver in GRUB. One being the memory corruption issues that prevents new code from being added to it, which is what I believe you are recommending. I submitted a fix for the memory corruption problems years ago, but the patch was ignored.

memory corruption example:

devpath created in grub_ofdisk_open
it then calls ofdisk_hash_add with devpath
it then calls ofdisk_hash_add_real with devpath
ofdisk_hash_add_real saves pointer of devpath
return
return
free devpath

dangling pointer/memory corruption with what is stored in ofdisk_hash_add_real, any new memory allocation corrupts devpath

As I recall, just trying to add a grub_printf in the wrong place can corrupt the devpath. I never understood why this bug was too risky to fix for 2.02 or why it still exists today.

I ended up writing a new driver which we use instead.

https://github.com/esnowberg/grub2-sparc/commit/d802909bc614980dcf6dc2f4484bfa8c2448adf1

This driver would take care of this double open problem making this patch unnecessary. It will also solve many other problems that currently exist in ofdisk. If you would consider this driver in upstream, let me know and I’ll start submitting it.

#9 lore raw

Hi Daniel and Eric!

Is there any progress on these patches?

May I suggest that we continue with the remaining SPARC patches first if there is still disagreement on the patches that have been posted so far?

I fear that this will fall into oblivion again and we continue to be stuck with SILO :(.

Please be assured that the Debian sparc64 porters are very happy to help with any issues that might arise with the patches, be it in the form of testing or helping to fix potential bugs.

Your work is highly appreciated and much anticipated :).

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#10 lore raw
Quoted 3 lines · John Paul Adrian Glaubitz

Hi Daniel and Eric!

Is there any progress on these patches?

Vladimir had some concerns. Sadly he was ill last week and I was going to ping him this one. Vladimir? If he does not voice his opinion I will apply this patch by the end of this week.

Quoted 2 lines

May I suggest that we continue with the remaining SPARC patches first if there is still disagreement on the patches that have been posted so far?

I am OK with that.

Quoted 2 lines

I fear that this will fall into oblivion again and we continue to be stuck with SILO :(.

Unfortunately I am swamped by two internal very pesky bugs and traveling next week. So, if it is possible to post new patches in the second half of November I will be very grateful.

Quoted 3 lines

Please be assured that the Debian sparc64 porters are very happy to help with any issues that might arise with the patches, be it in the form of testing or helping to fix potential bugs.

Great!

Quoted 1 line

Your work is highly appreciated and much anticipated :).

Thanks!

Daniel