linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] seq_read: move count check against iov_iter_count after calling op show
@ 2021-01-22 11:03 Xin Long
  2021-01-28  9:52 ` Xin Long
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Xin Long @ 2021-01-22 11:03 UTC (permalink / raw)
  To: linux-fsdevel, Alexander Viro; +Cc: NeilBrown

In commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code
and interface"), it broke a behavior: op show() is always called when op
next() returns an available obj.

This caused a refcnt leak in net/sctp/proc.c, as of the seq_operations
sctp_assoc_ops, transport obj is held in op next() and released in op
show().

Here fix it by moving count check against iov_iter_count after calling
op show() so that op show() can still be called when op next() returns
an available obj.

Note that m->index needs to increase so that op start() could go fetch
the next obj in the next round.

Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface")
Reported-by: Prijesh <prpatel@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 fs/seq_file.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 03a369c..da304f7 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -264,8 +264,6 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 		}
 		if (!p || IS_ERR(p))	// no next record for us
 			break;
-		if (m->count >= iov_iter_count(iter))
-			break;
 		err = m->op->show(m, p);
 		if (err > 0) {		// ->show() says "skip it"
 			m->count = offs;
@@ -273,6 +271,10 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 			m->count = offs;
 			break;
 		}
+		if (m->count >= iov_iter_count(iter)) {
+			m->index++;
+			break;
+		}
 	}
 	m->op->stop(m, p);
 	n = copy_to_iter(m->buf, m->count, iter);
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-02-04  5:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 11:03 [PATCH] seq_read: move count check against iov_iter_count after calling op show Xin Long
2021-01-28  9:52 ` Xin Long
2021-01-28 22:56 ` NeilBrown
2021-01-29  6:57   ` Xin Long
2021-02-04  4:57     ` Xin Long
2021-02-04  5:46       ` NeilBrown
2021-02-04  5:53         ` Xin Long
2021-02-04  6:08 ` [seq_read] 03c44acf0b: xfstests.generic.589.fail kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).