lkml.org 
[lkml]   [2020]   [Sep]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 4.19 034/206] mmc: core: Fix size overflow for mmc partitions
    Date
    From: Bradley Bolen <bradleybolen@gmail.com>

    [ Upstream commit f3d7c2292d104519195fdb11192daec13229c219 ]

    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>
    Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    drivers/mmc/core/mmc.c | 9 ++++-----
    include/linux/mmc/card.h | 2 +-
    2 files changed, 5 insertions(+), 6 deletions(-)

    diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
    index 5ca53e225382d..4b18034537f53 100644
    --- a/drivers/mmc/core/mmc.c
    +++ b/drivers/mmc/core/mmc.c
    @@ -300,7 +300,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)
    {
    @@ -316,7 +316,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 --
    @@ -346,8 +346,7 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
    (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
    << 8) +
    ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
    - part_size *= (size_t)(hc_erase_grp_sz *
    - hc_wp_grp_sz);
    + part_size *= (hc_erase_grp_sz * hc_wp_grp_sz);
    mmc_part_add(card, part_size << 19,
    EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
    "gp%d", idx, false,
    @@ -365,7 +364,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 8ef330027b134..3f8e84a80b4ad 100644
    --- a/include/linux/mmc/card.h
    +++ b/include/linux/mmc/card.h
    @@ -227,7 +227,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.25.1
    \
     
     \ /
      Last update: 2020-09-18 04:51    [W:4.131 / U:0.316 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site