Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp948878pxb; Wed, 6 Apr 2022 05:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdQ3vtGt+SDfhnSU4x6FpErr3rNh+d295Cd4MP47mpTN0LMQeMX3W+TBntyLNKdtvHCF/r X-Received: by 2002:a65:6e0e:0:b0:399:26d7:a224 with SMTP id bd14-20020a656e0e000000b0039926d7a224mr6766121pgb.437.1649246789982; Wed, 06 Apr 2022 05:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246789; cv=none; d=google.com; s=arc-20160816; b=dfaGLVVwgbEPSmyeWEs1+socC8Ue1OfFky8360+H+fVEqcH0qls5r3M18nA0zP877H PsgHMtthgqDDRiNNtvobbyliaOwNYByT9eEGIFPa57mJ5+udeCfsVYJBCZnhxAWDGCL6 PE+JKKU3YXi8YXXHX73v0t9JT6hTQzaHWK7KHClxuH3XeOIYMdvWaMdUZ72mgdqMwFs/ Iohws44I49hJ6z80WF4Q6ztYK26ss7z36E0cXb3g5lKYWhg3sRZO47EnMd28JxLBDvTC 1chM3uySgE8wYSbAisiZ17TLVgOmu4XFSU6Pbfex5x3VQuXjOBtwDT5Px2fhzNZP1oPA rHzw== 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=VihnDq0n6DLj9uM6EMPWKSQMpo94gfrYDrgTmtx/cm0=; b=IK67hD8aaZMaSUc0Qi2ERQuOXb8ZCA1sTXoFZSBGMCbchm/f0+c8v3zO1BUq8PIb3g 25asZHw6xTHVLs0nkpN9GVpWj/t/dhtaQq/UJ1EDtinQ50B9GYXR/9m3M4ckt6BdfTxP AZfT56DYILMdlyUDbgLETJONQ/K4kfLNU7bX9wzlY1bM8lmBPeU3+nTqnRnr/sJ9BW5c lh1FIAY73MsjUJCpV1rA7PPRS4gqiJ/hhKjH17fEmBwgolydJDeQ+Sm0BCZOUMTUvJPZ Yn4XAiOX6YJGPOY8MSqbn1/v4GYWG0d/MrlqFrSs7thlpH23dAOHy9jUUprT6XYUfn9c exvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ptufTXqp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q6-20020a170902dac600b00156b76ebb38si7165640plx.417.2022.04.06.05.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:06:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ptufTXqp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 85735686BC1; Wed, 6 Apr 2022 03:34:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358909AbiDEMvw (ORCPT + 99 others); Tue, 5 Apr 2022 08:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244635AbiDEJKG (ORCPT ); Tue, 5 Apr 2022 05:10:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D39D929819; Tue, 5 Apr 2022 01:59:36 -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 D8E6D61003; Tue, 5 Apr 2022 08:59:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB931C385A0; Tue, 5 Apr 2022 08:59:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149174; bh=ODLmb/qEa/+AEJJLUYZtqVO2J3cyrwlSn6sNYOX+hEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ptufTXqpMDRqTTzSZ2AHd9J9tri/NqoXAV7x2b4+xrtuXdVIBPIOSf+SL3dO5sBqq kuxW0Djwlz5NIQfVDYJlV19dKyrQ7tuzgwZceH/+OOtQKp5/WWjrcJTsxP/m7v+Lyh QeL7X+h9/d1Juw1IPEaDXgibt1V1N7faQV3IHkko= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.16 0620/1017] RDMA/nldev: Prevent underflow in nldev_stat_set_counter_dynamic_doit() Date: Tue, 5 Apr 2022 09:25:33 +0200 Message-Id: <20220405070412.686720962@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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 87e0eacb176f9500c2063d140c0a1d7fa51ab8a5 ] This code checks "index" for an upper bound but it does not check for negatives. Change the type to unsigned to prevent underflows. Fixes: 3c3c1f141639 ("RDMA/nldev: Allow optional-counter status configuration through RDMA netlink") Link: https://lore.kernel.org/r/20220316083948.GC30941@kili Signed-off-by: Dan Carpenter Reviewed-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/nldev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c index f5aacaf7fb8e..ca24ce34da76 100644 --- a/drivers/infiniband/core/nldev.c +++ b/drivers/infiniband/core/nldev.c @@ -1951,9 +1951,10 @@ static int nldev_stat_set_counter_dynamic_doit(struct nlattr *tb[], u32 port) { struct rdma_hw_stats *stats; - int rem, i, index, ret = 0; struct nlattr *entry_attr; unsigned long *target; + int rem, i, ret = 0; + u32 index; stats = ib_get_hw_stats_port(device, port); if (!stats) -- 2.34.1