From patchwork Mon Jun 5 03:34:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Liu X-Patchwork-Id: 13266878 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 217D3649; Mon, 5 Jun 2023 03:35:23 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6F89A4; Sun, 4 Jun 2023 20:35:21 -0700 (PDT) Received: from dggpeml500010.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QZK4636wlzTkjG; Mon, 5 Jun 2023 11:35:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpeml500010.china.huawei.com (7.185.36.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 5 Jun 2023 11:35:18 +0800 From: Xin Liu To: CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH] libbpf:fix use empty function pointers in ringbuf_poll Date: Mon, 5 Jun 2023 11:34:49 +0800 Message-ID: <20230605033449.239123-1-liuxin350@huawei.com> X-Mailer: git-send-email 2.33.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500010.china.huawei.com (7.185.36.155) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 X-Patchwork-Delegate: bpf@iogearbox.net 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. Signed-off-by: zhangmingyi --- tools/lib/bpf/ringbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 02199364db13..3661338a1d2e 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -248,7 +248,7 @@ static int64_t ringbuf_process_ring(struct ring *r) got_new_data = true; cons_pos += roundup_len(len); - if ((len & BPF_RINGBUF_DISCARD_BIT) == 0) { + if (r->sample_cb && ((len & BPF_RINGBUF_DISCARD_BIT) == 0)) { sample = (void *)len_ptr + BPF_RINGBUF_HDR_SZ; err = r->sample_cb(r->ctx, sample, len); if (err < 0) {