Skip to contentSkip to conversation

tty: rocket: Fix possible buffer overwrite on register_PCI

PATCH Superseded Anton Vasilyev 3 participants 4 messages Jul 27, 2018 – Sep 18, 2018 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: rocket: Fix possible buffer overwrite on register_PCI

If number of isa and pci boards exceed NUM_BOARDS on the path rp_init()->init_PCI()->register_PCI() then buffer overwrite occurs in register_PCI() on assign rcktpt_io_addr[i].

The patch adds check on upper bound for index of registered board in register_PCI.

Found by Linux Driver Verification project (linuxtesting.org).

---
 drivers/tty/rocket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/rocket.c +1 -1
index bdd17d2aaafd..b121d8f8f3d7 100644
@@ -1881,7 +1881,7 @@ static __init int register_PCI(int i, struct pci_dev *dev)
 	ByteIO_t UPCIRingInd = 0;
 
 	if (!dev || !pci_match_id(rocket_pci_ids, dev) ||
-	    pci_enable_device(dev))
+	    pci_enable_device(dev) || i >= NUM_BOARDS)
 		return 0;
 
 	rcktpt_io_addr[i] = pci_resource_start(dev, 0);
Signature · 1 line
2.18.0
#1 lore raw
Quoted 19 lines · On Fri, 27 Jul 2018 16:39:31 +0300 Anton Vasilyev <[email protected]> wrote:

If number of isa and pci boards exceed NUM_BOARDS on the path rp_init()->init_PCI()->register_PCI() then buffer overwrite occurs in register_PCI() on assign rcktpt_io_addr[i].

The patch adds check on upper bound for index of registered board in register_PCI.

Found by Linux Driver Verification project (linuxtesting.org).

---
 drivers/tty/rocket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/rocket.c +0 -0
index bdd17d2aaafd..b121d8f8f3d7 100644

drivers/tty/rocket.c static __init int register_PCI(int i, struct pci_dev *dev) · line 1887

Quoted 8 lines
drivers/tty/rocket.c +1 -1
@@ -1881,7 +1881,7 @@ static __init int register_PCI(int i, struct pci_dev *dev)
 	ByteIO_t UPCIRingInd = 0;
 
 	if (!dev || !pci_match_id(rocket_pci_ids, dev) ||
-	    pci_enable_device(dev))
+	    pci_enable_device(dev) || i >= NUM_BOARDS)
 		return 0;
 
 	rcktpt_io_addr[i] = pci_resource_start(dev, 0);

This is a real fix but you want to check i >= NUM_BOARDS before you enable the device

Alan

#2 lore raw

PATCH v2 1/1 tty: rocket: Fix possible buffer overwrite on register_PCI

If number of isa and pci boards exceed NUM_BOARDS on the path rp_init()->init_PCI()->register_PCI() then buffer overwrite occurs in register_PCI() on assign rcktpt_io_addr[i].

The patch adds check on upper bound for index of registered board in register_PCI.

Found by Linux Driver Verification project (linuxtesting.org).

---
v2: do not enable device which will not be managed by driver. Based on Alan's comment.

NOTE: I can't find if there is a call of pci_disable_device(), corresponding to pci_enable_device() from register_PCI().

---
 drivers/tty/rocket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/rocket.c +1 -1
index bdd17d2aaafd..f2238dc40426 100644
@@ -1881,7 +1881,7 @@ static __init int register_PCI(int i, struct pci_dev *dev)
 	ByteIO_t UPCIRingInd = 0;
 
 	if (!dev || !pci_match_id(rocket_pci_ids, dev) ||
-	    pci_enable_device(dev))
+	    i >= NUM_BOARDS || pci_enable_device(dev))
 		return 0;
 
 	rcktpt_io_addr[i] = pci_resource_start(dev, 0);
Signature · 1 line
2.18.0
#3 lore raw
Quoted 7 lines · Anton Vasilyev

If number of isa and pci boards exceed NUM_BOARDS on the path rp_init()->init_PCI()->register_PCI() then buffer overwrite occurs in register_PCI() on assign rcktpt_io_addr[i].

The patch adds check on upper bound for index of registered board in register_PCI.

Quoted 6 lines

Found by Linux Driver Verification project (linuxtesting.org).

---
v2: do not enable device which will not be managed by driver. Based on Alan's comment.

This patch doesn't apply to my tree at all :(

Can you rebase and resend?

thanks,

greg k-h