Zheng Lv <lv.zheng.2015@xxxxxxxxx> writes: > The original code did not check for size of device. A truncated device > would mount, I/O failures would occur when "attempt to access beyond end > of device", leading to data lost. > > Fix this by comparing total-sectors field in BPB with size of device. > > This commit also prints a KERN_INFO message if there are extra sectors > at end of device (ie. total sectors < device sectors). [...] > + device_sectors = sb->s_bdev->bd_inode->i_size / logical_sector_size; > + if (device_sectors && total_sectors > device_sectors) { > + fat_msg(sb, KERN_ERR, "total sectors %u " > + "exceeds size of device (%llu sectors)", > + total_sectors, device_sectors); > + goto out_invalid; Hm, it is a bit hard to think what to do. But I guess it is better to allow access to rescue some files. (Yes, it may lost new data. But read-only or in-place update is safe.) > + } else if (device_sectors && total_sectors < device_sectors) { > + fat_msg(sb, KERN_INFO, "%llu unused sectors at end of device", > + device_sectors - total_sectors); This is legal setup. So, probably, should not pollute log for each mount. > + } > + > total_clusters = (total_sectors - sbi->data_start) / sbi->sec_per_clus; > > if (sbi->fat_bits != 32) -- OGAWA Hirofumi <hirofumi@xxxxxxxxxxxxxxxxxx> -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html