mmc: core: Fix null pointer dereference in bus_shutdown
A message that is not in the archive (sent off-list or not yet received): CGME20240119073011epcas1p1841e79c8f673c3c69ef696edc9eb47b0@epcas1p1.samsung.com
PATCH 1/1 mmc: core: Fix null pointer dereference in bus_shutdown
When shutting down removable device, it can be occurred null pointer dereference.
To prevent null pointer dereference,
At first, check null pointer.
Next, block rescan worker to scan removable device during shutdown.
--- drivers/mmc/core/bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mmc/core/bus.c +9 -1
@@ -143,9 +143,17 @@ static void mmc_bus_shutdown(struct device *dev) {struct mmc_driver *drv =to_mmc_driver (dev->driver);struct mmc_card *card =mmc_dev_to_card (dev); -struct mmc_host *host = card->host; +struct mmc_host *host;int ret; +if (!drv || !card) { +pr_debug ("%s: drv or card is NULL.\n" ,dev_name (dev)); +return ; + } + + host = card->host; + host->rescan_disable =1 ; +if (dev->driver && drv->shutdown) drv->shutdown (card);
Signature · 1 line
2.29.0
Quoted 2 lines · Seunghui Lee
When shutting down removable device, it can be occurred null pointer dereference.
How?
And please wrap your lines properly.
Quoted 3 lines
To prevent null pointer dereference,
At first, check null pointer.
Next, block rescan worker to scan removable device during shutdown.
Why do two things?
Quoted 11 lines
Signed-off-by Seunghui Lee <[email protected]>--- drivers/mmc/core/bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/mmc/core/bus.c +0
-0
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 150
Quoted 9 lines
drivers/mmc/core/bus.c +3
-1@@ -143,9 +143,17 @@ static void mmc_bus_shutdown(struct device *dev) {struct mmc_driver *drv =to_mmc_driver (dev->driver);struct mmc_card *card =mmc_dev_to_card (dev); -struct mmc_host *host = card->host; +struct mmc_host *host;int ret; +if (!drv || !card) { +pr_debug ("%s: drv or card is NULL.\n" ,dev_name (dev));
What is this going to help with? And why not use dev_dbg()?
How can drv ever be NULL? That looks impossible to me based on just the code shown here.
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 154
Quoted 4 lines
drivers/mmc/core/bus.c +4
-0+return ; + } + + host = card->host;
Why is this change needed? This line can go back to the top just fine, right?
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 155
Quoted 1 line
drivers/mmc/core/bus.c +1
-0+ host->rescan_disable =1 ;
Shouldn't this be a separate change? And what happens if the check for this is right before you set it? Where is the locking to prevent the issue you are attempting to solve?
thanks,
greg k-h
Quoted 66 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Friday, January 19, 2024 5:21 PM
To: Seunghui Lee <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mmc: core: Fix null pointer dereference inbus_shutdownQuoted 2 lines · Seunghui Lee
When shutting down removable device, it can be occurred null pointer dereference.
How?
And please wrap your lines properly.
Quoted 3 lines
To prevent null pointer dereference,
At first, check null pointer.
Next, block rescan worker to scan removable device during shutdown.Why do two things?
Quoted 11 lines
Signed-off-by Seunghui Lee <[email protected]>--- drivers/mmc/core/bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/mmc/core/bus.c index renamed from drivers/mmc/core/bus.c +0
-0
0af96548e7da..4f370a6577aa100644drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 150
Quoted 9 lines
drivers/mmc/core/bus.c +3
-1@@ -143,9 +143,17 @@ static void mmc_bus_shutdown(struct device *dev) {struct mmc_driver *drv =to_mmc_driver (dev->driver);struct mmc_card *card =mmc_dev_to_card (dev); -struct mmc_host *host = card->host; +struct mmc_host *host;int ret; +if (!drv || !card) { +pr_debug ("%s: drv or card is NULL.\n" ,dev_name (dev));What is this going to help with? And why not use
dev_dbg()?How can drv ever be NULL? That looks impossible to me based on just the code shown here.
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 154
Quoted 4 lines
drivers/mmc/core/bus.c +4
-0+return ; + } + + host = card->host;Why is this change needed? This line can go back to the top just fine, right?
drivers/mmc/core/bus.c static void mmc_bus_shutdown(struct device *dev) · line 155
Quoted 1 line
drivers/mmc/core/bus.c +1
-0+ host->rescan_disable =1 ;Shouldn't this be a separate change? And what happens if the check for this is right before you set it? Where is the locking to prevent the issue you are attempting to solve?
Quoted 3 lines
thanks,
greg k-h
I've checked the issue again. This patch is not the proper solution. I'll reject this patch.
Hi, Thank you for your comment.