can: sja1000: fix use after free in ems_pcmcia_add_card()
Subsystems (4)
PATCH v2 1/1 can: sja1000: fix use after free in ems_pcmcia_add_card()
If the last channel is not available then "dev" is freed. Fortunately, we can just use "pdev->irq" instead.
---
v2: In the first version, I just failed the probe. Sorry about that.
drivers/net/can/sja1000/ems_pcmcia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/sja1000/ems_pcmcia.c +1 -1
@@ -234,7 +234,7 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)free_sja1000dev (dev); } - err =request_irq (dev->irq, &ems_pcmcia_interrupt,IRQF_SHARED , + err =request_irq (pdev->irq, &ems_pcmcia_interrupt,IRQF_SHARED ,DRV_NAME , card);if (!err)return 0 ;
Signature · 1 line
2.20.1
Hello Dan,
Quoted 2 lines · Dan Carpenter
If the last channel is not available then "dev" is freed. Fortunately, we can just use "
pdev->irq" instead.
But in the case that we do not find any channel the irq for the card is still requested (via pdev->irq).
Quoted 14 lines
Fixes fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card")Signed-off-by Dan Carpenter <[email protected]>---
v2: In the first version, I just failed the probe. Sorry about that.drivers/net/can/sja1000/ems_pcmcia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/can/sja1000/ems_pcmcia.c +0
-0
drivers/net/can/sja1000/ems_pcmcia.c static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base) · line 237
Quoted 4 lines
drivers/net/can/sja1000/ems_pcmcia.c +0
-1@@ -234,7 +234,7 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)free_sja1000dev (dev); } - err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
When adding this check, we should be fine:
+ if (card->channels)
drivers/net/can/sja1000/ems_pcmcia.c static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base) · line 240
Quoted 5 lines
drivers/net/can/sja1000/ems_pcmcia.c +1
-0+ err =request_irq (pdev->irq, &ems_pcmcia_interrupt,IRQF_SHARED ,DRV_NAME , card);if (!err)return 0 ;
Thanks for checking this code after so many years!
I saved that 17 year old EMS PCMCIA Card from my former CAN hardware box two weeks ago and made a 5.16-rc2 run on a 2006 Samsung X20 with Pentium M 1.7GHz yesterday. My only machine here at home with a PCMCIA slot :-D
https://www.amazon.de/Samsung-Centrino-1-73GHz-Graphic-Accelerator/dp/B000AXSIRE
And it still works with the CAN card!
Best regards,
Oliver
Quoted 29 lines · Oliver Hartkopp
Hello Dan,
Quoted 2 lines · Dan Carpenter
If the last channel is not available then "dev" is freed. Fortunately, we can just use "
pdev->irq" instead.But in the case that we do not find any channel the irq for the card is still requested (via
pdev->irq).Quoted 14 lines
Fixes fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card")Signed-off-by Dan Carpenter <[email protected]>---
v2: In the first version, I just failed the probe. Sorry about that.drivers/net/can/sja1000/ems_pcmcia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/can/sja1000/ems_pcmcia.c +0
-0drivers/net/can/sja1000/ems_pcmcia.c static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base) · line 236
Quoted 3 lines
drivers/net/can/sja1000/ems_pcmcia.c +0
-1@@ -234,7 +234,7 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)free_sja1000dev (dev); } - err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,When adding this check, we should be fine:
Review
Quoted 1 line
(quoted diff) +1
-0+ if (card->channels)
Sure, I will send a v3 with that.
regards,
dan carpenter
Oliver Hartkopp
Tested-byQuoted 30 lines · Dan Carpenter
Quoted 29 lines · Oliver Hartkopp
Hello Dan,
Quoted 2 lines · Dan Carpenter
If the last channel is not available then "dev" is freed. Fortunately, we can just use "
pdev->irq" instead.But in the case that we do not find any channel the irq for the card is still requested (via
pdev->irq).Quoted 14 lines
Fixes fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card")Signed-off-by Dan Carpenter <[email protected]>---
v2: In the first version, I just failed the probe. Sorry about that.drivers/net/can/sja1000/ems_pcmcia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/can/sja1000/ems_pcmcia.c +0
-0drivers/net/can/sja1000/ems_pcmcia.c static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base) · line 236
Quoted 3 lines
drivers/net/can/sja1000/ems_pcmcia.c +0
-1@@ -234,7 +234,7 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)free_sja1000dev (dev); } - err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,When adding this check, we should be fine:
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ if (card->channels)Sure, I will send a v3 with that.
With these discussed changes you might directly add my
Thanks,
Oliver