Skip to contentSkip to conversation

ieee1275: Fix crash in of_path_of_nvme when of_path is empty

PATCH New John Paul Adrian Glaubitz 3 participants 4 messages Mar 1, 2018 – Mar 5, 2018

lore
Share & tools
lore
#0 lore raw

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

Hi!

As suggested by James Clarke earlier on this mailing list today, I have modified of_path_of_nvme such that it behaves the same way as of_path_of_scsi and just returns NULL when the call to find_obppath returns NULL.

This makes much more sense than what my previous patch did as we don't want of_path_of_nvme to return anything but NULL when not run on a system not based on Open Firmware.

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 NULL and thus trying to append the disk name to of_path will result in a crash.

The proper behavior of of_path_of_nvme is, however, to just return NULL in such cases, like other users of find_obppath, such as of_path_of_scsi.

---
 grub-core/osdep/linux/ofpath.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
grub-core/osdep/linux/ofpath.c +4 -1
index 1c30e7233..61806212e 100644
@@ -389,8 +389,11 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
     }
 
   of_path = find_obppath (sysfs_path);
+
+  if (of_path)
+    strcat (of_path, disk);
+
   free (sysfs_path);
-  strcat (of_path, disk);
   return of_path;
 }
 
Signature · 1 line
2.16.2
Reviewed-by on v1 1/1
#2 lore raw
Quoted 39 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 NULL and thus trying to append the disk name to of_path will result in a crash.

The proper behavior of of_path_of_nvme is, however, to just return NULL in such cases, like other users of find_obppath, such as of_path_of_scsi.

---
grub-core/osdep/linux/ofpath.c | 5 ++++-

1 file changed, 4 insertions(+), 1 deletion(-)
grub-core/osdep/linux/ofpath.c +4 -1
index 1c30e7233..61806212e 100644
@@ -389,8 +389,11 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
    }
 
  of_path = find_obppath (sysfs_path);
+
+  if (of_path)
+    strcat (of_path, disk);
+
  free (sysfs_path);
-  strcat (of_path, disk);
  return of_path;
 }
 
Signature · 1 line
2.16.2
Applied
#3 lore raw
Quoted 36 lines · Eric Snowberg
Quoted 36 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 NULL and thus trying to append the disk name to of_path will result in a crash.

The proper behavior of of_path_of_nvme is, however, to just return NULL in such cases, like other users of find_obppath, such as of_path_of_scsi.

---
grub-core/osdep/linux/ofpath.c | 5 ++++-

1 file changed, 4 insertions(+), 1 deletion(-)
grub-core/osdep/linux/ofpath.c +4 -1
index 1c30e7233..61806212e 100644
@@ -389,8 +389,11 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
    }
 
  of_path = find_obppath (sysfs_path);
+
+  if (of_path)
+    strcat (of_path, disk);
+
  free (sysfs_path);
-  strcat (of_path, disk);
  return of_path;
 }
 
Quoted 4 lines
Quoted 2 lines

--
2.16.2

Applied. Please CC me next time.

Daniel