From patchwork Wed Apr 28 09:44:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 12228411 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.7 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 610C3C433ED for ; Wed, 28 Apr 2021 09:44:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 207CD613D9 for ; Wed, 28 Apr 2021 09:44:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbhD1JpM (ORCPT ); Wed, 28 Apr 2021 05:45:12 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:47080 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238148AbhD1JpL (ORCPT ); Wed, 28 Apr 2021 05:45:11 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0UX3IEJP_1619603064; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0UX3IEJP_1619603064) by smtp.aliyun-inc.com(127.0.0.1); Wed, 28 Apr 2021 17:44:24 +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 , netdev@vger.kernel.org Subject: [PATCH bpf v2] xsk: fix for xp_aligned_validate_desc() when len == chunk_size Date: Wed, 28 Apr 2021 17:44:24 +0800 Message-Id: <20210428094424.54435-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. Related commit: commit 2b43470add8c ("xsk: Introduce AF_XDP buffer allocation API") commit 26062b185eee ("xsk: Explicitly inline functions and move definitions") This problem was first introduced in "bbff2f321a86". Later in "2b43470add8c" this piece of code was moved into the new function xp_aligned_validate_desc(). Later this function was moved into the file xsk_queue.h in "26062b185eee". Fixes: bbff2f321a86 ("xsk: new descriptor addressing scheme") 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;