Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Mar 2018 23:01:00 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r331036 - stable/11/sys/dev/mmc
Message-ID:  <201803152301.w2FN101m072259@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Thu Mar 15 23:01:00 2018
New Revision: 331036
URL: https://svnweb.freebsd.org/changeset/base/331036

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/11/sys/dev/mmc/mmcsd.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/mmc/mmcsd.c
==============================================================================
--- stable/11/sys/dev/mmc/mmcsd.c	Thu Mar 15 22:58:34 2018	(r331035)
+++ stable/11/sys/dev/mmc/mmcsd.c	Thu Mar 15 23:01:00 2018	(r331036)
@@ -916,6 +916,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;
@@ -936,7 +946,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 {
@@ -948,13 +958,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,
@@ -963,6 +966,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;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803152301.w2FN101m072259>