From beca68adfa3abcf889781603ea775342191c32c7 Mon Sep 17 00:00:00 2001 From: Bastien Curutchet Date: Thu, 11 Jul 2024 10:18:37 +0200 Subject: [PATCH] mmc: davinci_mmc: Prevent transmitted data size from exceeding sgm's length BugLink: https://bugs.launchpad.net/bugs/2078289 commit 16198eef11c1929374381d7f6271b4bf6aa44615 upstream. No check is done on the size of the data to be transmiited. This causes a kernel panic when this size exceeds the sg_miter's length. Limit the number of transmitted bytes to sgm->length. Cc: stable@vger.kernel.org Fixes: ed01d210fd91 ("mmc: davinci_mmc: Use sg_miter for PIO") Signed-off-by: Bastien Curutchet Link: https://lore.kernel.org/r/20240711081838.47256-2-bastien.curutchet@bootlin.com Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman Signed-off-by: Portia Stephens Signed-off-by: Stefan Bader --- drivers/mmc/host/davinci_mmc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c index 8fa6796787f4..644e6d38a31c 100644 --- a/drivers/mmc/host/davinci_mmc.c +++ b/drivers/mmc/host/davinci_mmc.c @@ -238,6 +238,9 @@ static void davinci_fifo_data_trans(struct mmc_davinci_host *host, host->buffer_bytes_left -= n; host->bytes_left -= n; + if (n > sgm->length) + n = sgm->length; + /* NOTE: we never transfer more than rw_threshold bytes * to/from the fifo here; there's no I/O overlap. * This also assumes that access width( i.e. ACCWD) is 4 bytes