Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9110503pxu; Mon, 28 Dec 2020 06:55:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZWhx5wIqNAhKlBmxvw1hXO1ot6SXscDOJXB0BIEL39uJxjpuuRnzPSlaON9dBxEnqJhxV X-Received: by 2002:a17:906:a115:: with SMTP id t21mr41556213ejy.549.1609167317507; Mon, 28 Dec 2020 06:55:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609167317; cv=none; d=google.com; s=arc-20160816; b=JBy9Rt3piDGxFKZyvma8I5+D4vDFN4zetb8qV2yra+Jx784cPJAegWKJKnXE/Ck7Fz Us1TVlLSIxTQs8pazwSAvH9SGFLMIKP8yP55vyVmZRAqNJJXkPheRvRErBaHLJjIBqJc uhEcrrmH8bDxl6aMvfeIueua9FkjpyOBzRXqx2DUldi7vDKXQruAVHmOezRcetBofaLc +kR9zjRYBKgeaSMJy3+N5zfvVETt1SI4YVt0B5agfOIUAyGIbdypZlZATb1fU6W+CvTw z3qmcSiTONRwX7xjeHbhdE47rw+6zQPfDLZnoJ5ACoOJrglbVNvZfRyhagfXVCI5zsGt qHHg== 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=eW9h/eNldCOkPnex3pVzrlRI2Kwfk5fNXiIvnzHt8pA=; b=RAP/E6obaDuVdGUC4nmpb8vsAVY07Y4rBuLo+Akg8yPsNxJRezI8fUTUYeKGmerky8 rFVu+P4Lk59q2tzvW/oQGisIDV5VT4Y2EseThkoqRcx0r1B+w2O6BZHFfehdw7jxKX9B rynscETHUJst3DAho4bZ3dU9YSRkgZN3HoD5+zN9K8geUAKwLZubYi2nToT1t2PNfsi8 ekI1Xz4obdoHq+jtchyY7/rbqzxI64+XoR5lhzJ7dpirNFggL87npSYNYMmzTUvG8oIl pzoVBxDrPyKyI41Qyoxnau4Is2hS7Yh40lwTvUbf28IjqZKRhh8W99Lqe12D5cC2IQmW SWQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AlnycKOB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l6si18845091ejp.140.2020.12.28.06.54.52; Mon, 28 Dec 2020 06:55:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AlnycKOB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2501980AbgL1OSi (ORCPT + 99 others); Mon, 28 Dec 2020 09:18:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:53532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2501965AbgL1OSb (ORCPT ); Mon, 28 Dec 2020 09:18:31 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D5C6E207B2; Mon, 28 Dec 2020 14:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165064; bh=71SKSY2/USImcQ3Tk3tHrznhLVVAnQnCVzoOstVk+NY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AlnycKOB61R/PMcXMM6KTnQxkjf4Tn0IWLsq8mMC7rJxZa4aYdjfgGab1AwLUH7Gn 3EyD2CvSoKAUp3MA1ZGbofbCOf+PlC/ZSdoZBSzw66SNNYMH9hmOCdMVYWRxpremgG M3x1kxVfL+i8RZJjaRSOJzskZTLVawmtJmGP1bHY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Avihai Horon , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.10 397/717] RDMA/uverbs: Fix incorrect variable type Date: Mon, 28 Dec 2020 13:46:35 +0100 Message-Id: <20201228125040.019723744@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Avihai Horon [ Upstream commit e0da68994d16b46384cce7b86eb645f1ef7c51ef ] Fix incorrect type of max_entries in UVERBS_METHOD_QUERY_GID_TABLE - max_entries is of type size_t although it can take negative values. The following static check revealed it: drivers/infiniband/core/uverbs_std_types_device.c:338 ib_uverbs_handler_UVERBS_METHOD_QUERY_GID_TABLE() warn: 'max_entries' unsigned <= 0 Fixes: 9f85cbe50aa0 ("RDMA/uverbs: Expose the new GID query API to user space") Link: https://lore.kernel.org/r/20201208073545.9723-4-leon@kernel.org Reported-by: Dan Carpenter Signed-off-by: Avihai Horon Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/uverbs_std_types_device.c | 14 +++++--------- include/rdma/uverbs_ioctl.h | 10 ++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/infiniband/core/uverbs_std_types_device.c b/drivers/infiniband/core/uverbs_std_types_device.c index 302f898c5833f..9ec6971056fa8 100644 --- a/drivers/infiniband/core/uverbs_std_types_device.c +++ b/drivers/infiniband/core/uverbs_std_types_device.c @@ -317,8 +317,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_GID_TABLE)( struct ib_device *ib_dev; size_t user_entry_size; ssize_t num_entries; - size_t max_entries; - size_t num_bytes; + int max_entries; u32 flags; int ret; @@ -336,19 +335,16 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_GID_TABLE)( attrs, UVERBS_ATTR_QUERY_GID_TABLE_RESP_ENTRIES, user_entry_size); if (max_entries <= 0) - return -EINVAL; + return max_entries ?: -EINVAL; ucontext = ib_uverbs_get_ucontext(attrs); if (IS_ERR(ucontext)) return PTR_ERR(ucontext); ib_dev = ucontext->device; - if (check_mul_overflow(max_entries, sizeof(*entries), &num_bytes)) - return -EINVAL; - - entries = uverbs_zalloc(attrs, num_bytes); - if (!entries) - return -ENOMEM; + entries = uverbs_kcalloc(attrs, max_entries, sizeof(*entries)); + if (IS_ERR(entries)) + return PTR_ERR(entries); num_entries = rdma_query_gid_table(ib_dev, entries, max_entries); if (num_entries < 0) diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index b00270c72740f..94fac55772f57 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -862,6 +862,16 @@ static inline __malloc void *uverbs_zalloc(struct uverbs_attr_bundle *bundle, { return _uverbs_alloc(bundle, size, GFP_KERNEL | __GFP_ZERO); } + +static inline __malloc void *uverbs_kcalloc(struct uverbs_attr_bundle *bundle, + size_t n, size_t size) +{ + size_t bytes; + + if (unlikely(check_mul_overflow(n, size, &bytes))) + return ERR_PTR(-EOVERFLOW); + return uverbs_zalloc(bundle, bytes); +} int _uverbs_get_const(s64 *to, const struct uverbs_attr_bundle *attrs_bundle, size_t idx, s64 lower_bound, u64 upper_bound, s64 *def_val); -- 2.27.0