svn commit: r331037 - stable/10/sys/dev/mmc

Marius Strobl marius at FreeBSD.org
Thu Mar 15 23:01:08 UTC 2018


Author: marius
Date: Thu Mar 15 23:01:04 2018
New Revision: 331037
URL: https://svnweb.freebsd.org/changeset/base/331037

Log:
  MFC: r327355, r327926
  
  - Don't allow userland to switch partitions; it's next to impossible
    to recover from that, especially when something goes wrong.
  - When userland changes EXT_CSD, update the kernel copy before using
    relevant EXT_CSD bits in mmcsd_switch_part().

Modified:
  stable/10/sys/dev/mmc/mmcsd.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/mmc/mmcsd.c
==============================================================================
--- stable/10/sys/dev/mmc/mmcsd.c	Thu Mar 15 23:01:00 2018	(r331036)
+++ stable/10/sys/dev/mmc/mmcsd.c	Thu Mar 15 23:01:04 2018	(r331037)
@@ -914,6 +914,16 @@ mmcsd_ioctl_cmd(struct mmcsd_part *part, struct mmc_io
 		default:
 			break;
 		}
+		/*
+		 * No partition switching in userland; it's almost impossible
+		 * to recover from that, especially if things go wrong.
+		 */
+		if (cmd.opcode == MMC_SWITCH_FUNC && dp != NULL &&
+		    (((uint8_t *)dp)[EXT_CSD_PART_CONFIG] &
+		    EXT_CSD_PART_CONFIG_ACC_MASK) != part->type) {
+			err = EINVAL;
+			goto out;
+		}
 	}
 	dev = sc->dev;
 	mmcbus = sc->mmcbus;
@@ -934,7 +944,7 @@ mmcsd_ioctl_cmd(struct mmcsd_part *part, struct mmc_io
 	if (part->type == EXT_CSD_PART_CONFIG_ACC_RPMB) {
 		/*
 		 * If the request went to the RPMB partition, try to ensure
-		 * that the command actually has completed ...
+		 * that the command actually has completed.
 		 */
 		retries = MMCSD_CMD_RETRIES;
 		do {
@@ -946,13 +956,6 @@ mmcsd_ioctl_cmd(struct mmcsd_part *part, struct mmc_io
 				break;
 			DELAY(1000);
 		} while (retries-- > 0);
-
-switch_back:
-		/* ... and always switch back to the default partition. */
-		err = mmcsd_switch_part(mmcbus, dev, rca,
-		    EXT_CSD_PART_CONFIG_ACC_DEFAULT);
-		if (err != MMC_ERR_NONE)
-			goto release;
 	}
 	/*
 	 * If EXT_CSD was changed, our copy is outdated now.  Specifically,
@@ -961,6 +964,17 @@ switch_back:
 	 */
 	if (cmd.opcode == MMC_SWITCH_FUNC) {
 		err = mmc_send_ext_csd(mmcbus, dev, sc->ext_csd);
+		if (err != MMC_ERR_NONE)
+			goto release;
+	}
+switch_back:
+	if (part->type == EXT_CSD_PART_CONFIG_ACC_RPMB) {
+		/*
+		 * If the request went to the RPMB partition, always switch
+		 * back to the default partition (see mmcsd_switch_part()).
+		 */
+		err = mmcsd_switch_part(mmcbus, dev, rca,
+		    EXT_CSD_PART_CONFIG_ACC_DEFAULT);
 		if (err != MMC_ERR_NONE)
 			goto release;
 	}


More information about the svn-src-stable mailing list