mmc: core: Fix size overflow for mmc partitions
PATCH v2 1/1 mmc: core: Fix size overflow for mmc partitions
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.
--- drivers/mmc/core/mmc.c | 6 +++--- include/linux/mmc/card.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/mmc/core/mmc.c +3 -3
@@ -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;
include/linux/mmc/card.h +1 -1
@@ -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 */
Signature · 1 line
2.7.4
Quoted 7 lines
With large eMMC cards, it is possible to create general purpose partitions that are bigger than 4GB. The size member of the
mmc_partstruct 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 <[email protected]>
Looks fine.
Avri
Quoted 51 lines
--- drivers/mmc/core/mmc.c | 6 +++--- include/linux/mmc/card.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/mmc/core/mmc.c index renamed from drivers/mmc/core/mmc.c +0
-0c880489..fc02124 100644
drivers/mmc/core/mmc.c +1
-1@@ -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){
drivers/mmc/core/mmc.c +1
-1@@ -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;drivers/mmc/core/mmc.c +1
-1-unsigned int part_size; +u64 part_size;struct device_node *np;bool broken_hpi = false;include/linux/mmc/card.h index renamed from include/linux/mmc/card.h +0
-09b6336a..b59d35b 100644
include/linux/mmc/card.h +1
-2@@ -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
Quoted 26 lines · 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_partstruct 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 <[email protected]>--- drivers/mmc/core/mmc.c | 6 +++--- include/linux/mmc/card.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/mmc/core/mmc.c +1
-1@@ -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) {
drivers/mmc/core/mmc.c static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd) · line 316
Quoted 5 lines
drivers/mmc/core/mmc.c +1
-1@@ -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