Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1552407iob; Fri, 29 Apr 2022 07:47:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6Ad9m0tBDqorD2BeA4Lj+cFWUr1nD6YIB3aPPuxQeq5JSJzZK4rsHV5gcz9ncjHRWO5P7 X-Received: by 2002:a05:6512:1516:b0:448:39b8:d603 with SMTP id bq22-20020a056512151600b0044839b8d603mr27481758lfb.599.1651243630209; Fri, 29 Apr 2022 07:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651243630; cv=none; d=google.com; s=arc-20160816; b=Y5CR0TTrvjLblDvWRNskKWDdksnPCPm3DynKb8KdluSrDYPUM1bY0E/swKdSMTAvrQ KgnuDGPp3VqcBxWG0PKofd27vC5HLN+myxUv6WhaYSlks/DaCQTeXoRlDdY8h49JNTfW zXyL2nRE0PttRlsqszk3f4pZ2tHbZTCsIdUBEX9+gvtWBoq7tnnFz593lw/cy+U2vMlS rgcPw41RAms37FJVmYglH7pRwn765vY9PEUd4wG+b+CAIKDAoQQOgVevUQhGGU9bQiGC N64ImiKIRWZi3Hdt+yzA8vHQm1Jsv3ik4yi2X0QYMgN9FonI4gHfiVNu79qw71eOYp0H nhgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:subject:user-agent:mime-version:date:message-id; bh=r8wOnzq6zU26anq+4FCXswE1r0qwcRhZuhkGJ0bQyZk=; b=KBsKKrYKlDbyNLQqv3r+VgPX3cJntDCfmlXe6w+jFAzVgPzA+ov6FNTexRItYGQgnt MaZHrCQ2Z/iLBlFEGP1PAcDcAB5b16x7L8tkLmHnDNI9TTS93S/47IPuSQ96IzPB8ii4 2Jo1IIl8cpDWuSAjxannMquMQyi4tx9qg8T2JB8FHPqAe82SclZ5sjyMVHhFvPqOHWhE kge7VPRql3pSsfI/YTwiODbWqt06jb9B6dzA24KntaXJQ/AunJCSJI88Oyoh/bi1XDrG a7Jz2wta9I7EQdpxbH6qS/oV0fODcl2kzvDCcdEv7F8f5gTmRW+s4yVxluku/yDbSDSV GG6w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h13-20020a05651c158d00b0024e5c3d4f00si6837072ljq.137.2022.04.29.07.46.41; Fri, 29 Apr 2022 07:47:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346633AbiD1MuQ (ORCPT + 99 others); Thu, 28 Apr 2022 08:50:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245277AbiD1MuO (ORCPT ); Thu, 28 Apr 2022 08:50:14 -0400 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3472B37A94; Thu, 28 Apr 2022 05:46:56 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=mqaio@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VBazM0Q_1651150011; Received: from 30.225.28.125(mailfrom:mqaio@linux.alibaba.com fp:SMTPD_---0VBazM0Q_1651150011) by smtp.aliyun-inc.com(127.0.0.1); Thu, 28 Apr 2022 20:46:52 +0800 Message-ID: <5c641c77-f96d-4e75-ebc5-eef66cf0dbdc@linux.alibaba.com> Date: Thu, 28 Apr 2022 20:46:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH net-next] hinic: fix bug of wq out of bound access From: maqiao To: luobin9@huawei.com, davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, pabeni@redhat.com, huangguangbin2@huawei.com, keescook@chromium.org, gustavoars@kernel.org References: <282817b0e1ae2e28fdf3ed8271a04e77f57bf42e.1651148587.git.mqaio@linux.alibaba.com> In-Reply-To: <282817b0e1ae2e28fdf3ed8271a04e77f57bf42e.1651148587.git.mqaio@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham 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 cc Paolo Abeni, Guangbin Huang, Kees Cook, Gustavo A. R. Silva 在 2022/4/28 PM8:30, Qiao Ma 写道: > If wq has only one page, we need to check wqe rolling over page by > compare end_idx and curr_idx, and then copy wqe to shadow wqe to > avoid out of bound access. > This work has been done in hinic_get_wqe, but missed for hinic_read_wqe. > This patch fixes it, and removes unnecessary MASKED_WQE_IDX(). > > Fixes: 7dd29ee12865 ("hinic: add sriov feature support") > Signed-off-by: Qiao Ma > --- > drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c > index 5dc3743f8091..f04ac00e3e70 100644 > --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c > +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c > @@ -771,7 +771,7 @@ struct hinic_hw_wqe *hinic_get_wqe(struct hinic_wq *wq, unsigned int wqe_size, > /* If we only have one page, still need to get shadown wqe when > * wqe rolling-over page > */ > - if (curr_pg != end_pg || MASKED_WQE_IDX(wq, end_prod_idx) < *prod_idx) { > + if (curr_pg != end_pg || end_prod_idx < *prod_idx) { > void *shadow_addr = &wq->shadow_wqe[curr_pg * wq->max_wqe_size]; > > copy_wqe_to_shadow(wq, shadow_addr, num_wqebbs, *prod_idx); > @@ -841,7 +841,10 @@ struct hinic_hw_wqe *hinic_read_wqe(struct hinic_wq *wq, unsigned int wqe_size, > > *cons_idx = curr_cons_idx; > > - if (curr_pg != end_pg) { > + /* If we only have one page, still need to get shadown wqe when > + * wqe rolling-over page > + */ > + if (curr_pg != end_pg || end_cons_idx < curr_cons_idx) { > void *shadow_addr = &wq->shadow_wqe[curr_pg * wq->max_wqe_size]; > > copy_wqe_to_shadow(wq, shadow_addr, num_wqebbs, *cons_idx);