git: bf99b74302bd - main - cam: Fix the mmc_data mapping length for XPT_MMC_IO

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 05 Nov 2026 14:51:53 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=bf99b74302bdeb533a7f89149b0fcd2d9e225dad

commit bf99b74302bdeb533a7f89149b0fcd2d9e225dad
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-10-22 06:33:54 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-05 14:51:31 +0000

    cam: Fix the mmc_data mapping length for XPT_MMC_IO
    
    cam_periph_mapmem() and cam_periph_unmapmem() map the user-provided
    struct mmc_data for XPT_MMC_IO CCBs, but use sizeof(struct mmc_data *)
    instead of sizeof(struct mmc_data) as the length.  Only the pages
    covering a pointer are mapped, so accessing a field past the first
    pointer-sized region (for instance cmd->data->flags) faults if the
    structure happens to straddle a page boundary and the following page is
    not mapped.
    
    The failure is intermittent because it depends on where the caller places
    the struct mmc_data.  Issuing a CMD53 CCB through pass(4) to an MMCCAM
    SDIO card whose struct mmc_data lands at the end of a page panics with
    "data abort in critical section or under mutex" in the host driver.
    
    Map the whole structure in both the map and unmap paths.
    
    MFC after:      1 week
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D61022
---
 sys/cam/cam_periph.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
index 3de3ae327dc9..8f22e08c878a 100644
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -897,7 +897,7 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo,
 			return(0);
 		/* Two mappings: one for cmd->data and one for cmd->data->data */
 		data_ptrs[0] = (unsigned char **)&ccb->mmcio.cmd.data;
-		lengths[0] = sizeof(struct mmc_data *);
+		lengths[0] = sizeof(struct mmc_data);
 		dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK;
 		data_ptrs[1] = (unsigned char **)&ccb->mmcio.cmd.data->data;
 		lengths[1] = ccb->mmcio.cmd.data->len;
@@ -1076,7 +1076,7 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo)
 		break;
 	case XPT_MMC_IO:
 		data_ptrs[0] = (uint8_t **)&ccb->mmcio.cmd.data;
-		lengths[0] = sizeof(struct mmc_data *);
+		lengths[0] = sizeof(struct mmc_data);
 		dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK;
 		data_ptrs[1] = (uint8_t **)&ccb->mmcio.cmd.data->data;
 		lengths[1] = ccb->mmcio.cmd.data->len;