From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,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 DDBC6C43331 for ; Mon, 11 Nov 2019 18:46:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B32D521655 for ; Mon, 11 Nov 2019 18:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497961; bh=NJT/dnqZQQ5GqTsg0JsodvxiF/DmvijiBBevYIJ0iqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EJLQSazNoDd0IYT9JZUCjK1dWtaYgg+y6z1kGxPAiz3CuMBz0fycaJBjZylpaP9fe VMqOqyPIdWuslnfSiSEBkz8Wm8ho4Uks7lF0qEc7WljJSLyqTU7hfsSqjAxiitbe9B XqKNQw/fStwYVKT5NPvVwEHtLtTtR319iyMWb7xw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727025AbfKKSqA (ORCPT ); Mon, 11 Nov 2019 13:46:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:38220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729528AbfKKSp5 (ORCPT ); Mon, 11 Nov 2019 13:45:57 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9597320674; Mon, 11 Nov 2019 18:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497957; bh=NJT/dnqZQQ5GqTsg0JsodvxiF/DmvijiBBevYIJ0iqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pmdsDwBVHvoG8Mp7bGIVdDwP+1jz9L4OlE8n02EReY3aOHr4AiYow19DfkoAfuq4a 95gt1Iiq/XhEeP4409PHPDrceWH9GEphD5l5lJqgHAgBBnHaIPCTHtLFnPqlxRngWw Yv2++lCvZGws8Lbv0NqRcVeSqxA4XhNqwQ2HovOU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.19 080/125] RDMA/uverbs: Prevent potential underflow Date: Mon, 11 Nov 2019 19:28:39 +0100 Message-Id: <20191111181450.802298592@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit a9018adfde809d44e71189b984fa61cc89682b5e ] The issue is in drivers/infiniband/core/uverbs_std_types_cq.c in the UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE) function. We check that: if (attr.comp_vector >= attrs->ufile->device->num_comp_vectors) { But we don't check if "attr.comp_vector" is negative. It could potentially lead to an array underflow. My concern would be where cq->vector is used in the create_cq() function from the cxgb4 driver. And really "attr.comp_vector" is appears as a u32 to user space so that's the right type to use. Fixes: 9ee79fce3642 ("IB/core: Add completion queue (cq) object actions") Link: https://lore.kernel.org/r/20191011133419.GA22905@mwanda Signed-off-by: Dan Carpenter Reviewed-by: Jason Gunthorpe Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/uverbs.h | 2 +- include/rdma/ib_verbs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h index 5df8e548cc146..4a14de2d8c716 100644 --- a/drivers/infiniband/core/uverbs.h +++ b/drivers/infiniband/core/uverbs.h @@ -98,7 +98,7 @@ ib_uverbs_init_udata_buf_or_null(struct ib_udata *udata, struct ib_uverbs_device { atomic_t refcount; - int num_comp_vectors; + u32 num_comp_vectors; struct completion comp; struct device *dev; struct ib_device __rcu *ib_dev; diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index b7d63c3970d18..f3d475024d376 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -310,7 +310,7 @@ struct ib_tm_caps { struct ib_cq_init_attr { unsigned int cqe; - int comp_vector; + u32 comp_vector; u32 flags; }; -- 2.20.1