Re: [PATCH 1/6] seq_file: add seq_read_iter

Linus Torvalds
2020-11-11T17:54:35Z

On Tue, Nov 10, 2020 at 3:20 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> Any objections to the following?

Well, I don't _object_, but I find it ugly.

And I think both the old and the "fixed" code is wrong when an EFAULT
happens in the middle.

Yes, we can just return EFAULT. But for read() and write() we really
try to do the proper partial returns in other places, why not here?

IOW, why isn't the proper fix just something like this:

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3b20e21604e7..ecc6909b71f5 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -209,7 +209,8 @@ ssize_t seq_read_iter(struct kiocb *iocb,
struct iov_iter *iter)
/* if not empty - flush it first */
if (m->count) {
n = min(m->count, size);
- if (copy_to_iter(m->buf + m->from, n, iter) != n)
+ n = copy_to_iter(m->buf + m->from, n, iter);
+ if (!n)
goto Efault;
m->count -= n;
m->from += n;

which should get the "efault in the middle" case roughly right (ie the
usual "exact byte alignment and page crosser" caveats apply).

Linus