From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Zheng Lv <lv.zheng.2015@gmail.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] fat: check whether fs size exceeds device size
Date: Fri, 24 Jun 2016 18:34:25 +0900 [thread overview]
Message-ID: <8737o3lyla.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <1466758690-12354-1-git-send-email-lv.zheng.2015@gmail.com> (Zheng Lv's message of "Fri, 24 Jun 2016 04:58:10 -0400")
Zheng Lv <lv.zheng.2015@gmail.com> 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@mail.parknet.co.jp>
next prev parent reply other threads:[~2016-06-24 9:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 8:58 [PATCH] fat: check whether fs size exceeds device size Zheng Lv
2016-06-24 9:34 ` OGAWA Hirofumi [this message]
2016-06-24 13:56 ` Zheng Lv
2016-06-25 10:08 ` OGAWA Hirofumi
2016-06-24 14:02 ` Zheng Lv
2016-06-24 15:10 ` Zheng Lv
2016-06-24 9:38 ` kbuild test robot
2016-06-24 10:39 ` kbuild test robot
2016-06-24 10:53 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8737o3lyla.fsf@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=lv.zheng.2015@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.