Skip to contentSkip to conversation

kexec/fs2dt: Check for NULL pointer in dt_copy_old_root_param()

PATCH Superseded Madhavan Srinivasan 4 participants 4 messages Sep 29, 2016

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kexec/fs2dt: Check for NULL pointer in dt_copy_old_root_param()

In dt_copy_old_root_param(), FILE * returned from fopen is not checked for NULL pointer before passinig to fclose(). This could trigger a segfault. Patch to fix the same.

---
Changelog v1:
- Moved the check right after fopen

 kexec/fs2dt.c | 3 +++
 1 file changed, 3 insertions(+)
kexec/fs2dt.c +3 -0
index 6ed2399759cf..5ba3ec0fa65c 100644
@@ -524,6 +524,9 @@ static void dt_copy_old_root_param(void)
 	strcpy(filename, pathname);
 	strcat(filename, "bootargs");
 	fp = fopen(filename, "r");
+	if (!fp)
+		return;
+
 	if (fp) {
 		if (getline(&last_cmdline, &len, fp) == -1)
 			die("unable to read %s\n", filename);
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

[CC Dave Young]

Quoted 6 lines · Madhavan Srinivasan

In dt_copy_old_root_param(), FILE * returned from fopen is not checked for NULL pointer before passinig to fclose(). This could trigger a segfault. Patch to fix the same.

Probably Dave's tag should be dropped as that was for a somewhat different (though equally trivial) approach.

Quoted 13 lines

---
Changelog v1:
- Moved the check right after fopen

 kexec/fs2dt.c | 3 +++
 1 file changed, 3 insertions(+)
kexec/fs2dt.c +0 -0
index 6ed2399759cf..5ba3ec0fa65c 100644

kexec/fs2dt.c static void dt_copy_old_root_param(void) · line 529

Quoted 6 lines
kexec/fs2dt.c +3 -0
@@ -524,6 +524,9 @@ static void dt_copy_old_root_param(void)
 	strcpy(filename, pathname);
 	strcat(filename, "bootargs");
 	fp = fopen(filename, "r");
+	if (!fp)
+		return;
+

With the (!fp) conditional above the (fp) conditional below can be removed.

Quoted 6 lines
kexec/fs2dt.c +0 -0
 	if (fp) {
 		if (getline(&last_cmdline, &len, fp) == -1)
 			die("unable to read %s\n", filename);
Signature · 1 line
2.7.4

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 8 lines · Simon Horman

[CC Dave Young]

Quoted 5 lines · Madhavan Srinivasan

In dt_copy_old_root_param(), FILE * returned from fopen is not checked for NULL pointer before passinig to fclose(). This could trigger a segfault. Patch to fix the same.

Quoted 4 lines
Quoted 1 line

Probably Dave's tag should be dropped as that was for a somewhat different (though equally trivial) approach.

Simion, I think I'm fine with any of them.

Quoted 9 lines
Quoted 9 lines

---
Changelog v1:
- Moved the check right after fopen

 kexec/fs2dt.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 20 lines

kexec/fs2dt.c static void dt_copy_old_root_param(void) · line 529

Quoted 11 lines
kexec/fs2dt.c +3 -0
index 6ed2399759cf..5ba3ec0fa65c 100644
@@ -524,6 +524,9 @@ static void dt_copy_old_root_param(void)
 	strcpy(filename, pathname);
 	strcat(filename, "bootargs");
 	fp = fopen(filename, "r");
+	if (!fp)
+		return;
+

With the (!fp) conditional above the (fp) conditional below can be removed.

Quoted 6 lines
kexec/fs2dt.c +0 -0
 	if (fp) {
 		if (getline(&last_cmdline, &len, fp) == -1)
 			die("unable to read %s\n", filename);
Signature · 1 line
2.7.4

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Reviewed-by on v2 1/1
#3 lore raw
In reply to Madhavan Srinivasan
Quoted 7 lines · Madhavan Srinivasan

In dt_copy_old_root_param(), FILE * returned from fopen is not checked for NULL pointer before passinig to fclose(). This could trigger a segfault. Patch to fix the same.

Quoted 13 lines

---
Changelog v1:
- Moved the check right after fopen

 kexec/fs2dt.c | 3 +++
 1 file changed, 3 insertions(+)
kexec/fs2dt.c +0 -0
index 6ed2399759cf..5ba3ec0fa65c 100644

kexec/fs2dt.c static void dt_copy_old_root_param(void) · line 532

Quoted 9 lines
kexec/fs2dt.c +3 -0
@@ -524,6 +524,9 @@ static void dt_copy_old_root_param(void)
 	strcpy(filename, pathname);
 	strcat(filename, "bootargs");
 	fp = fopen(filename, "r");
+	if (!fp)
+		return;
+
 	if (fp) {
 		if (getline(&last_cmdline, &len, fp) == -1)
 			die("unable to read %s\n", filename);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec