From patchwork Fri Jul 22 02:13:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12925891 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5281AC433EF for ; Fri, 22 Jul 2022 02:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233818AbiGVCNZ (ORCPT ); Thu, 21 Jul 2022 22:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233762AbiGVCNX (ORCPT ); Thu, 21 Jul 2022 22:13:23 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26435974A6 for ; Thu, 21 Jul 2022 19:13:22 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id r64-20020a254443000000b006707b7c2baeso2639324yba.16 for ; Thu, 21 Jul 2022 19:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Wbl69skgO/KCoHNYhblp1Sm0LyLquoPWEcXNs9wNbPo=; b=rJw9XC43mi44QB1+Zv+0EGo3oMTnE3xe40wMfxakx81g1cnLeUw8Cqv3TXRAwkq5Nm KWWt0RRBq515La0wxMhp4lujt3SNAU2uOhbdpvKiidxcIh2PL33Oj5r+vvAOsnCaz+4z 712oAh2ADlaHBRVXKonzX4NgiiG+h9/t7W24Ix8ZpvCxIABdoaeeRTNXfF3VZzZFqLvd VgrZ32yrVT8iBTQe5diAh22lTuse6Ccpw5IXSvL8IaLDafmbtLex5gYU+QieMMEM5Q/Y glTTnu3V3OgdhFpOkdcrWxlrWCiC46vn1hvEItSHzRB2+ARpJ7Z1TnP91zok+hwYxRiT Fvdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Wbl69skgO/KCoHNYhblp1Sm0LyLquoPWEcXNs9wNbPo=; b=X6R5W8gmhN4rwdL4ihG2qEIMxVl/SAK6/fet9HuC8O5rP10G8S8NaFxoE18BDfBh/a 0Sgp7Wulm8azvimH7/nDjONEBzFOGJO0FRsch2tbc6t97l/it/vhBbiuvQw5GTPWlWG0 rINm1mEdfyhNmT8ZhvCDL4MGVXAFlVFM9z3ymmBJGUREJfbCwKqtmL3+AOQnYW2BPVlu 46Czp9bXSQyVR/ZqPV1ceh69g4Q8njTp2nowcwKrNRyA5x1lPf1jKku5O1Q1E+7nArgE rqsKpUBNPwMOoiY3RNh4Z9xulmsRih5KjhaMj/25X5Y9/JQI0h2ZvVEPeF3YA7WHBPWY Amkg== X-Gm-Message-State: AJIora/dgAjC9zIYGqG40bUcI/xc6QxhiNWyh4rxk6ZrOfNP3Bx7BYdl gkcbeY7lL04e9kF1Uwx04Vu4STWfdB9+vcTH X-Google-Smtp-Source: AGRyM1u1pgebccH4JOJx8RvDnApJJlB/bWLrM4dNttWXKsxXRFc6nHj6RzR/7COXpyyusIvV/1ZjGqw4zd+WGeSU X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:352:b0:669:4175:d1af with SMTP id e18-20020a056902035200b006694175d1afmr1243340ybs.395.1658456001361; Thu, 21 Jul 2022 19:13:21 -0700 (PDT) Date: Fri, 22 Jul 2022 02:13:08 +0000 In-Reply-To: <20220722021313.3150035-1-yosryahmed@google.com> Message-Id: <20220722021313.3150035-4-yosryahmed@google.com> Mime-Version: 1.0 References: <20220722021313.3150035-1-yosryahmed@google.com> X-Mailer: git-send-email 2.37.1.359.gd136c6c3e2-goog Subject: [PATCH bpf-next v4 3/8] bpf, iter: Fix the condition on p when calling stop. From: Yosry Ahmed To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , Hao Luo , Tejun Heo , Zefan Li Cc: Johannes Weiner , Shuah Khan , Michal Hocko , KP Singh , Benjamin Tissoires , John Fastabend , " =?utf-8?q?Michal_Koutn=C3=BD?= " , Roman Gushchin , David Rientjes , Stanislav Fomichev , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org, Yosry Ahmed Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Hao Luo 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. Signed-off-by: Hao Luo Signed-off-by: Yosry Ahmed Acked-by: Yonghong Song --- kernel/bpf/bpf_iter.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c index 7e8fd49406f6..4688ba39ef25 100644 --- a/kernel/bpf/bpf_iter.c +++ b/kernel/bpf/bpf_iter.c @@ -198,6 +198,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) {