Skip to contentSkip to conversation

vfs: added better file aio_read aio_write operations presence check

PATCH In review Marco Stornelli 3 participants 5 messages Sep 16, 2008 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: added better file aio_read aio_write operations presence check

From: Marco Stornelli <[email protected]>

If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful.

---

fs/read_write.c renamed from fs/read_write.c.orig +2 -0
@@ -240,6 +240,7 @@ ssize_t do_sync_read(struct file *filp,
 	kiocb.ki_pos = *ppos;
 	kiocb.ki_left = len;
 
+	BUG_ON(!filp->f_op->aio_read);
 	for (;;) {
 		ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
 		if (ret != -EIOCBRETRY)
@@ -295,6 +296,7 @@ ssize_t do_sync_write(struct file *filp,
 	kiocb.ki_pos = *ppos;
 	kiocb.ki_left = len;
 
+	BUG_ON(!filp->f_op->aio_write);
 	for (;;) {
 		ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
 		if (ret != -EIOCBRETRY)
#1 lore raw
Quoted 6 lines · Marco Stornelli

From: Marco Stornelli <[email protected]>

If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful.

Instead of doing a BUG_ON() why can't we simply fall back to the generic_aio functions since most of the fs tend to do so as below.

---
 fs/read_write.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/read_write.c +0 -0
index 9ba495d..5439bc4 100644
@@ -225,7 +225,11 @@ ssize_t do_sync_read(struct file *filp, char

__user *buf, size_t len, loff_t *pp
kiocb.ki_left = len;

for (;;) {
- ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+ if (filp->f_op->aio_read)
+ ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+ else
+ ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
wait_on_retry_sync_kiocb(&kiocb);
@@ -280,7 +284,10 @@ ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, lof
kiocb.ki_left = len;

for (;;) {
- ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+ if (filp->f_op->aio_write)
+ ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+ else
+ ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
wait_on_retry_sync_kiocb(&kiocb);

Signature · 5 lines
1.5.4.3


Thanks -
Manish
Quoted 27 lines

---

fs/read_write.c 2008-09-16 11:01:13.000000000 +0200 renamed from fs/read_write.c.orig 2008-08-20 20:11:37.000000000 +0200 +2 -1
@@ -240,6 +240,7 @@ ssize_t do_sync_read(struct file *filp,
       kiocb.ki_pos = *ppos;
       kiocb.ki_left = len;
 
+       BUG_ON(!filp->f_op->aio_read);
       for (;;) {
               ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
               if (ret != -EIOCBRETRY)
@@ -295,6 +296,7 @@ ssize_t do_sync_write(struct file *filp,
       kiocb.ki_pos = *ppos;
       kiocb.ki_left = len;
 
+       BUG_ON(!filp->f_op->aio_write);
       for (;;) {
               ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
               if (ret != -EIOCBRETRY)
 
--

To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

BUG_ON it was a way to say: "hey you've used the do_sync_read/write as read/write operation but you don't specified an aio_read/write", but your solutions it's good too.

Manish Katiyar ha scritto:

Quoted 49 lines
Quoted 6 lines · Marco Stornelli

From: Marco Stornelli <[email protected]>

If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful.

Instead of doing a BUG_ON() why can't we simply fall back to the generic_aio functions since most of the fs tend to do so as below.

---
 fs/read_write.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/read_write.c +0 -0
index 9ba495d..5439bc4 100644
@@ -225,7 +225,11 @@ ssize_t do_sync_read(struct file *filp, char

__user *buf, size_t len, loff_t *pp

fs/read_write.c +4 -1
 	kiocb.ki_left = len;
 
 	for (;;) {
-		ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+		if (filp->f_op->aio_read)
+			ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+		else
+			ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
 		if (ret != -EIOCBRETRY)
 			break;
 		wait_on_retry_sync_kiocb(&kiocb);
@@ -280,7 +284,10 @@ ssize_t do_sync_write(struct file *filp, const

char __user *buf, size_t len, lof

fs/read_write.c +4 -1
 	kiocb.ki_left = len;
 
 	for (;;) {
-		ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+		if (filp->f_op->aio_write)
+			ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+		else
+			ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
 		if (ret != -EIOCBRETRY)
 			break;
 		wait_on_retry_sync_kiocb(&kiocb);
#3 lore raw
Quoted 3 lines · Marco Stornelli

BUG_ON it was a way to say: "hey you've used the do_sync_read/write as read/write operation but you don't specified an aio_read/write", but your solutions it's good too.

Looks like I made some copy paste error while sending the patch. Below is the updated one.

---
 fs/read_write.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/read_write.c +0 -0
index 9ba495d..b89b707 100644
@@ -225,7 +225,10 @@ ssize_t do_sync_read(struct file *filp, char

__user *buf, size_t len, loff_t *pp
kiocb.ki_left = len;

for (;;) {
- ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+ if (filp->f_op->aio_read)
+ ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+ else
+ ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
wait_on_retry_sync_kiocb(&kiocb);
@@ -280,7 +283,10 @@ ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, lof
kiocb.ki_left = len;

for (;;) {
- ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+ if (filp->f_op->aio_write)
+ ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+ else
+ ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
wait_on_retry_sync_kiocb(&kiocb);

Signature · 4 lines
1.5.4.3

Thanks -
Manish
Quoted 53 lines

Manish Katiyar ha scritto:

Quoted 49 lines
Quoted 6 lines · Marco Stornelli

From: Marco Stornelli <[email protected]>

If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful.

Instead of doing a BUG_ON() why can't we simply fall back to the generic_aio functions since most of the fs tend to do so as below.

---
 fs/read_write.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/read_write.c +0 -0
index 9ba495d..5439bc4 100644
@@ -225,7 +225,11 @@ ssize_t do_sync_read(struct file *filp, char

__user *buf, size_t len, loff_t *pp

      kiocb.ki_left = len;

      for (;;) {
fs/read_write.c +4 -1
-             ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+             if (filp->f_op->aio_read)
+                     ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+             else
+                     ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
              if (ret != -EIOCBRETRY)
                      break;
              wait_on_retry_sync_kiocb(&kiocb);
@@ -280,7 +284,10 @@ ssize_t do_sync_write(struct file *filp, const

char __user *buf, size_t len, lof

      kiocb.ki_left = len;

      for (;;) {
fs/read_write.c +4 -1
-             ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+             if (filp->f_op->aio_write)
+                     ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
+             else
+                     ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
              if (ret != -EIOCBRETRY)
                      break;
              wait_on_retry_sync_kiocb(&kiocb);
#4 lore raw
In reply to Marco Stornelli
Quoted 6 lines · Marco Stornelli

From: Marco Stornelli <[email protected]>

If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful.

A NULL pointer derference is just as clear as the bug..