RE: [PATCH] exfat: fix file not locking when writing zeros in exfat_file_mmap()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Matthew Wilcox <willy@xxxxxxxxxxxxx> 
Sent: Wednesday, January 24, 2024 1:21 PM
To: Mo, Yuezhang <Yuezhang.Mo@xxxxxxxx>
Subject: Re: [PATCH] exfat: fix file not locking when writing zeros in exfat_file_mmap()
> On Wed, Jan 24, 2024 at 05:00:37AM +0000, mailto:Yuezhang.Mo@xxxxxxxx wrote:
> > inode->i_rwsem should be locked when writing file. But the lock
> > is missing when writing zeros to the file in exfat_file_mmap().
> 
> This is actually very weird behaviour in exfat.  This kind of "I must
> manipulate the on-disc layout" is not generally done in mmap(), it's
> done in ->page_mkwrite() or even delayed until we actually do writeback.
> Why does exfat do this?

In exfat, "valid_size" describes how far into the data stream user data has been
written and "size" describes the file size.  Return zeros if read "valid_size"~"size".

For example,

(1) xfs_io -t -f -c "pwrite -S 0x59 0 1024" $filename
     - Write 0x59 to 0~1023
     - both "size" and "valid_size" are 1024
(2) xfs_io -t -f -c "truncate 4K" $filename
     - "valid_size" is still 1024
     - "size" is changed to 4096
     - 1024~4095 is not zeroed
     - return zeros if read 1024~4095
(3) xfs_io -t -f -c "mmap -rw 0 3072" -c  "mwrite -S 0x5a 2048 512" $filename
     (3.1) "mmap -rw 0 3072"
              -  write zeros to 1024~3071
              -  "valid_size" is changed to 3072
              - "size" is still 4096
     (3.2) "mwrite -S 0x5a 2048 512"
             - write 0x5a to 2048~2559
             - "valid_size" is still 3072
             -  "size" is still 4096

To avoid 1024~2047 is not zeroed and no need to update "valid_size" in (3.2),
I zero 1024~3071 in (3.1).

If you have a better solution, welcome to contribute to  exfat or share your
solution in detail.




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux