From: Jiaxing Wang <hello.wjx@gmail.com>
To: Gu Zheng <guz.fnst@cn.fujitsu.com>, Al Viro <viro@zeniv.linux.org.uk>
Cc: fsdevel <linux-fsdevel@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] seq_file: always update file->f_pos in seq_lseek()
Date: Fri, 25 Oct 2013 21:23:49 +0800 [thread overview]
Message-ID: <526A70E5.1000909@gmail.com> (raw)
In-Reply-To: <526A44AA.8050804@cn.fujitsu.com>
On 10/25/2013 06:15 PM, Gu Zheng wrote:
> This issue was first pointed out by Jiaxing Wang several months ago, but no
> further comments:
> https://lkml.org/lkml/2013/6/29/41
>
> As we know pread() does not change f_pos, so after pread(), file->f_pos
> and m->read_pos become different. And seq_lseek() does not update file->f_pos
> if offset equals to m->read_pos, so after pread() and seq_lseek()(lseek to
> m->read_pos), then a subsequent read may read from a wrong position, the
> following program produces the problem:
>
> char str1[32] = { 0 };
> char str2[32] = { 0 };
> int poffset = 10;
> int count = 20;
>
> /*open any seq file*/
> int fd = open("/proc/modules", O_RDONLY);
>
> pread(fd, str1, count, poffset);
> printf("pread:%s\n", str1);
>
> /*seek to where m->read_pos is*/
> lseek(fd, poffset+count, SEEK_SET);
>
> /*supposed to read from poffset+count, but this read from position 0*/
> read(fd, str2, count);
> printf("read:%s\n", str2);
>
> out put:
> pread:
> ck_netbios_ns 12665
> read:
> nf_conntrack_netbios
>
> /proc/modules:
> nf_conntrack_netbios_ns 12665 0 - Live 0xffffffffa038b000
> nf_conntrack_broadcast 12589 1 nf_conntrack_netbios_ns, Live 0xffffffffa0386000
>
> So we always update file->f_pos to offset in seq_lseek() to fix this issue.
>
> Signed-off-by: Jiaxing Wang <hello.wjx@gmail.com>
> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
> ---
> fs/seq_file.c | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/fs/seq_file.c b/fs/seq_file.c
> index 3135c25..a290157 100644
> --- a/fs/seq_file.c
> +++ b/fs/seq_file.c
> @@ -328,6 +328,8 @@ loff_t seq_lseek(struct file *file, loff_t offset, int whence)
> m->read_pos = offset;
> retval = file->f_pos = offset;
> }
> + } else {
> + file->f_pos = offset;
> }
> }
> file->f_version = m->version;
>
Thanks Gu, I should have post this patch again.
And Viro, please take a few minutes to review this, thanks.
prev parent reply other threads:[~2013-10-25 13:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-25 10:15 [PATCH] seq_file: always update file->f_pos in seq_lseek() Gu Zheng
2013-10-25 13:23 ` Jiaxing Wang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=526A70E5.1000909@gmail.com \
--to=hello.wjx@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=guz.fnst@cn.fujitsu.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.