From mboxrd@z Thu Jan 1 00:00:00 1970 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 2954EC761A6 for ; Wed, 5 Apr 2023 23:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234191AbjDEX7r (ORCPT ); Wed, 5 Apr 2023 19:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233991AbjDEX7m (ORCPT ); Wed, 5 Apr 2023 19:59:42 -0400 Received: from mail-ed1-x563.google.com (mail-ed1-x563.google.com [IPv6:2a00:1450:4864:20::563]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A690659E3 for ; Wed, 5 Apr 2023 16:59:39 -0700 (PDT) Received: by mail-ed1-x563.google.com with SMTP id i5so145451383eda.0 for ; Wed, 05 Apr 2023 16:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dectris.com; s=google; t=1680739178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ks4G1hHrmLTNXZAOT0ue/jCDhDMHdqAw9Getw5UZWqk=; b=Iigyc5eP7nB4AKoLMRSQ89c4kVZ3UDYb+X3siip6Z86X9K4KHhr0TnUjZI/LGEbSaR 0Hmk9vJyPWqLxUYsN+bq921/s/M5RENTMYnm3XLgdl5mQl5gMMiuezNHAePUZi+SNO6C EnZ4Gd5593Nx869z1eNuEq2SeGXd9I8YEZbMs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680739178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ks4G1hHrmLTNXZAOT0ue/jCDhDMHdqAw9Getw5UZWqk=; b=euH2Vjfl21JCJOgXjaEaFQgFwnkzUgqGaBxKCxZfus7ktwLMRfVXXeXPmAf6Wb0AYr 5cNC4/4xahazpfc7PZPKmRDl75SWA6TOx0FndN50N+41EuM+lZmgBzrtAsP/qCI+XYS9 X4RnRr27ZORUtYm7nZ5HxIK41aouwCJSWTh905nTP9meom75n1wTaCv23X9Aif0k6UbW fEpxc+nOveRXZ26HxW65Znr1H1nA5b9ASX5pTkejjja0O9P2asXYnMaSS+1YXI3BK4Iv Tojkr3L8dFR7Yz3qpCm639YH31jnexoGzVBqesz7gHU3/WrD6y8DCGJVIbvASSbLrGNt dYZQ== X-Gm-Message-State: AAQBX9fNspp3/ejCp35gnoWB65JwWNucOJqVJ9aPkTLHVnS7/RGAB6Cz Lcv2HeIUgIKF6xMFmOIw7rhEkIXIc5B+qvF4StWY0vuKxtt0 X-Google-Smtp-Source: AKy350btrICbcmDgkQJedJGt0hgzeBaSP9SrDlYz8zzJmH6kwVvNwTFgMi+Y7lLBQg+qbKCf3S6Lt29F2gI6 X-Received: by 2002:a17:906:3c4d:b0:8af:2107:6ce5 with SMTP id i13-20020a1709063c4d00b008af21076ce5mr4815117ejg.35.1680739178039; Wed, 05 Apr 2023 16:59:38 -0700 (PDT) Received: from fedora.dectris.local (dect-ch-bad-pfw.cyberlink.ch. [62.12.151.50]) by smtp-relay.gmail.com with ESMTPS id hd33-20020a17090796a100b00949174b747bsm8548ejc.96.2023.04.05.16.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 16:59:38 -0700 (PDT) X-Relaying-Domain: dectris.com From: Kal Conley To: Magnus Karlsson , Martin KaFai Lau , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Maxim Mikityanskiy Cc: Kal Conley , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 1/2] xsk: Fix unaligned descriptor validation Date: Thu, 6 Apr 2023 01:59:18 +0200 Message-Id: <20230405235920.7305-2-kal.conley@dectris.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230405235920.7305-1-kal.conley@dectris.com> References: <20230405235920.7305-1-kal.conley@dectris.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make sure unaligned descriptors that straddle the end of the UMEM are considered invalid. Currently, descriptor validation is broken for zero-copy mode which only checks descriptors at page granularity. For example, descriptors in zero-copy mode that overrun the end of the UMEM but not a page boundary are (incorrectly) considered valid. The UMEM boundary check needs to happen before the page boundary and contiguity checks in xp_desc_crosses_non_contig_pg(). Do this check in xp_unaligned_validate_desc() instead like xp_check_unaligned() already does. Fixes: 2b43470add8c ("xsk: Introduce AF_XDP buffer allocation API") Signed-off-by: Kal Conley Acked-by: Magnus Karlsson --- include/net/xsk_buff_pool.h | 9 ++------- net/xdp/xsk_queue.h | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h index 3e952e569418..d318c769b445 100644 --- a/include/net/xsk_buff_pool.h +++ b/include/net/xsk_buff_pool.h @@ -180,13 +180,8 @@ static inline bool xp_desc_crosses_non_contig_pg(struct xsk_buff_pool *pool, if (likely(!cross_pg)) return false; - if (pool->dma_pages_cnt) { - return !(pool->dma_pages[addr >> PAGE_SHIFT] & - XSK_NEXT_PG_CONTIG_MASK); - } - - /* skb path */ - return addr + len > pool->addrs_cnt; + return pool->dma_pages_cnt && + !(pool->dma_pages[addr >> PAGE_SHIFT] & XSK_NEXT_PG_CONTIG_MASK); } static inline u64 xp_aligned_extract_addr(struct xsk_buff_pool *pool, u64 addr) diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index bfb2a7e50c26..66c6f57c9c44 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -162,6 +162,7 @@ static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool, return false; if (base_addr >= pool->addrs_cnt || addr >= pool->addrs_cnt || + addr + desc->len > pool->addrs_cnt || xp_desc_crosses_non_contig_pg(pool, addr, desc->len)) return false; -- 2.39.2