Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp678709pxb; Tue, 5 Apr 2022 18:26:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzYGtktU4A8gxaM+htGTQf4w/Gs3GYo0dbIU1R9yhf32dZj+gjrU7JpnOE7Ki1/0lg+5JR X-Received: by 2002:a17:907:6e87:b0:6e7:f655:3b41 with SMTP id sh7-20020a1709076e8700b006e7f6553b41mr5948828ejc.704.1649208368493; Tue, 05 Apr 2022 18:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649208368; cv=none; d=google.com; s=arc-20160816; b=mGxsHQxGx2Ko55347ga63ux8mI+9hsaqJPF1sbRBBxFFW6/MS3y4DYw/Sj6ImiQbWJ 1pGPC+TcmDoMebmBi+/7/YLpAksf8sYobecmTjhmoc8T3ERTL0fzYXeX3iN+1ixcFYuy r7l4QJsssihAzUhIzcJzst2C+nYHtghb77NiXImBqnrXG8YadSM6rwX92WSyCVQRPMan dr6x3oMNFdY8UsG3ZBARMwNEsn0WSDPj+zh+aWXgriagxE6cPtHTS3eJT05y+0KpCHvA S8n7ZRDSDi5pZZIY0bwkqVq2fQj4gNY12spaOFppoSsTrYSYnG+9sqDD4STFPYZt6Bij wHhA== 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=Evm2EKIEisRA43tumBZMMFJK8Hpa/Jrfk8ixEVUuOWDw+CENlW1ojoFhL5ZBSFWQkC 7LIHNhNGmvXfJAVkR/MfQvVhTcs1zbD4BUVzYF7+/H4vrs/l3Kpnpmis2MHZoqQnvfZ9 TvqWhdj1+5jApHJzQAqR0kt5HP+alIG7uCFHuod404dNFfZbxZ2iKGW63BYz6DCmSnhW 1s0Llzq0TMnwumBEs7Iogt5FiPPvcuBc2Q4lk9j3ekwNl09Xr8gm8uHb2WOReN/anAD0 NBqD+I2XzXSYR1yUoViyACdLg80VD3R/yEbWMpWeKCX2LKiSYdOcx5Y6H37uvucs61yx M6FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AmU48dx1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id le10-20020a170907170a00b006df76385f2asi10380630ejc.970.2022.04.05.18.25.43; Tue, 05 Apr 2022 18:26:08 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AmU48dx1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244124AbiDEJlI (ORCPT + 99 others); Tue, 5 Apr 2022 05:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239166AbiDEITx (ORCPT ); Tue, 5 Apr 2022 04:19:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76D857891F; Tue, 5 Apr 2022 01:10:20 -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 12E6B609AD; Tue, 5 Apr 2022 08:10:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2100AC385A0; Tue, 5 Apr 2022 08:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146219; bh=ODLmb/qEa/+AEJJLUYZtqVO2J3cyrwlSn6sNYOX+hEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AmU48dx1lt4xhU3CF4m0n73MxYBHCrytZ1RhEszsgGlMiRPDS87j7fbghg0GeCg5v 6lHi42/1gDepTMq0+fhx4Lk7XUughomWM3BrPpZqFSLFMF7znpV9Y5cL+TytyijPPO ps7qXjrCd1sWbOb5V2EupL6wqgs1zO9+yAiTfRBU= 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.17 0686/1126] RDMA/nldev: Prevent underflow in nldev_stat_set_counter_dynamic_doit() Date: Tue, 5 Apr 2022 09:23:53 +0200 Message-Id: <20220405070427.752366418@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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