diff mbox series

[v1] exfat: fix file being changed by unaligned direct write

Message ID PUZPR04MB631696A2513D72126D4165B881542@PUZPR04MB6316.apcprd04.prod.outlook.com (mailing list archive)
State New
Headers show
Series [v1] exfat: fix file being changed by unaligned direct write | expand

Commit Message

Yuezhang.Mo@sony.com Oct. 30, 2024, 7:47 a.m. UTC
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: 11a347fb6cef ("exfat: change to get file size from DataLength")
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Co-developed-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 fs/exfat/file.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Namjae Jeon Oct. 31, 2024, 12:23 p.m. UTC | #1
On Wed, Oct 30, 2024 at 4:47 PM Yuezhang.Mo@sony.com
<Yuezhang.Mo@sony.com> wrote:
>
> 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: 11a347fb6cef ("exfat: change to get file size from DataLength")
> Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
> Co-developed-by: Namjae Jeon <linkinjeon@kernel.org>
> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Applied them to #dev.
Thanks!
diff mbox series

Patch

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index a25d7eb789f4..a00f3f1b2cbb 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -584,6 +584,12 @@  static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
 	if (ret < 0)
 		goto unlock;
 
+	if ((iocb->ki_flags & IOCB_DIRECT) &&
+	    EXFAT_BLK_OFFSET(pos | ret, inode->i_sb)) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+
 	if (pos > valid_size) {
 		ret = exfat_extend_valid_size(file, pos);
 		if (ret < 0 && ret != -ENOSPC) {