From patchwork Tue Apr 27 12:19:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 12226633 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFBA8C433B4 for ; Tue, 27 Apr 2021 12:19:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2818613B2 for ; Tue, 27 Apr 2021 12:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235410AbhD0MTu (ORCPT ); Tue, 27 Apr 2021 08:19:50 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:42502 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236139AbhD0MTt (ORCPT ); Tue, 27 Apr 2021 08:19:49 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0UWzhhbo_1619525943; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0UWzhhbo_1619525943) by smtp.aliyun-inc.com(127.0.0.1); Tue, 27 Apr 2021 20:19:03 +0800 From: Xuan Zhuo To: bpf@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Maxim Mikityanskiy , netdev@vger.kernel.org Subject: [PATCH bpf] xsk: fix for xp_aligned_validate_desc() when len == chunk_size Date: Tue, 27 Apr 2021 20:19:03 +0800 Message-Id: <20210427121903.76556-1-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net When desc->len is equal to chunk_size, it is legal. But xp_aligned_validate_desc() got "chunk_end" by desc->addr + desc->len pointing to the next chunk during the check, which caused the check to fail. Fixes: 35fcde7f8deb ("xsk: support for Tx") Fixes: bbff2f321a86 ("xsk: new descriptor addressing scheme") Fixes: 2b43470add8c ("xsk: Introduce AF_XDP buffer allocation API") Fixes: 26062b185eee ("xsk: Explicitly inline functions and move definitions") Signed-off-by: Xuan Zhuo Acked-by: Magnus Karlsson --- net/xdp/xsk_queue.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index 2823b7c3302d..40f359bf2044 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -128,13 +128,12 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr) static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) { - u64 chunk, chunk_end; + u64 chunk; - chunk = xp_aligned_extract_addr(pool, desc->addr); - chunk_end = xp_aligned_extract_addr(pool, desc->addr + desc->len); - if (chunk != chunk_end) + if (desc->len > pool->chunk_size) return false; + chunk = xp_aligned_extract_addr(pool, desc->addr); if (chunk >= pool->addrs_cnt) return false;