From nobody Mon Sep 29 21:08:05 2025 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 D64F7C00140 for ; Tue, 16 Aug 2022 00:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356026AbiHPABz (ORCPT ); Mon, 15 Aug 2022 20:01:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356247AbiHOXyA (ORCPT ); Mon, 15 Aug 2022 19:54:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35BDEC6B60; Mon, 15 Aug 2022 13:18:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 49FB1B81183; Mon, 15 Aug 2022 20:18:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BE74C43470; Mon, 15 Aug 2022 20:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594724; bh=0FbSLWD+h5j9QQmrAuoZsBgelezyJQ90AnloIDebRaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vfOCCOvinwDy1+fJDICzlicMOZji+RSieUAAVS2QCI11j0xE3U3L6c6dRZsQQRdq8 VMIwdkBBYRELyDAUebhxTe0TCR0snlHWfxxuj7mYtWdD/bt4zVYaH/I54iJsr1JwuJ NEgZkikPy8r8aZdpPEuS370LcwPzMkOhmZ1D8Wro= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joanne Koong , Daniel Borkmann , Martin KaFai Lau , Lorenzo Bianconi , Sasha Levin Subject: [PATCH 5.19 0538/1157] bpf: Fix bpf_xdp_pointer return pointer Date: Mon, 15 Aug 2022 19:58:14 +0200 Message-Id: <20220815180501.185772727@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Joanne Koong [ Upstream commit bbd52178e249fe893ef4a9b87cde5b6c473b0a7c ] For the case where offset + len =3D=3D size, bpf_xdp_pointer should return a valid pointer to the addr because that access is permitted. We should only return NULL in the case where offset + len exceeds size. Fixes: 3f364222d032 ("net: xdp: introduce bpf_xdp_pointer utility routine") Signed-off-by: Joanne Koong Signed-off-by: Daniel Borkmann Acked-by: Martin KaFai Lau Acked-by: Lorenzo Bianconi Link: https://lore.kernel.org/bpf/20220722220105.2065466-1-joannelkoong@gma= il.com Signed-off-by: Sasha Levin --- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 5978984b752f..74f05ed6aff2 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3918,7 +3918,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u3= 2 offset, u32 len) offset -=3D frag_size; } out: - return offset + len < size ? addr + offset : NULL; + return offset + len <=3D size ? addr + offset : NULL; } =20 BPF_CALL_4(bpf_xdp_load_bytes, struct xdp_buff *, xdp, u32, offset, --=20 2.35.1