Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4632405rwl; Mon, 3 Apr 2023 07:38:01 -0700 (PDT) X-Google-Smtp-Source: AKy350Z6NIwIN7ysyUrKEMXrM8s9sxHVUv6+tP74gSIC+gXiBTJmimp44ZUhUT//+tRUvSb0g120 X-Received: by 2002:a05:6402:10d4:b0:502:4182:648a with SMTP id p20-20020a05640210d400b005024182648amr19977378edu.9.1680532681481; Mon, 03 Apr 2023 07:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680532681; cv=none; d=google.com; s=arc-20160816; b=EzjOneJ1v5Dtb/+kjIhEmvYQfI0d4Yh5nMTxBwRp5aTQnk2CHgzgo+4w0P0i0R8C1m HvmV83owTipI65DGrnJIObQY6AnqL7YWPoe3zpZzw7p7U1lEHWEEsmTph+kLIo2jndpy jkfGCIautLUKb3VxJQbIDiemRrOd2u5p+P6LiMlut5cLqgT5hCbF8AILUrPJaa/pzGZj py0c/0rUv9qhGnOU9AzGTIn8BNhTq2PngcWJ6ArhWkoZDVTKzxbS3TtXDlHqr+H9+wU9 sCDyHvf5OF+ZWYYh0pP6AB2OwPCuaS2B95OdUkEItmfuehpTdQSVNwSwXeirnSXqm3Zu zm7Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=U5r7YRW0ZNQYQAUWUSjjSl8/aBINAbtHL/3e+twmpks=; b=OJ2KXzDMXb9gLerzKIA4S4I+h/2uL9RxpJP3DlbyXXGz6ZPmib+fTO1tmYPXvbskGr CbeGAGTEYLjGXX50M5q+9HIurS82zbbyuWceBictxNwSDit5/ARpZNqa7/kFSiw+r+bh YDCT3Pags+Jclf7Ho09BaKmBecfAaJM17UxqNvdUtlUjNiRK6J4sRN1scIHy7fOsiNCs 9zHfK66WPi7iAQm6a+tl6aCGyg5vJ37FJi+ofECYua56gyQ/PBNShvlTcNPfwnu/VMof VEjzOsexP+vBYBDHo6TMaR745S+mpYo4TyVnD/qD0dToIa+yj/k8bv74WkJHA1cvnS3W Wnzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dectris.com header.s=google header.b=r9QrjT90; 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=dectris.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a056402129400b004c0e614f887si7504780edv.94.2023.04.03.07.37.36; Mon, 03 Apr 2023 07:38:01 -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=@dectris.com header.s=google header.b=r9QrjT90; 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=dectris.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233656AbjDCOgY (ORCPT + 99 others); Mon, 3 Apr 2023 10:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233653AbjDCOgX (ORCPT ); Mon, 3 Apr 2023 10:36:23 -0400 Received: from mail-ed1-x564.google.com (mail-ed1-x564.google.com [IPv6:2a00:1450:4864:20::564]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7CC617672 for ; Mon, 3 Apr 2023 07:36:13 -0700 (PDT) Received: by mail-ed1-x564.google.com with SMTP id er13so77228953edb.9 for ; Mon, 03 Apr 2023 07:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dectris.com; s=google; t=1680532572; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U5r7YRW0ZNQYQAUWUSjjSl8/aBINAbtHL/3e+twmpks=; b=r9QrjT90BPkxKRltjojacHRrzBGVAyjMvPlwDhL7hO3+MhZunGBQH16KYfsoQWb8UT Nndx/n9S8RG17b8ls9oB7tYUKQIHRSQng5VaC9NU2wfOrLjI06fONzYAMLCY+UAv0/0q df9M4hXqP+nHHYYLwkoLfc31ZkdgVrE7/RY+8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680532572; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U5r7YRW0ZNQYQAUWUSjjSl8/aBINAbtHL/3e+twmpks=; b=ENwqIKIcg3bu6Xib0n4AasbtYRDB7/f8v6GfLHOhzAO1/E8z98kpU24SvIUQiX3dRj 1i8CfFw3UG7z5YQGrIMJY4z6LcfUVIM3CxjPDKYF8OoEJYpn7vsVSv0CJeimGo9phLMi t35YRO7/fMLSa+1MJ0uRsct05u1Rs99GX4ncXSgu1ffG7T7jvZOCro+hYkhZo5jyUTBN 3/Se1wSkeJoS+AkNDNBF9d5bmz+e2HsmzOTX9x8PDnf9QMb8xjzzZi1WcdoQcRLqG9+k 2ocwYXUSb00IeVv82RnYUGlh/B8PZJ8s5/6qwEf2awdJCiFbm9wAuL9Lf7l6h9cwR1Ga 8ARg== X-Gm-Message-State: AAQBX9foC0nzEA5gcPYMzm1AkYGvs4u9s41GTREAEGQlpljdcgj0+u0d GTsVMX5JRF41E88a8db8ynRCNTe4koM2qvHLeaNU/v7jZUQ6 X-Received: by 2002:a17:906:4990:b0:932:20a5:5b with SMTP id p16-20020a170906499000b0093220a5005bmr17548153eju.23.1680532572026; Mon, 03 Apr 2023 07:36:12 -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 r6-20020a1709064d0600b008b25260a59dsm3079775eju.290.2023.04.03.07.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 07:36:12 -0700 (PDT) X-Relaying-Domain: dectris.com From: Kal Conley To: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , 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] xsk: Fix unaligned descriptor validation Date: Mon, 3 Apr 2023 16:36:01 +0200 Message-Id: <20230403143601.32168-1-kal.conley@dectris.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 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. Descriptors that cross the end of the UMEM but not a page boundary may be therefore incorrectly considered valid. The 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 --- 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