Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4010948imm; Mon, 14 May 2018 00:57:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpxhJto7/jGLP65ZrU9l+qI/6SUh6sx0JUyqHhrQMsi5t8uAevBoEsTVCIGfTUuGXCFyHWV X-Received: by 2002:a62:6a0a:: with SMTP id f10-v6mr9212570pfc.99.1526284625711; Mon, 14 May 2018 00:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526284625; cv=none; d=google.com; s=arc-20160816; b=YqvJh+r2MISfYGR6D2EAcpEGktOwhCj7vYvbmNpDcTQcg2L6gKvyKfnTvX0nJ+AZo+ /NA6NwY3zSILCtg96//TzkQVfRI7mUiNXfuTQudfoE+N/cNstuKewNmM9zLF2AfolvrI 46C23yYMhtuDrNzqjTVqBBD7ID+k6dO6zP9GvoMYWGJxKtybZOSEC8DI90obDlRxFI0F 9nHCYOqkN7i/cBMkTcsLRcl5DxFK1bmg3VFefyvzvax8uFVRm7GDY05sxrz18X088bnu xkV/d2acDGMAQfGc+acraosYqSnw5jEJg1yg60v/BLeaUybiFEdh72QTfFSlOQrtVFOP Jbqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=n92luJ9bZJXIy3nT7Zp3dIjoUyn9g3dxBGuEpoAX7Lo=; b=TYOAe/H8zPE/SiA7u37uf40nxMiue6MXrQH3mGm3e1u3iXQtXv9D3frI/3140e4NXy iUFy5xeTEHwYkFQ4L8yr2vjzGR/MqDFfTDLeWnK5390J7zSJvjSjAq/gx8FKWS8HG4ig HPDTbZyeHapuCOenQ842V6QNVw7580T0NmnRbkNimpqaeGCPOcnIlIIbu8U1nuRCsi9r CEkwHQvR5sw1zJPLGXu9YvK+UbouAeSm7d5aDZOZBv78UTmfOiZHpXcIfy+ii8adLI1s p0npa7pDNkd223btrwwWbZwSmcSTFp6VJOCpMVcC6PeluVXhnVLuFlRZbwLvkIdtQ9Yw PAJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n5f4BxT/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b60-v6si9274242plc.270.2018.05.14.00.56.51; Mon, 14 May 2018 00:57:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n5f4BxT/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752190AbeENGuU (ORCPT + 99 others); Mon, 14 May 2018 02:50:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:56952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752169AbeENGuO (ORCPT ); Mon, 14 May 2018 02:50:14 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 E4AB621738; Mon, 14 May 2018 06:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526280614; bh=IJkbS5d1tSev43dVsOz51PImnOxkjmXdBaP3dKalqwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n5f4BxT/5sEBznHPeSUWqTDGDnVE4dA/CNUbaJzUlZTuH26KPyfVTcNZuK8ik3hHw JCKUXaHmHx6UeLtUQqw2vi/LNMyV1H9wNQBox8BrP7JS00XMuZR9dNZBtd04l/T2aI /9K6C1NWXvrVrPMbLWmXw42DzExAIvBiZliRhjis= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzkaller , Noa Osherovich , Leon Romanovsky , Doug Ledford Subject: [PATCH 3.18 08/23] RDMA/mlx5: Protect from shift operand overflow Date: Mon, 14 May 2018 08:48:37 +0200 Message-Id: <20180514064704.400523758@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514064704.046463679@linuxfoundation.org> References: <20180514064704.046463679@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leon Romanovsky commit 002bf2282b2d7318e444dca9ffcb994afc5d5f15 upstream. Ensure that user didn't supply values too large that can cause overflow. UBSAN: Undefined behaviour in drivers/infiniband/hw/mlx5/qp.c:263:23 shift exponent -2147483648 is negative CPU: 0 PID: 292 Comm: syzkaller612609 Not tainted 4.16.0-rc1+ #131 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.0-0-g63451fca13-prebuilt.qemu-project.org 04/01/2014 Call Trace: dump_stack+0xde/0x164 ubsan_epilogue+0xe/0x81 set_rq_size+0x7c2/0xa90 create_qp_common+0xc18/0x43c0 mlx5_ib_create_qp+0x379/0x1ca0 create_qp.isra.5+0xc94/0x2260 ib_uverbs_create_qp+0x21b/0x2a0 ib_uverbs_write+0xc2c/0x1010 vfs_write+0x1b0/0x550 SyS_write+0xc7/0x1a0 do_syscall_64+0x1aa/0x740 entry_SYSCALL_64_after_hwframe+0x26/0x9b RIP: 0033:0x433569 RSP: 002b:00007ffc6e62f448 EFLAGS: 00000217 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 00000000004002f8 RCX: 0000000000433569 RDX: 0000000000000070 RSI: 00000000200042c0 RDI: 0000000000000003 RBP: 00000000006d5018 R08: 00000000004002f8 R09: 00000000004002f8 R10: 00000000004002f8 R11: 0000000000000217 R12: 0000000000000000 R13: 000000000040c9f0 R14: 000000000040ca80 R15: 0000000000000006 Cc: # 3.10 Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Cc: syzkaller Reported-by: Noa Osherovich Signed-off-by: Leon Romanovsky Signed-off-by: Doug Ledford Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/mlx5/qp.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -174,7 +174,11 @@ static int set_rq_size(struct mlx5_ib_de } else { if (ucmd) { qp->rq.wqe_cnt = ucmd->rq_wqe_count; + if (ucmd->rq_wqe_shift > BITS_PER_BYTE * sizeof(ucmd->rq_wqe_shift)) + return -EINVAL; qp->rq.wqe_shift = ucmd->rq_wqe_shift; + if ((1 << qp->rq.wqe_shift) / sizeof(struct mlx5_wqe_data_seg) < qp->wq_sig) + return -EINVAL; qp->rq.max_gs = (1 << qp->rq.wqe_shift) / sizeof(struct mlx5_wqe_data_seg) - qp->wq_sig; qp->rq.max_post = qp->rq.wqe_cnt; } else {