hw/ipmi: Fix realize() error API violations

isa_ipmi_bt_realize(), ipmi_isa_realize(), pci_ipmi_bt_realize(), and
pci_ipmi_kcs_realize() dereference @errp when IPMIInterfaceClass
method init() fails.  That's wrong; see the big comment in error.h.
Introduced in commit 0719029c47 "ipmi: Add an ISA KCS low-level
interface", then imitated in commit a9b74079cb "ipmi: Add a BT
low-level interface" and commit 12f983c6aa "ipmi: Add PCI IPMI
interfaces".

No caller actually passes null.

Fix anyway: splice in a local Error *err, and error_propagate().

Cc: Corey Minyard <cminyard@mvista.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20191204093625.14836-9-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2019-12-04 10:36:15 +01:00
parent bc0e339b01
commit f6166a4da5
4 changed files with 18 additions and 8 deletions

View file

@ -70,6 +70,7 @@ static void isa_ipmi_bt_lower_irq(IPMIBT *ib)
static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
{
Error *err = NULL;
ISADevice *isadev = ISA_DEVICE(dev);
ISAIPMIBTDevice *iib = ISA_IPMI_BT(dev);
IPMIInterface *ii = IPMI_INTERFACE(dev);
@ -85,9 +86,11 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp)
iib->bt.bmc->intf = ii;
iib->bt.opaque = iib;
iic->init(ii, 0, errp);
if (*errp)
iic->init(ii, 0, &err);
if (err) {
error_propagate(errp, err);
return;
}
if (iib->isairq > 0) {
isa_init_irq(isadev, &iib->irq, iib->isairq);

View file

@ -69,6 +69,7 @@ static void isa_ipmi_kcs_lower_irq(IPMIKCS *ik)
static void ipmi_isa_realize(DeviceState *dev, Error **errp)
{
Error *err = NULL;
ISADevice *isadev = ISA_DEVICE(dev);
ISAIPMIKCSDevice *iik = ISA_IPMI_KCS(dev);
IPMIInterface *ii = IPMI_INTERFACE(dev);
@ -84,9 +85,11 @@ static void ipmi_isa_realize(DeviceState *dev, Error **errp)
iik->kcs.bmc->intf = ii;
iik->kcs.opaque = iik;
iic->init(ii, 0, errp);
if (*errp)
iic->init(ii, 0, &err);
if (err) {
error_propagate(errp, err);
return;
}
if (iik->isairq > 0) {
isa_init_irq(isadev, &iik->irq, iik->isairq);

View file

@ -54,6 +54,7 @@ static void pci_ipmi_lower_irq(IPMIBT *ik)
static void pci_ipmi_bt_realize(PCIDevice *pd, Error **errp)
{
Error *err = NULL;
PCIIPMIBTDevice *pik = PCI_IPMI_BT(pd);
IPMIInterface *ii = IPMI_INTERFACE(pd);
IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
@ -74,8 +75,9 @@ static void pci_ipmi_bt_realize(PCIDevice *pd, Error **errp)
pik->bt.raise_irq = pci_ipmi_raise_irq;
pik->bt.lower_irq = pci_ipmi_lower_irq;
iic->init(ii, 8, errp);
if (*errp) {
iic->init(ii, 8, &err);
if (err) {
error_propagate(errp, err);
return;
}
pci_register_bar(pd, 0, PCI_BASE_ADDRESS_SPACE_IO, &pik->bt.io);

View file

@ -54,6 +54,7 @@ static void pci_ipmi_lower_irq(IPMIKCS *ik)
static void pci_ipmi_kcs_realize(PCIDevice *pd, Error **errp)
{
Error *err = NULL;
PCIIPMIKCSDevice *pik = PCI_IPMI_KCS(pd);
IPMIInterface *ii = IPMI_INTERFACE(pd);
IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii);
@ -74,8 +75,9 @@ static void pci_ipmi_kcs_realize(PCIDevice *pd, Error **errp)
pik->kcs.raise_irq = pci_ipmi_raise_irq;
pik->kcs.lower_irq = pci_ipmi_lower_irq;
iic->init(ii, 8, errp);
if (*errp) {
iic->init(ii, 8, &err);
if (err) {
error_propagate(errp, err);
return;
}
pci_register_bar(pd, 0, PCI_BASE_ADDRESS_SPACE_IO, &pik->kcs.io);