From mboxrd@z Thu Jan 1 00:00:00 1970 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 91896C43334 for ; Sat, 9 Jul 2022 00:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbiGIAFG (ORCPT ); Fri, 8 Jul 2022 20:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229672AbiGIAE6 (ORCPT ); Fri, 8 Jul 2022 20:04:58 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ADFEA7D6D for ; Fri, 8 Jul 2022 17:04:53 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id k11-20020a170902c40b00b0016bac120046so98068plk.0 for ; Fri, 08 Jul 2022 17:04:53 -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=Z+JHBwxAxDgScZtO1p/+es4hJDW+SiPZzqWzOE/0rOo=; b=FM9Dmst+4r/eCIlrO0NIewdKZfGIpGWmXrkjfyiCnHGlO+FW3rZHJdcwkrNHgDaTY+ cvSYpDa2VVz8F5b/HJk2BsfHzDEHYzxa91MpEdZrSY4qCNp+aQGUemw3B+BBN2wVTepD IMDuPcDtlPxcTr/9vxUCX+eFJDXNBb+wibjvwy3nMSfNb27E8YxtzMH96QbzdtOJNFWi GDPEPDNWf0f1RW1m8z9GtmDs2h6Q2PqyNj6+5ie+TBMvfXKwUN8BGxbqZXCks4Nl8kEE u5szkY6eBbLmh9vcfQeF7tEyiY5MgEIXNcmRC9xkHn1LF9PtT+MBlXQoXha+si78OTkH 13MQ== 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=Z+JHBwxAxDgScZtO1p/+es4hJDW+SiPZzqWzOE/0rOo=; b=OWSLov6wK6oP9AZgzqv3aPSmVzxW65xPrtbwELr3PxJykGOu9wYFMbi5q38Sc+tR+c xbWSmMQ63+E8KELSTRNOaVMca8MQT2W7sGlJ6x0HODzsqY4QBSpIxsm0ta1J7fqwyu6z rivOC/0OOfPnl3aIra3z86R3FDL75nhHRWAYVEnWFlLSS6j2f/G1jTbxW0N6Pcm5geof 4MajGrNA+jSd6y4sFNpjn1RGtLQoFUiKwYEQKSuHaFZetdS1rgopYJTjKa0AArY4rmiB ncL4IoHC41MZV41x92Dj7Ofj7Vn6hWzeduTHHfp4jPGe06JDDr22UtskdABEQ/e7JuiH dCjA== X-Gm-Message-State: AJIora/Phrw78rBBVUkwMpA7V1aE+tUsgRgHXq7kXUidf5rFZdZ4gLzR 2roy7jyuBFRLWN8FyjT2VCcxAkAs+8x84R84 X-Google-Smtp-Source: AGRyM1ufvN6zG8QX4o7lGTyaqM53ImlvEYlHfwqxbRh1DGpIE6etmZTIKsXrAdCkxaqLrYyu8O+dj0LKvGFHdfxm X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:d191:b0:16b:ea2d:60f2 with SMTP id m17-20020a170902d19100b0016bea2d60f2mr5961637plb.24.1657325092664; Fri, 08 Jul 2022 17:04:52 -0700 (PDT) Date: Sat, 9 Jul 2022 00:04:34 +0000 In-Reply-To: <20220709000439.243271-1-yosryahmed@google.com> Message-Id: <20220709000439.243271-4-yosryahmed@google.com> Mime-Version: 1.0 References: <20220709000439.243271-1-yosryahmed@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH bpf-next v3 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=20Koutn=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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 7e8fd49406f64..4688ba39ef25c 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) { -- 2.37.0.rc0.161.g10f37bed90-goog