Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2828933pxv; Mon, 12 Jul 2021 02:58:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJIhqYiPbXOh5JHv39us3DazUduPbuK8j8VOLOvsK7JEYLIvzwIWcjtilca91BJaI3K8aO X-Received: by 2002:a92:d303:: with SMTP id x3mr778832ila.212.1626083938650; Mon, 12 Jul 2021 02:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626083938; cv=none; d=google.com; s=arc-20160816; b=Q5mF0IvhvlFkyQCGTSSncBbEpZPjy3B1n/E0HoasSHbLesqbL32stT9GcUXfTnzBWZ Jnzbh+Rjg/FVColnUSbhpXM/VDmWAU0Kuuj54Hb6/hAxjTZQkcYCRVH2511e6g/oXCJq Y5w2++1epLZTZfZyE6CFfG4FUSoTtuzWHbHwgjL1+rsVP5yrmumb7ztF/4PbYa5UhRL1 Q8p7FKXWsipqeyu5mCrwOyMNCcZTkwI8awIxpB/5E1H4/Yvwi0rZjFxp52n69cQk2sOf HqmVz/YJtO/SfD1zNJti8sXXk31jkIOW/ADxWjLc/+qXCvG7DMunkznj7eRp5fgtJMdn Jp8A== 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=RYWyv7LV5PArGvRSM43HQyFE03gEHmZq8k3r70YjXrM=; b=VFCl7R1OkTMv2PFinTwLHePOJIkbSTFqV0VatWUY4pQJUjzSy4mr+hcF4GLps9+8da iNniESpzR/yl14h3EdZ7fLsrRwzSeTCuLq8QaGj0+9bXME9ZwqWKs/IcaGp/cC3dY8kC S2hq0zEhzvpx081aCHEXFaphddrWHDc2WtNcuMkxjXDC4LE6HUtSasQbok/bbmFtSOEm LbKZOBkPO3OW9gCSP+MutEmcVXfWWbjUn2pbDUA2AXmTwmf/o5siZUiI3ZCdO4lYsGJC J24mC1mNobr1Xcb0ZOAahqlArgcLwkNYfuP1kS2ZH9yjwYafR8U2LdCJV7C8OyrMjpOR RGcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QSyHeJHY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si2930697ilo.83.2021.07.12.02.58.46; Mon, 12 Jul 2021 02:58:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QSyHeJHY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240431AbhGLHC1 (ORCPT + 99 others); Mon, 12 Jul 2021 03:02:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:41512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237238AbhGLGqJ (ORCPT ); Mon, 12 Jul 2021 02:46:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F1D661152; Mon, 12 Jul 2021 06:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072118; bh=8mzXLg0yDhF0iUgrxIe37YacjcJwVN75C/cMHvDwuOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QSyHeJHYCLFf2xssQIrSM1bVCapq28lz5QgI9fucElzi2Gcqs8/iRpZkx+o6O7aWA 1gcG3Bq8AmpkbUtsAnjUZEy0rOFhge3cyHs7KBZzjfdyRbtzBwnMSYCRsVAmuDBs4q nHs/CQjHr29KX3/h8NwADab9VVYxj20hElBX4z5s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Magnus Karlsson , Daniel Borkmann , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Sasha Levin Subject: [PATCH 5.10 362/593] xsk: Fix missing validation for skb and unaligned mode Date: Mon, 12 Jul 2021 08:08:42 +0200 Message-Id: <20210712060926.316046812@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Magnus Karlsson [ Upstream commit 2f99619820c2269534eb2c0cde44870313c6d353 ] Fix a missing validation of a Tx descriptor when executing in skb mode and the umem is in unaligned mode. A descriptor could point to a buffer straddling the end of the umem, thus effectively tricking the kernel to read outside the allowed umem region. This could lead to a kernel crash if that part of memory is not mapped. In zero-copy mode, the descriptor validation code rejects such descriptors by checking a bit in the DMA address that tells us if the next page is physically contiguous or not. For the last page in the umem, this bit is not set, therefore any descriptor pointing to a packet straddling this last page boundary will be rejected. However, the skb path does not use this bit since it copies out data and can do so to two different pages. (It also does not have the array of DMA address, so it cannot even store this bit.) The code just returned that the packet is always physically contiguous. But this is unfortunately also returned for the last page in the umem, which means that packets that cross the end of the umem are being allowed, which they should not be. Fix this by introducing a check for this in the SKB path only, not penalizing the zero-copy path. Fixes: 2b43470add8c ("xsk: Introduce AF_XDP buffer allocation API") Signed-off-by: Magnus Karlsson Signed-off-by: Daniel Borkmann Acked-by: Björn Töpel Link: https://lore.kernel.org/bpf/20210617092255.3487-1-magnus.karlsson@gmail.com Signed-off-by: Sasha Levin --- include/net/xsk_buff_pool.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h index eaa8386dbc63..7a9a23e7a604 100644 --- a/include/net/xsk_buff_pool.h +++ b/include/net/xsk_buff_pool.h @@ -147,11 +147,16 @@ static inline bool xp_desc_crosses_non_contig_pg(struct xsk_buff_pool *pool, { bool cross_pg = (addr & (PAGE_SIZE - 1)) + len > PAGE_SIZE; - if (pool->dma_pages_cnt && cross_pg) { + if (likely(!cross_pg)) + return false; + + if (pool->dma_pages_cnt) { return !(pool->dma_pages[addr >> PAGE_SHIFT] & XSK_NEXT_PG_CONTIG_MASK); } - return false; + + /* skb path */ + return addr + len > pool->addrs_cnt; } static inline u64 xp_aligned_extract_addr(struct xsk_buff_pool *pool, u64 addr) -- 2.30.2