]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/partitions/check.c
block: sanitize invalid partition table entries
[linux-2.6-omap-h63xx.git] / fs / partitions / check.c
index 7408227c49c91cefed99f861a90a8bbb85e8b346..fbeb2f372a93dba06f0d9aab1cfb438389a5668e 100644 (file)
@@ -538,10 +538,23 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
                sector_t from = state->parts[p].from;
                if (!size)
                        continue;
+               if (from >= get_capacity(disk)) {
+                       printk(KERN_WARNING
+                              "%s: p%d ignored, start %llu is behind the end of the disk\n",
+                              disk->disk_name, p, (unsigned long long) from);
+                       continue;
+               }
                if (from + size > get_capacity(disk)) {
+                       /*
+                        * we can not ignore partitions of broken tables
+                        * created by for example camera firmware, but we
+                        * limit them to the end of the disk to avoid
+                        * creating invalid block devices
+                        */
                        printk(KERN_WARNING
-                               "%s: p%d exceeds device capacity\n",
-                               disk->disk_name, p);
+                              "%s: p%d size %llu limited to end of disk\n",
+                              disk->disk_name, p, (unsigned long long) size);
+                       size = get_capacity(disk) - from;
                }
                res = add_partition(disk, p, from, size, state->parts[p].flags);
                if (res) {