Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH] vfs: added better file aio_read aio_write operations presence check

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


marco.stornelli at coritel

Sep 16, 2008, 2:29 AM

Post #1 of 7 (1080 views)
Permalink
[PATCH] vfs: added better file aio_read aio_write operations presence check

From: Marco Stornelli <marco.stornelli [at] gmail>

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.
Signed-off-by: Marco Stornelli <marco.stornelli [at] gmail>
---

--- linux-2.6.26.5/fs/read_write.c.orig 2008-08-20 20:11:37.000000000 +0200
+++ linux-2.6.26.5/fs/read_write.c 2008-09-16 11:01:13.000000000 +0200
@@ -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-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


mkatiyar at gmail

Sep 16, 2008, 4:03 AM

Post #2 of 7 (1027 views)
Permalink
Re: [PATCH] vfs: added better file aio_read aio_write operations presence check [In reply to]

On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli
<marco.stornelli [at] coritel> wrote:
> From: Marco Stornelli <marco.stornelli [at] gmail>
>
> 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.


Signed-off-by: Manish Katiyar <mkatiyar [at] gmail>

---
fs/read_write.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 9ba495d..5439bc4 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -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);
--
1.5.4.3


Thanks -
Manish

> Signed-off-by: Marco Stornelli <marco.stornelli [at] gmail>
> ---
>
> --- linux-2.6.26.5/fs/read_write.c.orig 2008-08-20 20:11:37.000000000 +0200
> +++ linux-2.6.26.5/fs/read_write.c 2008-09-16 11:01:13.000000000 +0200
> @@ -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 majordomo [at] vger
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


marco.stornelli at coritel

Sep 16, 2008, 4:13 AM

Post #3 of 7 (1023 views)
Permalink
Re: [PATCH] vfs: added better file aio_read aio_write operations presence check [In reply to]

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:
> On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli
> <marco.stornelli [at] coritel> wrote:
>> From: Marco Stornelli <marco.stornelli [at] gmail>
>>
>> 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.
>
>
> Signed-off-by: Manish Katiyar <mkatiyar [at] gmail>
>
> ---
> fs/read_write.c | 10 ++++++++--
> 1 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 9ba495d..5439bc4 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -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);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


mkatiyar at gmail

Sep 16, 2008, 4:31 AM

Post #4 of 7 (1016 views)
Permalink
Re: [PATCH] vfs: added better file aio_read aio_write operations presence check [In reply to]

On Tue, Sep 16, 2008 at 4:43 PM, Marco Stornelli
<marco.stornelli [at] coritel> wrote:
> 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.

Signed-off-by: Manish Katiyar <mkatiyar [at] gmail>

---
fs/read_write.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 9ba495d..b89b707 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -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);
--
1.5.4.3

Thanks -
Manish


>
> Manish Katiyar ha scritto:
>> On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli
>> <marco.stornelli [at] coritel> wrote:
>>> From: Marco Stornelli <marco.stornelli [at] gmail>
>>>
>>> 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.
>>
>>
>> Signed-off-by: Manish Katiyar <mkatiyar [at] gmail>
>>
>> ---
>> fs/read_write.c | 10 ++++++++--
>> 1 files changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/read_write.c b/fs/read_write.c
>> index 9ba495d..5439bc4 100644
>> --- a/fs/read_write.c
>> +++ b/fs/read_write.c
>> @@ -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);
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


7eggert at gmx

Sep 16, 2008, 8:36 AM

Post #5 of 7 (1012 views)
Permalink
Re: [PATCH] vfs: added better file aio_read aio_write operations presence check [In reply to]

Manish Katiyar <mkatiyar [at] gmail> wrote:
> On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli
>> From: Marco Stornelli <marco.stornelli [at] gmail>

>> 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.

> --- a/fs/read_write.c

> - 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);

Why can't the file system registration code set filp->f_op->aio_read to
generic_file_aio_read?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


matthew at wil

Sep 16, 2008, 8:41 AM

Post #6 of 7 (1007 views)
Permalink
Re: [PATCH] vfs: added better file aio_read aio_write operations presence check [In reply to]

On Tue, Sep 16, 2008 at 05:36:09PM +0200, Bodo Eggert wrote:
> Why can't the file system registration code set filp->f_op->aio_read to
> generic_file_aio_read?

const struct file_operations *f_op;

Having said that, BUILD_BUG_ON(!f_op->aio_read) is fine by me ... make
the filesystem writer put it in without slowing down anyone at runtime.

--
Matthew Wilcox Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


hch at infradead

Sep 16, 2008, 9:36 AM

Post #7 of 7 (1011 views)
Permalink
Re: [PATCH] vfs: added better file aio_read aio_write operations presence check [In reply to]

On Tue, Sep 16, 2008 at 11:29:41AM +0200, Marco Stornelli wrote:
> From: Marco Stornelli <marco.stornelli [at] gmail>
>
> 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..

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.