mmc: core: Fix NULL ptr crash from mmc_should_fail_request [Linux 5.0]

mmc: core: Fix NULL ptr crash from mmc_should_fail_request [Linux 5.0]

This Linux kernel change "mmc: core: Fix NULL ptr crash from mmc_should_fail_request" is included in the Linux 5.0 release. This change is authored by Ritesh Harjani <riteshh [at] codeaurora.org> on Fri Feb 22 19:21:34 2019 +0530. The commit for this change in Linux stable tree is e5723f9 (patch).

mmc: core: Fix NULL ptr crash from mmc_should_fail_request

In case of CQHCI, mrq->cmd may be NULL for data requests (non DCMD).
In such case mmc_should_fail_request is directly dereferencing
mrq->cmd while cmd is NULL.
Fix this by checking for mrq->cmd pointer.

Fixes: 72a5af554df8 ("mmc: core: Add support for handling CQE requests")
Signed-off-by: Ritesh Harjani <[email protected]rg>
Cc: [email protected]
Signed-off-by: Ulf Hansson <[email protected]>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/mmc/core/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 5bd58b9..b27a1e6 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -95,7 +95,7 @@ static void mmc_should_fail_request(struct mmc_host *host,
    if (!data)
        return;

-   if (cmd->error || data->error ||
+   if ((cmd && cmd->error) || data->error ||
        !should_fail(&host->fail_mmc_request, data->blksz * data->blocks))
        return;

Leave a Reply

Your email address will not be published. Required fields are marked *