Changeset 36475


Ignore:
Timestamp:
2013-04-28T19:01:56+02:00 (5 years ago)
Author:
hauke
Message:

kernel: fix a memory leak in split_rootfs_data()

allocate_partition() copies all the content of dpart into a new struct.

Location:
trunk/target/linux/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/target/linux/generic/patches-3.8/400-rootfs_split.patch

    r35055 r36475  
    3636 /* 
    3737  * MTD methods which simply translate the effective address and pass through 
    38 @@ -613,6 +615,155 @@ int mtd_del_partition(struct mtd_info *m 
     38@@ -613,6 +615,144 @@ int mtd_del_partition(struct mtd_info *m 
    3939 } 
    4040 EXPORT_SYMBOL_GPL(mtd_del_partition); 
     
    8989+static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, const struct mtd_partition *part) 
    9090+{ 
    91 +       struct mtd_partition *dpart; 
     91+       struct mtd_partition dpart; 
    9292+       struct mtd_part *slave = NULL; 
    9393+       struct mtd_part *spart; 
     
    102102+               return 0; 
    103103+ 
    104 +       dpart = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL); 
    105 +       if (dpart == NULL) { 
    106 +               printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n", 
    107 +                       ROOTFS_SPLIT_NAME); 
    108 +               return -ENOMEM; 
    109 +       } 
    110 + 
    111 +       memcpy(dpart, part, sizeof(*part)); 
    112 +       dpart->name = (unsigned char *)&dpart[1]; 
    113 +       strcpy(dpart->name, ROOTFS_SPLIT_NAME); 
    114 + 
    115 +       dpart->size = rpart->size - (split_offset - spart->offset); 
    116 +       dpart->offset = split_offset; 
    117 + 
    118 +       if (dpart == NULL) 
    119 +               return 1; 
     104+       memcpy(&dpart, part, sizeof(dpart)); 
     105+       dpart.name = ROOTFS_SPLIT_NAME; 
     106+ 
     107+       dpart.size = rpart->size - (split_offset - spart->offset); 
     108+       dpart.offset = split_offset; 
    120109+ 
    121110+       printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%llX, len=%llX \n", 
    122 +               ROOTFS_SPLIT_NAME, dpart->offset, dpart->size); 
    123 + 
    124 +       slave = allocate_partition(master, dpart, 0, split_offset); 
     111+               ROOTFS_SPLIT_NAME, dpart.offset, dpart.size); 
     112+ 
     113+       slave = allocate_partition(master, &dpart, 0, split_offset); 
    125114+       if (IS_ERR(slave)) 
    126115+               return PTR_ERR(slave); 
     
    192181  * This function, given a master MTD object and a partition table, creates 
    193182  * and registers slave MTD objects which are bound to the master according to 
    194 @@ -629,6 +780,9 @@ int add_mtd_partitions(struct mtd_info * 
     183@@ -629,6 +769,9 @@ int add_mtd_partitions(struct mtd_info * 
    195184        struct mtd_part *slave; 
    196185        uint64_t cur_offset = 0; 
     
    202191        printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name); 
    203192  
    204 @@ -643,12 +797,53 @@ int add_mtd_partitions(struct mtd_info * 
     193@@ -643,12 +786,53 @@ int add_mtd_partitions(struct mtd_info * 
    205194  
    206195                add_mtd_device(&slave->mtd); 
  • trunk/target/linux/generic/patches-3.9/400-rootfs_split.patch

    r36008 r36475  
    3636 /* 
    3737  * MTD methods which simply translate the effective address and pass through 
    38 @@ -613,6 +615,155 @@ int mtd_del_partition(struct mtd_info *m 
     38@@ -613,6 +615,144 @@ int mtd_del_partition(struct mtd_info *m 
    3939 } 
    4040 EXPORT_SYMBOL_GPL(mtd_del_partition); 
     
    8989+static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, const struct mtd_partition *part) 
    9090+{ 
    91 +       struct mtd_partition *dpart; 
     91+       struct mtd_partition dpart; 
    9292+       struct mtd_part *slave = NULL; 
    9393+       struct mtd_part *spart; 
     
    102102+               return 0; 
    103103+ 
    104 +       dpart = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL); 
    105 +       if (dpart == NULL) { 
    106 +               printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n", 
    107 +                       ROOTFS_SPLIT_NAME); 
    108 +               return -ENOMEM; 
    109 +       } 
    110 + 
    111 +       memcpy(dpart, part, sizeof(*part)); 
    112 +       dpart->name = (unsigned char *)&dpart[1]; 
    113 +       strcpy(dpart->name, ROOTFS_SPLIT_NAME); 
    114 + 
    115 +       dpart->size = rpart->size - (split_offset - spart->offset); 
    116 +       dpart->offset = split_offset; 
    117 + 
    118 +       if (dpart == NULL) 
    119 +               return 1; 
     104+       memcpy(&dpart, part, sizeof(dpart)); 
     105+       dpart.name = ROOTFS_SPLIT_NAME; 
     106+ 
     107+       dpart.size = rpart->size - (split_offset - spart->offset); 
     108+       dpart.offset = split_offset; 
    120109+ 
    121110+       printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%llX, len=%llX \n", 
    122 +               ROOTFS_SPLIT_NAME, dpart->offset, dpart->size); 
    123 + 
    124 +       slave = allocate_partition(master, dpart, 0, split_offset); 
     111+               ROOTFS_SPLIT_NAME, dpart.offset, dpart.size); 
     112+ 
     113+       slave = allocate_partition(master, &dpart, 0, split_offset); 
    125114+       if (IS_ERR(slave)) 
    126115+               return PTR_ERR(slave); 
     
    192181  * This function, given a master MTD object and a partition table, creates 
    193182  * and registers slave MTD objects which are bound to the master according to 
    194 @@ -629,6 +780,9 @@ int add_mtd_partitions(struct mtd_info * 
     183@@ -629,6 +769,9 @@ int add_mtd_partitions(struct mtd_info * 
    195184        struct mtd_part *slave; 
    196185        uint64_t cur_offset = 0; 
     
    202191        printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name); 
    203192  
    204 @@ -643,12 +797,53 @@ int add_mtd_partitions(struct mtd_info * 
     193@@ -643,12 +786,53 @@ int add_mtd_partitions(struct mtd_info * 
    205194  
    206195                add_mtd_device(&slave->mtd); 
Note: See TracChangeset for help on using the changeset viewer.