Commit 35c9bfa5 authored by Gabriel Krisman Bertazi's avatar Gabriel Krisman Bertazi Committed by Greg Kroah-Hartman

8250_pci: Fix potential use-after-free in error path

commit c130b666 upstream.

Commit f209fa03 ("serial: 8250_pci: Detach low-level driver during
PCI error recovery") introduces a potential use-after-free in case the
pciserial_init_ports call in serial8250_io_resume fails, which may
happen if a memory allocation fails or if the .init quirk failed for
whatever reason).  If this happen, further pci_get_drvdata will return a
pointer to freed memory.

This patch reworks the PCI recovery resume hook to restore the old priv
structure in this case, which should be ok, since the ports were already
detached. Such error during recovery causes us to give up on the
recovery.

Fixes: f209fa03 ("serial: 8250_pci: Detach low-level driver during PCI error recovery")
Reported-by: default avatarMichal Suchanek <msuchanek@suse.com>
Signed-off-by: default avatarGabriel Krisman Bertazi <krisman@linux.vnet.ibm.com>
Signed-off-by: default avatarGuilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6f81dea4
...@@ -5850,17 +5850,15 @@ static pci_ers_result_t serial8250_io_slot_reset(struct pci_dev *dev) ...@@ -5850,17 +5850,15 @@ static pci_ers_result_t serial8250_io_slot_reset(struct pci_dev *dev)
static void serial8250_io_resume(struct pci_dev *dev) static void serial8250_io_resume(struct pci_dev *dev)
{ {
struct serial_private *priv = pci_get_drvdata(dev); struct serial_private *priv = pci_get_drvdata(dev);
const struct pciserial_board *board; struct serial_private *new;
if (!priv) if (!priv)
return; return;
board = priv->board; new = pciserial_init_ports(dev, priv->board);
kfree(priv); if (!IS_ERR(new)) {
priv = pciserial_init_ports(dev, board); pci_set_drvdata(dev, new);
kfree(priv);
if (!IS_ERR(priv)) {
pci_set_drvdata(dev, priv);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment