Skip to contentSkip to conversation

ieee1275: Fix crash in of_path_of_nvme when of_path is empty

PATCH Superseded John Paul Adrian Glaubitz 2 participants 4 messages Mar 1, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ieee1275: Fix crash in of_path_of_nvme when of_path is empty

Hi!

We have recently backported the upstream changes to Debian's grub2 package to support modern SPARC hardware for Debian's sparc64 port.

One of the changes introduced a regression on systems with NVME devices which are not based on Open Firmware. On these systems, find_obppath returns an empty string and trying to append the disk name to that empty name results in a crash in of_path_of_nvme.

Fix that by making sure of_path isn't empty and if it is, just return the disk name in of_path_of_nvme.

Debian bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=891773

Thanks,
Adrian

#1 lore raw

PATCH 1/1 ieee1275: Fix crash in of_path_of_nvme when of_path is empty

The of_path_of_nvme function (commit 2391d57, ieee1275: add nvme support within ofpath) introduced a functional regression:

On systems which are not based on Open Firmware but have at least one NVME device, find_obppath will return an empty path and appending the disk name to of_path will therefore result in a crash. Thus, when of_path is empty, just return the disk name in of_path_of_nvme.

---
 grub-core/osdep/linux/ofpath.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
grub-core/osdep/linux/ofpath.c +6 -1
index 1c30e7233..da0000f0f 100644
@@ -389,8 +389,13 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
     }
 
   of_path = find_obppath (sysfs_path);
+
+  if(of_path)
+    strcat (of_path, disk);
+  else
+    of_path = strdup(disk);
+
   free (sysfs_path);
-  strcat (of_path, disk);
   return of_path;
 }
 
Signature · 1 line
2.16.2
#2 lore raw

Re: Bug#891773: [PATCH] ieee1275: Fix crash in of_path_of_nvme when of_path is empty

Quoted 19 lines · John Paul Adrian Glaubitz

The of_path_of_nvme function (commit 2391d57, ieee1275: add nvme support within ofpath) introduced a functional regression:

On systems which are not based on Open Firmware but have at least one NVME device, find_obppath will return an empty path and appending the disk name to of_path will therefore result in a crash. Thus, when of_path is empty, just return the disk name in of_path_of_nvme.

---
 grub-core/osdep/linux/ofpath.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
grub-core/osdep/linux/ofpath.c +0 -0
index 1c30e7233..da0000f0f 100644

grub-core/osdep/linux/ofpath.c of_path_of_nvme(const char *sys_devname __attribute__((unused)), · line 397

Quoted 9 lines
grub-core/osdep/linux/ofpath.c +6 -0
@@ -389,8 +389,13 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
     }
 
   of_path = find_obppath (sysfs_path);
+
+  if(of_path)
+    strcat (of_path, disk);
+  else
+    of_path = strdup(disk);
+

Whitespace issues aside, should it not be returning NULL if of_path is NULL, like the other users of find_obppath, such as of_path_of_scsi? This should restore the behaviour from before of_path_of_nvme was added, as grub_util_devname_to_ofpath would have previously returned NULL due to the unknown type?

James

Quoted 7 lines
grub-core/osdep/linux/ofpath.c +0 -1
   free (sysfs_path);
-  strcat (of_path, disk);
   return of_path;
 }
 
Signature · 1 line
2.16.2
#3 lore raw

Re: Bug#891773: [PATCH] ieee1275: Fix crash in of_path_of_nvme when of_path is empty

Quoted 2 lines · James Clarke

Whitespace issues aside, should it not be returning NULL if of_path is NULL, like the other users of find_obppath, such as of_path_of_scsi?

Hmm. Good point.

Quoted 3 lines

This should restore the behaviour from before of_path_of_nvme was added, as grub_util_devname_to_ofpath would have previously returned NULL due to the unknown type?

Right. I'll wait for some comments from Daniel and Eric first though.

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