aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/bpf_iter.c
diff options
context:
space:
mode:
authorHao Luo <haoluo@google.com>2022-08-05 14:48:16 -0700
committerAlexei Starovoitov <ast@kernel.org>2022-08-09 09:12:00 -0700
commitbe3bb83dab2df838cd9e681e3e9dcde87bfe4f95 (patch)
treeff83550a986ccf9a8f52386234fa90730c7dea92 /kernel/bpf/bpf_iter.c
parentcgroup: enable cgroup_get_from_file() on cgroup1 (diff)
downloadlinux-dev-be3bb83dab2df838cd9e681e3e9dcde87bfe4f95.tar.xz
linux-dev-be3bb83dab2df838cd9e681e3e9dcde87bfe4f95.zip
bpf, iter: Fix the condition on p when calling stop.
In bpf_seq_read, seq->op->next() could return an ERR and jump to the label stop. However, the existing code in stop does not handle the case when p (returned from next()) is an ERR. Adds the handling of ERR of p by converting p into an error and jumping to done. Because all the current implementations do not have a case that returns ERR from next(), so this patch doesn't have behavior changes right now. Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Hao Luo <haoluo@google.com> Link: https://lore.kernel.org/r/20220805214821.1058337-4-haoluo@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/bpf_iter.c')
-rw-r--r--kernel/bpf/bpf_iter.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index 2726a5950cfa..4b112aa8bba3 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -197,6 +197,11 @@ static ssize_t bpf_seq_read(struct file *file, char __user *buf, size_t size,
}
stop:
offs = seq->count;
+ if (IS_ERR(p)) {
+ seq->op->stop(seq, NULL);
+ err = PTR_ERR(p);
+ goto done;
+ }
/* bpf program called if !p */
seq->op->stop(seq, p);
if (!p) {