Skip to contentSkip to conversation

mmc: arm_pl180: Limit data transfer to U16_MAX

PATCH Superseded [email protected] 3 participants 8 messages Feb 27, 2024 – Apr 15, 2024 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: arm_pl180: Limit data transfer to U16_MAX

From: max <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
---
 drivers/mmc/arm_pl180_mmci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mmc/arm_pl180_mmci.c +11 -0
index 5cf5502ed5..af2f9a5a84 100644
@@ -231,6 +231,7 @@ static int do_data_transfer(struct mmc *dev,
 	u32 blksz = 0;
 	u32 data_ctrl = 0;
 	u32 data_len = (u32) (data->blocks * data->blocksize);
+	assert(data_len < U16_MAX); // should be ensured by arm_pl180_get_b_max
 
 	if (!host->version2) {
 		blksz = (ffs(data->blocksize) - 1);
@@ -358,6 +359,14 @@ static int  host_set_ios(struct mmc *dev)
 	return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct mmc *mmc = upriv->mmc;
+
+	return U16_MAX / mmc->read_bl_len;
+}
+
 #ifndef CONFIG_DM_MMC
 /* MMC uses open drain drivers in the enumeration phase */
 static int mmc_host_reset(struct mmc *dev)
@@ -373,6 +382,7 @@ static const struct mmc_ops arm_pl180_mmci_ops = {
 	.send_cmd = host_request,
 	.set_ios = host_set_ios,
 	.init = mmc_host_reset,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 /*
@@ -531,6 +541,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
 	.send_cmd = dm_host_request,
 	.set_ios = dm_host_set_ios,
 	.get_cd = dm_mmc_getcd,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
Signature · 1 line
2.43.0
#1 lore raw

Quick reminder:
Can anyone help to review this?
Thanks!

Best Regards,
*Lean Sheng Tan*

9elements GmbH, Kortumstraße 19-21, 44787 Bochum, Germany
Email: [email protected]
Phone: *+49 234 68 94 188 <+492346894188>*
Mobile: *+49 176 76 113842 <+4917676113842>*

Registered office: Bochum
Commercial register: Amtsgericht Bochum, HRB 17519
Management: Sebastian German, Eray Bazaar

Data protection information according to Art. 13 GDPR
<https://9elements.com/privacy>

Quoted 68 lines · On Tue, 27 Feb 2024 at 22:02, <[email protected]> wrote:

From: max <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
---
 drivers/mmc/arm_pl180_mmci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mmc/arm_pl180_mmci.c +1 -0
index 5cf5502ed5..af2f9a5a84 100644
@@ -231,6 +231,7 @@ static int do_data_transfer(struct mmc *dev,
        u32 blksz = 0;
        u32 data_ctrl = 0;
        u32 data_len = (u32) (data->blocks * data->blocksize);
+       assert(data_len < U16_MAX); // should be ensured by

arm_pl180_get_b_max

        if (!host->version2) {
                blksz = (ffs(data->blocksize) - 1);
drivers/mmc/arm_pl180_mmci.c +8 -0
@@ -358,6 +359,14 @@ static int  host_set_ios(struct mmc *dev)
        return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t
 blkcnt)
+{
+       struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+       struct mmc *mmc = upriv->mmc;
+
+       return U16_MAX / mmc->read_bl_len;
+}
+
 #ifndef CONFIG_DM_MMC
 /* MMC uses open drain drivers in the enumeration phase */

static int mmc_host_reset(struct mmc *dev)

drivers/mmc/arm_pl180_mmci.c +2 -1
@@ -373,6 +382,7 @@ static const struct mmc_ops arm_pl180_mmci_ops = {
        .send_cmd = host_request,
        .set_ios = host_set_ios,
        .init = mmc_host_reset,
+       .get_b_max = arm_pl180_get_b_max,
 };
 
 /*
@@ -531,6 +541,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
        .send_cmd = dm_host_request,
        .set_ios = dm_host_set_ios,
        .get_cd = dm_mmc_getcd,
+       .get_b_max = arm_pl180_get_b_max,
 };
 
 static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
--

2.43.0

#2 lore raw

+ @Simon

Best Regards,
*Lean Sheng Tan*

9elements GmbH, Kortumstraße 19-21, 44787 Bochum, Germany
Email: [email protected]
Phone: *+49 234 68 94 188 <+492346894188>*
Mobile: *+49 176 76 113842 <+4917676113842>*

Registered office: Bochum
Commercial register: Amtsgericht Bochum, HRB 17519
Management: Sebastian German, Eray Bazaar

Data protection information according to Art. 13 GDPR
<https://9elements.com/privacy>

Quoted 93 lines · Lean Sheng Tan

Quick reminder:
Can anyone help to review this?
Thanks!

Best Regards,
*Lean Sheng Tan*

9elements GmbH, Kortumstraße 19-21, 44787 Bochum, Germany
Email: [email protected]
Phone: *+49 234 68 94 188 <+492346894188>*
Mobile: *+49 176 76 113842 <+4917676113842>*

Registered office: Bochum
Commercial register: Amtsgericht Bochum, HRB 17519
Management: Sebastian German, Eray Bazaar

Data protection information according to Art. 13 GDPR
<https://9elements.com/privacy>

Quoted 69 lines · On Tue, 27 Feb 2024 at 22:02, <[email protected]> wrote:

From: max <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
---
 drivers/mmc/arm_pl180_mmci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mmc/arm_pl180_mmci.c +1 -0
index 5cf5502ed5..af2f9a5a84 100644
@@ -231,6 +231,7 @@ static int do_data_transfer(struct mmc *dev,
        u32 blksz = 0;
        u32 data_ctrl = 0;
        u32 data_len = (u32) (data->blocks * data->blocksize);
+       assert(data_len < U16_MAX); // should be ensured by

arm_pl180_get_b_max

        if (!host->version2) {
                blksz = (ffs(data->blocksize) - 1);
drivers/mmc/arm_pl180_mmci.c +8 -0
@@ -358,6 +359,14 @@ static int  host_set_ios(struct mmc *dev)
        return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t
 blkcnt)
+{
+       struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+       struct mmc *mmc = upriv->mmc;
+
+       return U16_MAX / mmc->read_bl_len;
+}
+
 #ifndef CONFIG_DM_MMC
 /* MMC uses open drain drivers in the enumeration phase */

static int mmc_host_reset(struct mmc *dev)

drivers/mmc/arm_pl180_mmci.c +2 -0
@@ -373,6 +382,7 @@ static const struct mmc_ops arm_pl180_mmci_ops = {
        .send_cmd = host_request,
        .set_ios = host_set_ios,
        .init = mmc_host_reset,
+       .get_b_max = arm_pl180_get_b_max,
 };
 
 /*
@@ -531,6 +541,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops =
 {
        .send_cmd = dm_host_request,
        .set_ios = dm_host_set_ios,
        .get_cd = dm_mmc_getcd,
+       .get_b_max = arm_pl180_get_b_max,
 };
 

static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
--
2.43.0

#3 lore raw
In reply to [email protected]

Hi,

Quoted 5 lines · On 2/28/24 05:18, [email protected] wrote:

From: max <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

Quoted 8 lines

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

Could you add your full name as Signed-off's tag?

Quoted 11 lines
Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
---
 drivers/mmc/arm_pl180_mmci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mmc/arm_pl180_mmci.c +0 -0
index 5cf5502ed5..af2f9a5a84 100644

drivers/mmc/arm_pl180_mmci.c static int do_data_transfer(struct mmc *dev, · line 234

Quoted 4 lines
drivers/mmc/arm_pl180_mmci.c +1 -0
@@ -231,6 +231,7 @@ static int do_data_transfer(struct mmc *dev,
 	u32 blksz = 0;
 	u32 data_ctrl = 0;
 	u32 data_len = (u32) (data->blocks * data->blocksize);
+	assert(data_len < U16_MAX); // should be ensured by arm_pl180_get_b_max

Add the comment at above with "/* ... */"

/* Should be ensured by arm_pl180_get_b_max */
assert(data_len < U16_MAX);

Best Regards,
Jaehoon Chung

Quoted 34 lines
drivers/mmc/arm_pl180_mmci.c +10 -0
 	if (!host->version2) {
 		blksz = (ffs(data->blocksize) - 1);
@@ -358,6 +359,14 @@ static int  host_set_ios(struct mmc *dev)
 	return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct mmc *mmc = upriv->mmc;
+
+	return U16_MAX / mmc->read_bl_len;
+}
+
 #ifndef CONFIG_DM_MMC
 /* MMC uses open drain drivers in the enumeration phase */
 static int mmc_host_reset(struct mmc *dev)
@@ -373,6 +382,7 @@ static const struct mmc_ops arm_pl180_mmci_ops = {
 	.send_cmd = host_request,
 	.set_ios = host_set_ios,
 	.init = mmc_host_reset,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 /*
@@ -531,6 +541,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
 	.send_cmd = dm_host_request,
 	.set_ios = dm_host_set_ios,
 	.get_cd = dm_mmc_getcd,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
#4 lore raw

PATCH v2 1/1 mmc: arm_pl180: Limit data transfer to U16_MAX

In reply to [email protected]

From: Maximilian Brune <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

---
 drivers/mmc/arm_pl180_mmci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mmc/arm_pl180_mmci.c +11 -0
index 5cf5502ed5..cad73ea106 100644
@@ -231,6 +231,7 @@ static int do_data_transfer(struct mmc *dev,
 	u32 blksz = 0;
 	u32 data_ctrl = 0;
 	u32 data_len = (u32) (data->blocks * data->blocksize);
+	assert(data_len < U16_MAX); /* should be ensured by arm_pl180_get_b_max */
 
 	if (!host->version2) {
 		blksz = (ffs(data->blocksize) - 1);
@@ -358,6 +359,14 @@ static int  host_set_ios(struct mmc *dev)
 	return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct mmc *mmc = upriv->mmc;
+
+	return U16_MAX / mmc->read_bl_len;
+}
+
 #ifndef CONFIG_DM_MMC
 /* MMC uses open drain drivers in the enumeration phase */
 static int mmc_host_reset(struct mmc *dev)
@@ -373,6 +382,7 @@ static const struct mmc_ops arm_pl180_mmci_ops = {
 	.send_cmd = host_request,
 	.set_ios = host_set_ios,
 	.init = mmc_host_reset,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 /*
@@ -531,6 +541,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
 	.send_cmd = dm_host_request,
 	.set_ios = dm_host_set_ios,
 	.get_cd = dm_mmc_getcd,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
Signature · 1 line
2.44.0
Reviewed-by on v2 1/1
#5 lore raw

Hi,

Quoted 13 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, April 4, 2024 3:58 PM
To: [email protected]
Cc: Maximilian Brune <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>
Subject: [PATCH v2] mmc: arm_pl180: Limit data transfer to U16_MAX

From: Maximilian Brune <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

Quoted 8 lines

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

Best Regards,
Jaehoon Chung

Quoted 51 lines
Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
---
 drivers/mmc/arm_pl180_mmci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/mmc/arm_pl180_mmci.c +11 -1
index 5cf5502ed5..cad73ea106 100644
@@ -231,6 +231,7 @@ static int do_data_transfer(struct mmc *dev,
 	u32 blksz = 0;
 	u32 data_ctrl = 0;
 	u32 data_len = (u32) (data->blocks * data->blocksize);
+	assert(data_len < U16_MAX); /* should be ensured by arm_pl180_get_b_max */
 
 	if (!host->version2) {
 		blksz = (ffs(data->blocksize) - 1);
@@ -358,6 +359,14 @@ static int  host_set_ios(struct mmc *dev)
 	return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct mmc *mmc = upriv->mmc;
+
+	return U16_MAX / mmc->read_bl_len;
+}
+
 #ifndef CONFIG_DM_MMC
 /* MMC uses open drain drivers in the enumeration phase */
 static int mmc_host_reset(struct mmc *dev)
@@ -373,6 +382,7 @@ static const struct mmc_ops arm_pl180_mmci_ops = {
 	.send_cmd = host_request,
 	.set_ios = host_set_ios,
 	.init = mmc_host_reset,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 /*
@@ -531,6 +541,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
 	.send_cmd = dm_host_request,
 	.set_ios = dm_host_set_ios,
 	.get_cd = dm_mmc_getcd,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
--

2.44.0

#6 lore raw

PATCH v2 1/1 mmc: arm_pl180: Limit data transfer to U16_MAX

In reply to [email protected]

From: Maximilian Brune <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

---
 drivers/mmc/arm_pl180_mmci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mmc/arm_pl180_mmci.c +10 -0
index 2666b65362..cecc7ad783 100644
@@ -229,6 +229,7 @@ static int do_data_transfer(struct mmc *dev,
 	u32 blksz = 0;
 	u32 data_ctrl = 0;
 	u32 data_len = (u32) (data->blocks * data->blocksize);
+	assert(data_len < U16_MAX); /* should be ensured by arm_pl180_get_b_max */
 
 	if (!host->version2) {
 		blksz = (ffs(data->blocksize) - 1);
@@ -356,6 +357,14 @@ static int  host_set_ios(struct mmc *dev)
 	return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct mmc *mmc = upriv->mmc;
+
+	return U16_MAX / mmc->read_bl_len;
+}
+
 static void arm_pl180_mmc_init(struct pl180_mmc_host *host)
 {
 	u32 sdi_u32;
@@ -470,6 +479,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
 	.send_cmd = dm_host_request,
 	.set_ios = dm_host_set_ios,
 	.get_cd = dm_mmc_getcd,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
Signature · 1 line
2.44.0
Reviewed-by on v2 1/1
#7 lore raw
Quoted 15 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Monday, April 15, 2024 6:53 PM
To: [email protected]
Cc: Maximilian Brune <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>
Subject: [PATCH v2] mmc: arm_pl180: Limit data transfer to U16_MAX

From: Maximilian Brune <[email protected]>

Currently fetching files bigger that cause a data transfer greater than U16_MAX fails.

Quoted 8 lines

The reason is that the specification defines the datalength register as a 16 bit wide register, but in u-boot it is used as if it is an 32 bit register. Therefore values greater than U16_MAX cause an infinite loop inside u-boot. U-boot expects to get more data from interface/hardware then it will ever get and therefore inifintely waits for more data that will never come.

Best Regards,
Jaehoon Chung

Quoted 43 lines
Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
---
 drivers/mmc/arm_pl180_mmci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mmc/arm_pl180_mmci.c +10 -1
index 2666b65362..cecc7ad783 100644
@@ -229,6 +229,7 @@ static int do_data_transfer(struct mmc *dev,
 	u32 blksz = 0;
 	u32 data_ctrl = 0;
 	u32 data_len = (u32) (data->blocks * data->blocksize);
+	assert(data_len < U16_MAX); /* should be ensured by arm_pl180_get_b_max */
 
 	if (!host->version2) {
 		blksz = (ffs(data->blocksize) - 1);
@@ -356,6 +357,14 @@ static int  host_set_ios(struct mmc *dev)
 	return 0;
 }
 
+static int arm_pl180_get_b_max(struct udevice *dev, void *dst, lbaint_t blkcnt)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct mmc *mmc = upriv->mmc;
+
+	return U16_MAX / mmc->read_bl_len;
+}
+
 static void arm_pl180_mmc_init(struct pl180_mmc_host *host)
 {
 	u32 sdi_u32;
@@ -470,6 +479,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
 	.send_cmd = dm_host_request,
 	.set_ios = dm_host_set_ios,
 	.get_cd = dm_mmc_getcd,
+	.get_b_max = arm_pl180_get_b_max,
 };
 
 static int arm_pl180_mmc_of_to_plat(struct udevice *dev)
--

2.44.0