Skip to contentSkip to conversation

ipmi: fix open() NULL argument

PATCH In review Cédric Le Goater 4 participants 10 messages Apr 25, 2017 – Apr 26, 2017

lore
Share & tools
lore
#0 lore raw

cover ipmi: fix open() NULL argument

Hello,

Here is a small series fixing an NULL argument issue in the IPMI BMC simulator and activating the IPMI tests under PPC64.

Thanks,

C.

Cédric Le Goater (2):
tests: add IPMI tests for ppc64
ipmi: don't try to open a NULL filename

 hw/ipmi/ipmi_bmc_sim.c | 5 +++++
 tests/Makefile.include | 2 ++
 2 files changed, 7 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 tests: add IPMI tests for ppc64

---
 tests/Makefile.include | 2 ++
 1 file changed, 2 insertions(+)
tests/Makefile.include +2 -0
index 579ec07cce03..8ff22ccfbdde 100644
@@ -287,6 +287,8 @@ check-qtest-ppc64-y += tests/pnv-xscom-test$(EXESUF)
 check-qtest-ppc64-y += tests/drive_del-test$(EXESUF)
 check-qtest-ppc64-y += tests/postcopy-test$(EXESUF)
 check-qtest-ppc64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-ppc64-y += tests/ipmi-kcs-test$(EXESUF)
+check-qtest-ppc64-y += tests/ipmi-bt-test$(EXESUF)
 check-qtest-ppc64-y += tests/rtas-test$(EXESUF)
 check-qtest-ppc64-y += tests/pxe-test$(EXESUF)
 check-qtest-ppc64-y += tests/usb-hcd-ohci-test$(EXESUF)
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 ipmi: don't try to open a NULL filename

In reply to Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

---
 hw/ipmi/ipmi_bmc_sim.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +5 -0
index 155561d06614..277c28cb40ed 100644
@@ -1899,6 +1899,10 @@ static void ipmi_fru_init(IPMIFru *fru)
     int fsize;
     int size = 0;
 
+    if (!fru->filename) {
+        goto out;
+    }
+
     fsize = get_image_size(fru->filename);
     if (fsize > 0) {
         size = QEMU_ALIGN_UP(fsize, fru->areasize);
@@ -1910,6 +1914,7 @@ static void ipmi_fru_init(IPMIFru *fru)
         }
     }
 
+out:
     if (!fru->data) {
         /* give one default FRU */
         size = fru->areasize;
Signature · 1 line
2.7.4
Reviewed-by on v1 2/2
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

Quoted 2 lines · Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

POSIX doesn't require it to work. Linux is nice and gives you EFAULT, but there are systems where open(NULL) crashes with SIGSEGV. The clang warning is correct.

Quoted 8 lines

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

---
 hw/ipmi/ipmi_bmc_sim.c | 5 +++++
 1 file changed, 5 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

In reply to Cédric Le Goater
Quoted 5 lines · Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

This isn't "new clang", incidentally, it's just clang with the runtime-static-analysis enabled, which causes warnings to be printed at runtime for undefined behaviours. You can enable this by passing configure --extra-cflags=-fsanitize=undefined . (I have clang 3.8.0 here.)

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

Quoted 4 lines · Peter Maydell
Quoted 3 lines · Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

Quoted 8 lines
Quoted 2 lines

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

This isn't "new clang", incidentally, it's just clang with the runtime-static-analysis enabled, which causes warnings to be printed at runtime for undefined behaviours. You can enable this by passing configure --extra-cflags=-fsanitize=undefined . (I have clang 3.8.0 here.)

OK. So I have now reproduced the issue on a f24. That made be realize that the IPMI tests check for the arch they are being run on and that more changes are required for them to run on ppc64.

We can drop patch 1/2. Tell me if you want a resend.

Thanks,

C.

#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

Quoted 14 lines · Cédric Le Goater
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

Quoted 8 lines
Quoted 2 lines

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

This isn't "new clang", incidentally, it's just clang with the runtime-static-analysis enabled, which causes warnings to be printed at runtime for undefined behaviours. You can enable this by passing configure --extra-cflags=-fsanitize=undefined . (I have clang 3.8.0 here.)

Quoted 6 lines

OK. So I have now reproduced the issue on a f24. That made be realize that the IPMI tests check for the arch they are being run on and that more changes are required for them to run on ppc64.

We can drop patch 1/2. Tell me if you want a resend.

No, that's fine. A patch to enable the tests on ppc properly ASAP would be great, though.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

Quoted 20 lines · David Gibson
Quoted 19 lines · Cédric Le Goater
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

Quoted 8 lines
Quoted 2 lines

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

This isn't "new clang", incidentally, it's just clang with the runtime-static-analysis enabled, which causes warnings to be printed at runtime for undefined behaviours. You can enable this by passing configure --extra-cflags=-fsanitize=undefined . (I have clang 3.8.0 here.)

OK. So I have now reproduced the issue on a f24. That made be realize that the IPMI tests check for the arch they are being run on and that more changes are required for them to run on ppc64.

Quoted 4 lines
Quoted 1 line

We can drop patch 1/2. Tell me if you want a resend.

No, that's fine. A patch to enable the tests on ppc properly ASAP would be great, though.

Yes, it would. I need to understand what is behind :

	qtest_irq_intercept_in(...)

C.

#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

In reply to Cédric Le Goater
Quoted 7 lines · Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

Since my ppc-for-2.10 pull request has been held up because of this anyway, tather than just apply this on top, I've folded it into your earlier patch which caused the bug - that way we won't break bisect.

Quoted 27 lines
---
 hw/ipmi/ipmi_bmc_sim.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +5 -0
index 155561d06614..277c28cb40ed 100644
@@ -1899,6 +1899,10 @@ static void ipmi_fru_init(IPMIFru *fru)
     int fsize;
     int size = 0;
 
+    if (!fru->filename) {
+        goto out;
+    }
+
     fsize = get_image_size(fru->filename);
     if (fsize > 0) {
         size = QEMU_ALIGN_UP(fsize, fru->areasize);
@@ -1910,6 +1914,7 @@ static void ipmi_fru_init(IPMIFru *fru)
         }
     }
 
+out:
     if (!fru->data) {
         /* give one default FRU */
         size = fru->areasize;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

Quoted 4 lines · David Gibson
Quoted 3 lines · Cédric Le Goater

Currenlty, the code relies on the fact that open() handles NULL filenames but that can cause an error with new clang:

Quoted 8 lines
Quoted 4 lines

hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1, which is declared to never be null

Since my ppc-for-2.10 pull request has been held up because of this anyway, tather than just apply this on top, I've folded it into your earlier patch which caused the bug - that way we won't break bisect.

Yes that is the best option.

Thanks,

C.