From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.parknet.co.jp ([210.171.160.6]:56900 "EHLO mail.parknet.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750853AbcFXJe2 (ORCPT ); Fri, 24 Jun 2016 05:34:28 -0400 From: OGAWA Hirofumi To: Zheng Lv Cc: linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] fat: check whether fs size exceeds device size References: <1466758690-12354-1-git-send-email-lv.zheng.2015@gmail.com> Date: Fri, 24 Jun 2016 18:34:25 +0900 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") Message-ID: <8737o3lyla.fsf@mail.parknet.co.jp> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Zheng Lv 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