Skip to content

Commit 2e94e5b

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: fix file being changed by unaligned direct write
Unaligned direct writes are invalid and should return an error without making any changes, rather than extending ->valid_size and then returning an error. Therefore, alignment checking is required before extending ->valid_size. Fixes: 11a347f ("exfat: change to get file size from DataLength") Signed-off-by: Yuezhang Mo <[email protected]> Co-developed-by: Namjae Jeon <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 02dffe9 commit 2e94e5b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/exfat/file.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,16 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
584584
if (ret < 0)
585585
goto unlock;
586586

587+
if (iocb->ki_flags & IOCB_DIRECT) {
588+
unsigned long align = pos | iov_iter_alignment(iter);
589+
590+
if (!IS_ALIGNED(align, i_blocksize(inode)) &&
591+
!IS_ALIGNED(align, bdev_logical_block_size(inode->i_sb->s_bdev))) {
592+
ret = -EINVAL;
593+
goto unlock;
594+
}
595+
}
596+
587597
if (pos > valid_size) {
588598
ret = exfat_extend_valid_size(file, pos);
589599
if (ret < 0 && ret != -ENOSPC) {

0 commit comments

Comments
 (0)