Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1048859rwd; Thu, 8 Jun 2023 11:14:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4r6hBhXbswbk+66NwE95UUdDit94P+o2Seu6XdygP25ak55UuxIfHrTGDbyfpokwIEJXvG X-Received: by 2002:a17:90a:d3d4:b0:256:33ba:8f5f with SMTP id d20-20020a17090ad3d400b0025633ba8f5fmr4396812pjw.36.1686248097965; Thu, 08 Jun 2023 11:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686248097; cv=none; d=google.com; s=arc-20160816; b=hM4N33gav2dKp+akflKAXR/CJ/0YJdVnUJbMBMu5I2dWmzRKYvneMHPMDUcKgNWsv9 1EPKco0TBfYtSRUWP73cdWsODu95Qk3Qb3uHHmDTm9lF7vbXoYG4Ls+rMv9uSWlWD7sV ZQjDnqX4D5IgWlY7vrDxgqRPD97wigu+PxZMwxwrkBL92BaHBBZUfHcQYkASV9WtgiOb e2bA3E5Jd14iTgnbpnDkxIQprzmCyCmWCxIEiKxUnPoG09VQQA3hOIhY8J0MUB1m6WKf aNMf39E/Ltrz4yQNnHfsapZXIA3ALXsD0y0Z85V4t0+VvFNmFyzeHW+l9LRZutwE4J2Z C8Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Ff0sWLws5Xaq7O24yT6WqYHWuKSh3wtpXB/C2lu5Ovk=; b=p2lUaVxf6OYKdWm00gYI1IzA9Tt/wPFRws7Te2KsVQ3sOZhc2cZcvUfPgNDJDaqVca 9v0CKJ4rZQcubYBYBVOybWWEUunQESdhFgBGrPZrTu7WAFzT/hKoUoDpSMKtpBDzk/7C 4Tn0Ins++smGv0AE19X/CPkawbeOfgkIlrEv52c8ui3wck40KiDCHHFumiV1r4A+HthK VmvS1VsTlX0XIBxrZoT84uDboEps2ydHQIafGoXacfuLiAaCJgfdTAx8NkzENGdF4mjJ Bfjh3zgXyM93/txXwwNyne/K5Y+FT3vaPGs5m/XjSHs4s2sv8EyglHEIpuk9HXRJ1dKq 6fOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="mu/l35IY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v11-20020a637a0b000000b0054661651289si1284175pgc.449.2023.06.08.11.14.44; Thu, 08 Jun 2023 11:14:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="mu/l35IY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234459AbjFHRiw (ORCPT + 99 others); Thu, 8 Jun 2023 13:38:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234192AbjFHRiv (ORCPT ); Thu, 8 Jun 2023 13:38:51 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E281D2D55; Thu, 8 Jun 2023 10:38:46 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-977d7bdde43so191834866b.0; Thu, 08 Jun 2023 10:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686245925; x=1688837925; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ff0sWLws5Xaq7O24yT6WqYHWuKSh3wtpXB/C2lu5Ovk=; b=mu/l35IYxUbQLaIyq4ylFKbzYLiErz85A9NiSRiqQOfX9yUdP7jIYoc1h4f9gVsNmW LwBPOjDW46jPLbBpZUOpoF8FSaKaFImNKIda/d6A8E7wwo71DZ/C8KhRJv9K1UfQ+IWe Ch6Pqei1KFgLqFYAdwCLFFF9LWuvqqKJQtWyShFOqO1rCA6cLu5YBr2wP8R+nRT11/UK P53xP0aaXmFc/RGmZyh51K7UrBJI2RhqUWY6OW9etGsAGFvsEY+Oxdz/I56PoYW9VWrK 5PS6PctZSbQ3nY7sYM3x2hsVt0yyLADscCysobVbMvhdqtJdf+sqMlhjqvrlf1qwAqnx aw3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686245925; x=1688837925; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ff0sWLws5Xaq7O24yT6WqYHWuKSh3wtpXB/C2lu5Ovk=; b=i5T/nUSyrnPrXd1OVWkD8yIW07rypRlV6qK7NrxEnm6eW4ya3DTYS9kAGMGyLufiDY CzDeTumdc9IG4lR3e2Spa3pCN3ppF3TMerkuDyCaEaU/r7w0HwUJig9shJwxgQxV78b2 tgf3uOC9dzTDVOy8yy+keibfDrjp/7djUMb8mSXnVX6kbHElU0NzsoUnrae6WTGNbSDF DZ+76jHgh0VsXzrqPceJmBv0swRRBxNnBFQ3JNvbbG1Pg640S8rxtQPeGYHgOEmR7dDX ertHiTqLBJpUIlw1qeSNkcqwQzf5+yfPHVkNWTbxakFGAkQyArLwgeN9zqPaCLrUFpw3 TwkA== X-Gm-Message-State: AC+VfDwylnSTv2jKa43DOxagUY+E8GqnIbX+x9N1lRix/665o49Reu60 oDZCEz9ZXmhaGOFLf05Z203r0w0L/NrKJaaf/PA= X-Received: by 2002:a17:906:58d5:b0:977:e501:cc01 with SMTP id e21-20020a17090658d500b00977e501cc01mr288236ejs.24.1686245925056; Thu, 08 Jun 2023 10:38:45 -0700 (PDT) MIME-Version: 1.0 References: <20230608125820.726340-1-zhangmingyi5@huawei.com> In-Reply-To: From: Andrii Nakryiko Date: Thu, 8 Jun 2023 10:38:32 -0700 Message-ID: Subject: Re: [PATCH] libbpf:fix use empty function pointers in ringbuf_poll To: Stanislav Fomichev Cc: zhangmingyi , andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hsinweih@uci.edu, jakub@cloudflare.com, john.fastabend@gmail.com, kongweibin2@huawei.com, kuba@kernel.org, linux-kernel@vger.kernel.org, liuxin350@huawei.com, netdev@vger.kernel.org, pabeni@redhat.com, syzbot+49f6cef45247ff249498@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, wuchangye@huawei.com, xiesongyang@huawei.com, yanan@huawei.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 8, 2023 at 9:27=E2=80=AFAM Stanislav Fomichev = wrote: > > On Thu, Jun 8, 2023 at 6:00=E2=80=AFAM zhangmingyi wrote: > > > > On 06/06,Stanislav Fomichev wrote: > > > > > On 06/05, Xin Liu wrote: > > > > From: zhangmingyi > > > > > > > The sample_cb of the ring_buffer__new interface can transfer NULL. = However, > > > > the system does not check whether sample_cb is NULL during > > > > ring_buffer__poll, null pointer is used. > > > > > What is the point of calling ring_buffer__new with sample_cb =3D=3D N= ULL? > > > > Yes, as you said, passing sample_cb in ring_buffer__new to NULL doesn't > > make sense, and few people use it that way, but that doesn't prevent th= is > > from being a allowed and supported scenario. And when ring_buffer__poll= is > > called, it leads to a segmentation fault (core dump), which I think nee= ds > > to be fixed to ensure the security quality of libbpf. > > I dunno. I'd argue that passing a NULL to ring_buffer__new is an API > misuse. Maybe ring_buffer__new should return -EINVAL instead when > passed NULL sample_cb? Although, we don't usually have those checks > for the majority of the arguments in libbpf... Right. I'd say we should add a proper doc comment specifying all arguments and which ones are optional or not. And make it explicit that callback is not optional. If we start checking every possible pointer for NULL, libbpf will be littered with NULL checks, I'm not sure that's good.