Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3058220rwb; Mon, 15 Aug 2022 17:06:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ptw6yfIRaK6qvSHypvlXdjJ+mnr+uav84Drc5XWBrT/r3B7zKN1WGQSOSWUwFlCUjRiL0 X-Received: by 2002:a17:907:a06a:b0:730:d10e:fff3 with SMTP id ia10-20020a170907a06a00b00730d10efff3mr12238663ejc.109.1660608373506; Mon, 15 Aug 2022 17:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660608373; cv=none; d=google.com; s=arc-20160816; b=htLPBfujQ5ka6q6P5ZwnVaXWCESNv6xv9ctb2i7gYiYzms3Gu7/yQ1yXewwqoJyNPC Ge/cy+lDGwRhm4Quuvyfp5IsidtGG/Jc7csfXmAX7rYXiN0Qy/frD2/9nL9VDgsxTKmp LSfvrooz1ksW0gIAex9OUJ2vrhrWdueHqpQxfl9gVgdvgdeFV2iYhHyoUO5RvCO/F4cv O8iYQiRK5NIAJNvggOjPWWPO0tQgBoR99VsvdmueQzRPDLSmF78LHiy87YWFfo8VRR3n 06Yhp8RUsNoOeipJP8qmpT7KifQgpm+XBVgfPvYRzUkppAe6XnE+rPw9b+V0Zne4rYv5 ccPA== 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=ACW62GJN6KvhJi/3rHy2+A/WnAQDsigcz9JafPPDmNk=; b=Yxfy8xV8bRiOZfEi3j4R3zCMELjhSMTn9d0nnANlIf5Nz+2yw8TCWwXV+KMb1fEdDk y4S+YvLPXRuRMrofh6bkluILGZbtXBFM8ZtzZHCzVap4TAGyWxfEzuNm85y+upgC1faP jumy3ehmq1mYqF7gfjJ5YEudea5bKMkUG1FjeJtqoEGsToZGvpHcXAb1mqQvGCbUFRyT AaL9ulRU/CDIbtxUGRUSy1RWH6MW+pVG6j4sioiwPsMkKVp+9rf4PmJYul6UHytCQCYB shHAKCoTI/WK0Qh3YZCa4kUdOcLDZ7GkOyrprgAVUHR1IZczEibt+Y226cSA3dDprdMn 0FZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vfOCCOvi; 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 q17-20020a50cc91000000b0043e438a48e1si9017126edi.178.2022.08.15.17.05.24; Mon, 15 Aug 2022 17:06:13 -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=vfOCCOvi; 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 S1356007AbiHPABy (ORCPT + 99 others); Mon, 15 Aug 2022 20:01:54 -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-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 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, 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