Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3024036rwb; Mon, 15 Aug 2022 16:21:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR6UOxOXHRcCavKwkNP2Kr6B97auveKpPJZ4z3Nt3Q0RxG6rTa0nbepPDaMQDXMO1KjUwXbk X-Received: by 2002:a17:907:1c27:b0:730:ad6d:9fc9 with SMTP id nc39-20020a1709071c2700b00730ad6d9fc9mr11712027ejc.583.1660605607375; Mon, 15 Aug 2022 16:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605607; cv=none; d=google.com; s=arc-20160816; b=mRzTwI4x9jGlQh0Ckfx5oWbEQTRJGGEVKOJft6Sqd6d0aZxHznqWlWwP+Ksh9jiUyd pC0z7mX3/cQYck0UlTCyKWM27HX477TQOA+jpO8a+B6JLG6R2EZecKNN9HT9jnfHMLkd cWEUz9wYgnVuK52KpkiepG49B3+e0ex9/AjHwurP0ui3HgdyOeg+CW6BQDhX/BsZEgHr El5EmHT7yjb2XyNCFD1tBqjJsVFhzraxzPYM0MIaIpQWvstmjJJiwp/FvavJ/ty7+R7Q uUBu80881GRmrQeuCoZccirFTgorTEwHgrvbXLVKG82CiaYbuHfCUT74G2Q9cG689zlv 2WEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NQz/VKIP3kN2QLn8l27m/P9Kt7cszTwZVYsqpZ+wqno=; b=ysN8u7kjxeXE0gOGHk8nV5RRe6WWVIGNylBHY+iVDwxIdSjCtCMYhZP/m8ZK1KslgD UZMdtUWj38r/OIHTMRXEnWJMUC8K3wB3F9TlV6VsCc0n+qwyu1qH0ahopwHsznU2kc8w Gol5NgWuOZ0GF5G81ivlH37waHeuXO1bJauqfgQjwFsUDXtR22qb1b1lItVc00UvX2aF XiTpNoabAEFhDDHJp5HUKa6xHQv2eSn8JKPbzLc6V+3P8ZzZEF7yiNEt5BLTaiRLbHCN usODAvbFUEb+pw0lGWOxV44vZZDnTgYxbm7grZZdkh3srf584uzM/LlLZXdKjOsVD7Yo q5+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q1nrQguo; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp18-20020a1709071b1200b007387740b9c5si1194887ejc.22.2022.08.15.16.19.42; Mon, 15 Aug 2022 16:20:07 -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=@linuxfoundation.org header.s=korg header.b=q1nrQguo; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244825AbiHOVZR (ORCPT + 99 others); Mon, 15 Aug 2022 17:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347024AbiHOVSO (ORCPT ); Mon, 15 Aug 2022 17:18:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E33ACC5; Mon, 15 Aug 2022 12:21:47 -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 dfw.source.kernel.org (Postfix) with ESMTPS id AC6CE60EF0; Mon, 15 Aug 2022 19:21:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3DA5C4315D; Mon, 15 Aug 2022 19:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591306; bh=7HKHyqcvmrU1BBYjyvlutRcXUP3YLfWBNtPAvCpOBb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q1nrQguorhrAiTSNB9HbQiOhsSkEnp6oCT1xBHEA8k1SIU1EkS0MNZUKiKh0MjgiS 81KrJfcDZgXsUA/ZSFJ/wq/VLycAxQ/570OhjVA97s4henDem277jG7K+IeB1Rwe9H TsecEe5PPtPqnw4646Gogcb90sh1mV9U0q53pHPI= 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.18 0503/1095] bpf: Fix bpf_xdp_pointer return pointer Date: Mon, 15 Aug 2022 19:58:22 +0200 Message-Id: <20220815180450.337220358@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Joanne Koong [ Upstream commit bbd52178e249fe893ef4a9b87cde5b6c473b0a7c ] For the case where offset + len == 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@gmail.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 5db4fae23925..a98f34cb5aee 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3917,7 +3917,7 @@ static void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len) offset -= frag_size; } out: - return offset + len < size ? addr + offset : NULL; + return offset + len <= size ? addr + offset : NULL; } BPF_CALL_4(bpf_xdp_load_bytes, struct xdp_buff *, xdp, u32, offset, -- 2.35.1