Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp913499pxb; Wed, 6 Apr 2022 04:06:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvuwuAMMdzw/ocT1Xci21erm5V1RALof8arCgVjnQRypwtqbSug1geG9jeSh+2oXnhR4J+ X-Received: by 2002:a17:903:2c5:b0:14f:4a29:1f64 with SMTP id s5-20020a17090302c500b0014f4a291f64mr7951576plk.90.1649243209198; Wed, 06 Apr 2022 04:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649243209; cv=none; d=google.com; s=arc-20160816; b=Yl7MSdCtJO6mtbuwyp/c3AM43qj+h/CXocHNyBnTWp0+Vo9Y/7WQBD/RxyOKk/tMcQ KGnLFXzRzT/u+IasLaoiFosqOc4c5kRLbUuF4YOHG9SKYyxU/TH0AXnM+l13dEhtm/zv R9PsH5vkc0JDBGlUqPlQ8p39pceVzPSz/zBdHepkn32AJL+toOs7YLBnnueP1eBu5jyN JdcjdLnmrTTLf1lCXK2HQnDSw21F5mkBTbHE+NkbS8fe9wNKiEFozsdr+DyNciNw/FEC t691pDN4Eke7/iOFRSQN+qYY+Qligt3tw5K/opUWIJquTjD7Lg3fhLpK4fWUs1bq1kL9 6MAw== 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=AK0D2PfaJgFf6UlWiVyIkbCTAfQRU0KsqILSMBRcfBQ=; b=sl9lNnJZMYVOoXm9Pjx1TMbCNjs/8TzwDhkFnMYISNFNZ0Bq5FSO/gNSPDrt+lzEGs YYAJyMCZiy2qJVvYyOHtl58Yzy4q9F2DWemUKrJ61GGPul/2w8AMkTle9m3Wnn3VFFpv OwzABIzvde7u3QiQ3JaBz/mhehZ6Is5fiKj+StKjOuA9LKDDch4ACJhxVH38USbbkNgK BjHJmKH9GIMR6rvikSzi8DW81EKvj1qUIVddTT55zqhqO7R6w4r/srfxEGsqI/VYuUo5 fgHwTJboTQqAZ/96oWgKVLT3dXNmQ95nVjI1/IUwOWNBLq/SEunESHVHDYxyqBiCd7c0 K7gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="b/56oO+u"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c19-20020a637253000000b0038251571eacsi14994657pgn.180.2022.04.06.04.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:06:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="b/56oO+u"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC43E5C4F6D; Wed, 6 Apr 2022 02:29:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390290AbiDEWDf (ORCPT + 99 others); Tue, 5 Apr 2022 18:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349342AbiDEJtl (ORCPT ); Tue, 5 Apr 2022 05:49:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB1C6334; Tue, 5 Apr 2022 02:44:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CBCE061675; Tue, 5 Apr 2022 09:44:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1E79C385A2; Tue, 5 Apr 2022 09:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151851; bh=yZ+WimmexbVpDWgdZiQrjWS7LEoQpVE2+xeHGJ7M12k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b/56oO+u1GkTTDTNjzrBsFhyEqFuGsSy84UErdjGCERJiconwuSwp0yvjo9OgFBe4 VtBc9FCS2yHfAMJET5KhphkRCcNXmYKPW9Is9HkbNEqx8cFW2MAAPL+ZoaUkh3vO7B o+08V4wFHWH5rrWbvfm8yX4j3vsnQvynAyZxUSks= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Shiraz Saleem , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.15 537/913] RDMA/irdma: Prevent some integer underflows Date: Tue, 5 Apr 2022 09:26:39 +0200 Message-Id: <20220405070355.945964593@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Dan Carpenter [ Upstream commit 6f6dbb819dfc1a35bcb8b709b5c83a3ea8beff75 ] My static checker complains that: drivers/infiniband/hw/irdma/ctrl.c:3605 irdma_sc_ceq_init() warn: can subtract underflow 'info->dev->hmc_fpm_misc.max_ceqs'? It appears that "info->dev->hmc_fpm_misc.max_ceqs" comes from the firmware in irdma_sc_parse_fpm_query_buf() so, yes, there is a chance that it could be zero. Even if we trust the firmware, it's easy enough to change the condition just as a hardenning measure. Fixes: 3f49d6842569 ("RDMA/irdma: Implement HW Admin Queue OPs") Link: https://lore.kernel.org/r/20220307125928.GE16710@kili Signed-off-by: Dan Carpenter Acked-by: Shiraz Saleem Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/irdma/ctrl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/irdma/ctrl.c b/drivers/infiniband/hw/irdma/ctrl.c index f1e5515256e0..1ac7067e21be 100644 --- a/drivers/infiniband/hw/irdma/ctrl.c +++ b/drivers/infiniband/hw/irdma/ctrl.c @@ -431,7 +431,7 @@ enum irdma_status_code irdma_sc_qp_create(struct irdma_sc_qp *qp, struct irdma_c cqp = qp->dev->cqp; if (qp->qp_uk.qp_id < cqp->dev->hw_attrs.min_hw_qp_id || - qp->qp_uk.qp_id > (cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt - 1)) + qp->qp_uk.qp_id >= (cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt)) return IRDMA_ERR_INVALID_QP_ID; wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch); @@ -2551,10 +2551,10 @@ static enum irdma_status_code irdma_sc_cq_create(struct irdma_sc_cq *cq, enum irdma_status_code ret_code = 0; cqp = cq->dev->cqp; - if (cq->cq_uk.cq_id > (cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].max_cnt - 1)) + if (cq->cq_uk.cq_id >= (cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].max_cnt)) return IRDMA_ERR_INVALID_CQ_ID; - if (cq->ceq_id > (cq->dev->hmc_fpm_misc.max_ceqs - 1)) + if (cq->ceq_id >= (cq->dev->hmc_fpm_misc.max_ceqs)) return IRDMA_ERR_INVALID_CEQ_ID; ceq = cq->dev->ceq[cq->ceq_id]; @@ -3656,7 +3656,7 @@ enum irdma_status_code irdma_sc_ceq_init(struct irdma_sc_ceq *ceq, info->elem_cnt > info->dev->hw_attrs.max_hw_ceq_size) return IRDMA_ERR_INVALID_SIZE; - if (info->ceq_id > (info->dev->hmc_fpm_misc.max_ceqs - 1)) + if (info->ceq_id >= (info->dev->hmc_fpm_misc.max_ceqs)) return IRDMA_ERR_INVALID_CEQ_ID; pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt; @@ -4205,7 +4205,7 @@ enum irdma_status_code irdma_sc_ccq_init(struct irdma_sc_cq *cq, info->num_elem > info->dev->hw_attrs.uk_attrs.max_hw_cq_size) return IRDMA_ERR_INVALID_SIZE; - if (info->ceq_id > (info->dev->hmc_fpm_misc.max_ceqs - 1)) + if (info->ceq_id >= (info->dev->hmc_fpm_misc.max_ceqs )) return IRDMA_ERR_INVALID_CEQ_ID; pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt; -- 2.34.1