diff mbox series

[bpf-next,4/8] bpf: add WARN_ONCE if bpf_seq_read show() return a positive number

Message ID 20200512155236.1080458-1-yhs@fb.com
State New
Headers show
Series None | expand

Commit Message

Yonghong Song May 12, 2020, 3:52 p.m. UTC
In seq_read() implementation, a positive integer return value
of seq_ops->show() indicates that the current object seq_file
buffer is discarded and next object should be checked.
bpf_seq_read() implemented in a similar way if show()
returns a positive integer value.

But for bpf_seq_read(), show() didn't return positive integer for
all currently supported targets. Let us add a WARN_ONCE for
such cases so we can get an alert when things are changed.

Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 kernel/bpf/bpf_iter.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index 0a45a6cdfabd..b0c8b3bdf3b0 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -120,6 +120,7 @@  static ssize_t bpf_seq_read(struct file *file, char __user *buf, size_t size,
 
 	err = seq->op->show(seq, p);
 	if (err > 0) {
+		WARN_ONCE(1, "seq_ops->show() returns %d\n", err);
 		/* object is skipped, decrease seq_num, so next
 		 * valid object can reuse the same seq_num.
 		 */
@@ -156,6 +157,7 @@  static ssize_t bpf_seq_read(struct file *file, char __user *buf, size_t size,
 
 		err = seq->op->show(seq, p);
 		if (err > 0) {
+			WARN_ONCE(1, "seq_ops->show() returns %d\n", err);
 			bpf_iter_dec_seq_num(seq);
 			seq->count = offs;
 		} else if (err < 0 || seq_has_overflowed(seq)) {