From patchwork Tue May 12 15:52:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 219408 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7226C2D0F6 for ; Tue, 12 May 2020 15:53:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96B6720722 for ; Tue, 12 May 2020 15:53:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="LH4keD8Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730620AbgELPxP (ORCPT ); Tue, 12 May 2020 11:53:15 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:55972 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727795AbgELPxP (ORCPT ); Tue, 12 May 2020 11:53:15 -0400 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04CFpMr7016651 for ; Tue, 12 May 2020 08:53:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=B0la6kbxVl951yfPwl0NKZpbJioGf0wtnobq3n9O/bY=; b=LH4keD8QGtFs8lJlFn2npsBLdCfBNiLZ0KGYeO9Mckzq2l+Kk96WAVde66juZISVuPbr TCYNT3I5AwIYDu8kYe6tGXu8nyY9sIG/2bZ6NeH07Qlsin14q3wC1Gv0BShdDZwjftab IgKSuv4Pygm/vym+aacqobu+o8IP7Ep9cA8= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 30xcc3w243-12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 12 May 2020 08:53:14 -0700 Received: from intmgw003.03.ash8.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Tue, 12 May 2020 08:52:44 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 0EB973700839; Tue, 12 May 2020 08:52:36 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Yonghong Song Smtp-Origin-Hostname: devbig003.ftw2.facebook.com To: Andrii Nakryiko , , Martin KaFai Lau , CC: Alexei Starovoitov , Daniel Borkmann , , Alexei Starovoitov Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next 4/8] bpf: add WARN_ONCE if bpf_seq_read show() return a positive number Date: Tue, 12 May 2020 08:52:36 -0700 Message-ID: <20200512155236.1080458-1-yhs@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200512155232.1080167-1-yhs@fb.com> References: <20200512155232.1080167-1-yhs@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.676 definitions=2020-05-12_05:2020-05-11,2020-05-12 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005120120 X-FB-Internal: deliver Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Signed-off-by: Yonghong Song --- kernel/bpf/bpf_iter.c | 2 ++ 1 file changed, 2 insertions(+) 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)) {