Skip to contentSkip to conversation

mmc: core: Add error check to avoid kernel panic caused by NULL pointer

PATCH In review Corey Gao 2 participants 2 messages Jun 2, 2020 – Jun 16, 2020 MMC, SD and SDIO

lore
Share & tools
lore

Corey Gao

author
#0 lore raw

PATCH 1/1 mmc: core: Add error check to avoid kernel panic caused by NULL pointer

If __mmc_start_req(host, mrq) fails with error, the mrq->cmd->mrq will be NULL. This will cause kernel panic in the following mmc_wait_for_req_done(host, mrq). Add error check to cancle unnecessary mmc_wait_for_req_done(host, mrq) if __mmc_start_req(host, mrq) fails.

---
 drivers/mmc/core/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mmc/core/core.c +4 -2
index 2553d903a82b..b13b484e64aa 100644
@@ -734,9 +734,11 @@ EXPORT_SYMBOL(mmc_start_req);
  */
 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 {
-	__mmc_start_req(host, mrq);
+	int err;
 
-	if (!mrq->cap_cmd_during_tfr)
+	err = __mmc_start_req(host, mrq);
+
+	if (!mrq->cap_cmd_during_tfr && !err)
 		mmc_wait_for_req_done(host, mrq);
 }
 EXPORT_SYMBOL(mmc_wait_for_req);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · Corey Gao

If __mmc_start_req(host, mrq) fails with error, the mrq->cmd->mrq will be NULL. This will cause kernel panic in the following mmc_wait_for_req_done(host, mrq). Add error check to cancle unnecessary mmc_wait_for_req_done(host, mrq) if __mmc_start_req(host, mrq) fails.

The above is a bit hard for me to follow, can you please try to elaborate on the problem. Moreover, please, provide a stack trace, as that is easier to follow for me.

Kind regards
Uffe

Quoted 27 lines
---
 drivers/mmc/core/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mmc/core/core.c +4 -3
index 2553d903a82b..b13b484e64aa 100644
@@ -734,9 +734,11 @@ EXPORT_SYMBOL(mmc_start_req);
  */
 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 {
-       __mmc_start_req(host, mrq);
+       int err;
 
-       if (!mrq->cap_cmd_during_tfr)
+       err = __mmc_start_req(host, mrq);
+
+       if (!mrq->cap_cmd_during_tfr && !err)
                mmc_wait_for_req_done(host, mrq);
 }
 EXPORT_SYMBOL(mmc_wait_for_req);
--

2.17.1