Skip to contentSkip to conversation

minix: fix bug when opening a file with O_DIRECT will

PATCH Superseded Qinghua Jin 3 participants 4 messages Jan 6, 2022 – Jan 7, 2022 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 minix: fix bug when opening a file with O_DIRECT will

Testcase:
1. create a minix file system and mount it
2. open a file on the file system with O_RDWR|O_CREAT|O_TRUNC|O_DIRECT
3. open fails with -EINVAL but leaves an empty file behind. All other open() failures don't leave the failed open files behind.

It is hard to check the direct_IO op before creating the inode. Just as ext4 and btrfs do, this patch will resolve the issue by allowing to create the file with O_DIRECT but returning error when writing the file.

---
 fs/minix/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/minix/inode.c +2 -1
index a71f1cf894b9..d4bd94234ef7 100644
@@ -447,7 +447,8 @@ static const struct address_space_operations minix_aops = {
 	.writepage = minix_writepage,
 	.write_begin = minix_write_begin,
 	.write_end = generic_write_end,
-	.bmap = minix_bmap
+	.bmap = minix_bmap,
+	.direct_IO = noop_direct_IO
 };
 
 static const struct inode_operations minix_symlink_inode_operations = {
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Qinghua Jin

Testcase:
1. create a minix file system and mount it
2. open a file on the file system with O_RDWR|O_CREAT|O_TRUNC|O_DIRECT
3. open fails with -EINVAL but leaves an empty file behind. All other open() failures don't leave the failed open files behind.

It is hard to check the direct_IO op before creating the inode. Just as ext4 and btrfs do, this patch will resolve the issue by allowing to create the file with O_DIRECT but returning error when writing the file.

The patch looks good. Thanks. Feel free to add:

Just out of curiosity: Do you happen to really use minix filesystem or was this just a fallout from some fuzz testing or something like that?

Honza

Quoted 21 lines
---
 fs/minix/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/minix/inode.c +2 -1
index a71f1cf894b9..d4bd94234ef7 100644
@@ -447,7 +447,8 @@ static const struct address_space_operations minix_aops = {
 	.writepage = minix_writepage,
 	.write_begin = minix_write_begin,
 	.write_end = generic_write_end,
-	.bmap = minix_bmap
+	.bmap = minix_bmap,
+	.direct_IO = noop_direct_IO
 };
 
 static const struct inode_operations minix_symlink_inode_operations = {
Signature · 1 line
2.30.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR

A message that is not in the archive (sent off-list or not yet received): CACL7WEN+eBW2MFGCti-NAzxAZAKXkjJ2F+6=eGqX0UdcAzw8Eg@mail.gmail.com

#3 lore raw
Quoted 17 lines · Qinghua Jin
Quoted 15 lines · Jan Kara
Quoted 11 lines · Qinghua Jin

Testcase:
1. create a minix file system and mount it
2. open a file on the file system with O_RDWR|O_CREAT|O_TRUNC|O_DIRECT
3. open fails with -EINVAL but leaves an empty file behind. All other open() failures don't leave the failed open files behind.

It is hard to check the direct_IO op before creating the inode. Just as ext4 and btrfs do, this patch will resolve the issue by allowing to create the file with O_DIRECT but returning error when writing the file.

The patch looks good. Thanks. Feel free to add:

Quoted 8 lines
Quoted 6 lines

Just out of curiosity: Do you happen to really use minix filesystem or was this just a fallout from some fuzz testing or something like that?

Thanks, It's a bug reported by [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=213041
I don't include the email because it's not reachable.

Fwiw, Colin's now at Intel:
Colin Ian King <[email protected]>

(While I'm here:

#4 lore raw

PATCH v2 1/1 minix: fix bug when opening a file with O_DIRECT

Testcase:
1. create a minix file system and mount it
2. open a file on the file system with O_RDWR|O_CREAT|O_TRUNC|O_DIRECT
3. open fails with -EINVAL but leaves an empty file behind. All other open() failures don't leave the failed open files behind.

It is hard to check the direct_IO op before creating the inode. Just as ext4 and btrfs do, this patch will resolve the issue by allowing to create the file with O_DIRECT but returning error when writing the file.

---
 fs/minix/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/minix/inode.c +2 -1
index a71f1cf894b9..d4bd94234ef7 100644
@@ -447,7 +447,8 @@ static const struct address_space_operations minix_aops = {
 	.writepage = minix_writepage,
 	.write_begin = minix_write_begin,
 	.write_end = generic_write_end,
-	.bmap = minix_bmap
+	.bmap = minix_bmap,
+	.direct_IO = noop_direct_IO
 };
 
 static const struct inode_operations minix_symlink_inode_operations = {
Signature · 1 line
2.30.2