Linux-mmc Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] mmc: core: Fix size overflow for mmc partitions
@ 2019-11-07  3:25 Bradley Bolen
  2019-11-07  8:30 ` Avri Altman
  2019-11-14 11:12 ` Ulf Hansson
  0 siblings, 2 replies; 3+ messages in thread
From: Bradley Bolen @ 2019-11-07  3:25 UTC (permalink / raw)
  To: linux-mmc
  Cc: ulf.hansson, kstewart, tglx, avri.altman, wsa+renesas, yinbo.zhu,
	hongjiefang, linux-kernel, Bradley Bolen

With large eMMC cards, it is possible to create general purpose
partitions that are bigger than 4GB.  The size member of the mmc_part
struct is only an unsigned int which overflows for gp partitions larger
than 4GB.  Change this to a u64 to handle the overflow.

Signed-off-by: Bradley Bolen <bradleybolen@gmail.com>
---
 drivers/mmc/core/mmc.c   | 6 +++---
 include/linux/mmc/card.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index c880489..fc02124 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -297,7 +297,7 @@ static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd)
 	}
 }
 
-static void mmc_part_add(struct mmc_card *card, unsigned int size,
+static void mmc_part_add(struct mmc_card *card, u64 size,
 			 unsigned int part_cfg, char *name, int idx, bool ro,
 			 int area_type)
 {
@@ -313,7 +313,7 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
 {
 	int idx;
 	u8 hc_erase_grp_sz, hc_wp_grp_sz;
-	unsigned int part_size;
+	u64 part_size;
 
 	/*
 	 * General purpose partition feature support --
@@ -362,7 +362,7 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
 static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
 {
 	int err = 0, idx;
-	unsigned int part_size;
+	u64 part_size;
 	struct device_node *np;
 	bool broken_hpi = false;
 
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 9b6336a..b59d35b 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -226,7 +226,7 @@ struct mmc_queue_req;
  * MMC Physical partitions
  */
 struct mmc_part {
-	unsigned int	size;	/* partition size (in bytes) */
+	u64		size;	/* partition size (in bytes) */
 	unsigned int	part_cfg;	/* partition type */
 	char	name[MAX_MMC_PART_NAME_LEN];
 	bool	force_ro;	/* to make boot parts RO by default */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH v2] mmc: core: Fix size overflow for mmc partitions
  2019-11-07  3:25 [PATCH v2] mmc: core: Fix size overflow for mmc partitions Bradley Bolen
@ 2019-11-07  8:30 ` Avri Altman
  2019-11-14 11:12 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Avri Altman @ 2019-11-07  8:30 UTC (permalink / raw)
  To: Bradley Bolen, linux-mmc
  Cc: ulf.hansson, kstewart, tglx, wsa+renesas, yinbo.zhu, hongjiefang,
	linux-kernel

> 
> With large eMMC cards, it is possible to create general purpose partitions that
> are bigger than 4GB.  The size member of the mmc_part struct is only an
> unsigned int which overflows for gp partitions larger than 4GB.  Change this to a
> u64 to handle the overflow.
> 
> Signed-off-by: Bradley Bolen <bradleybolen@gmail.com>
Looks fine.
Avri

> ---
>  drivers/mmc/core/mmc.c   | 6 +++---
>  include/linux/mmc/card.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index
> c880489..fc02124 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -297,7 +297,7 @@ static void mmc_manage_enhanced_area(struct
> mmc_card *card, u8 *ext_csd)
>         }
>  }
> 
> -static void mmc_part_add(struct mmc_card *card, unsigned int size,
> +static void mmc_part_add(struct mmc_card *card, u64 size,
>                          unsigned int part_cfg, char *name, int idx, bool ro,
>                          int area_type)
>  {
> @@ -313,7 +313,7 @@ static void mmc_manage_gp_partitions(struct
> mmc_card *card, u8 *ext_csd)  {
>         int idx;
>         u8 hc_erase_grp_sz, hc_wp_grp_sz;
> -       unsigned int part_size;
> +       u64 part_size;
> 
>         /*
>          * General purpose partition feature support -- @@ -362,7 +362,7 @@
> static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
> static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)  {
>         int err = 0, idx;
> -       unsigned int part_size;
> +       u64 part_size;
>         struct device_node *np;
>         bool broken_hpi = false;
> 
> diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index
> 9b6336a..b59d35b 100644
> --- a/include/linux/mmc/card.h
> +++ b/include/linux/mmc/card.h
> @@ -226,7 +226,7 @@ struct mmc_queue_req;
>   * MMC Physical partitions
>   */
>  struct mmc_part {
> -       unsigned int    size;   /* partition size (in bytes) */
> +       u64             size;   /* partition size (in bytes) */
>         unsigned int    part_cfg;       /* partition type */
>         char    name[MAX_MMC_PART_NAME_LEN];
>         bool    force_ro;       /* to make boot parts RO by default */
> --
> 2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mmc: core: Fix size overflow for mmc partitions
  2019-11-07  3:25 [PATCH v2] mmc: core: Fix size overflow for mmc partitions Bradley Bolen
  2019-11-07  8:30 ` Avri Altman
@ 2019-11-14 11:12 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2019-11-14 11:12 UTC (permalink / raw)
  To: Bradley Bolen
  Cc: linux-mmc, Kate Stewart, Thomas Gleixner, Avri Altman,
	Wolfram Sang, yinbo.zhu, Hongjie Fang, Linux Kernel Mailing List

On Thu, 7 Nov 2019 at 04:26, Bradley Bolen <bradleybolen@gmail.com> wrote:
>
> With large eMMC cards, it is possible to create general purpose
> partitions that are bigger than 4GB.  The size member of the mmc_part
> struct is only an unsigned int which overflows for gp partitions larger
> than 4GB.  Change this to a u64 to handle the overflow.
>
> Signed-off-by: Bradley Bolen <bradleybolen@gmail.com>
> ---
>  drivers/mmc/core/mmc.c   | 6 +++---
>  include/linux/mmc/card.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index c880489..fc02124 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -297,7 +297,7 @@ static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd)
>         }
>  }
>
> -static void mmc_part_add(struct mmc_card *card, unsigned int size,
> +static void mmc_part_add(struct mmc_card *card, u64 size,
>                          unsigned int part_cfg, char *name, int idx, bool ro,
>                          int area_type)
>  {
> @@ -313,7 +313,7 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
>  {
>         int idx;
>         u8 hc_erase_grp_sz, hc_wp_grp_sz;
> -       unsigned int part_size;
> +       u64 part_size;

There is also a cast to a "size_t" while computing the part_size in
mmc_manage_gp_partitions(). Should we remove that as well?

[...]

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07  3:25 [PATCH v2] mmc: core: Fix size overflow for mmc partitions Bradley Bolen
2019-11-07  8:30 ` Avri Altman
2019-11-14 11:12 ` Ulf Hansson

Linux-mmc Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mmc/0 linux-mmc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mmc linux-mmc/ https://lore.kernel.org/linux-mmc \
		linux-mmc@vger.kernel.org
	public-inbox-index linux-mmc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mmc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git