Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2286699imm; Thu, 7 Jun 2018 08:12:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLdXFBv/EouLgsiy0XqjCoOK4x4WZJDBZkIPef9ssp+GarYQPGbRSzosWBMunzf1C+TAcRA X-Received: by 2002:a63:721d:: with SMTP id n29-v6mr1902942pgc.194.1528384371091; Thu, 07 Jun 2018 08:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528384371; cv=none; d=google.com; s=arc-20160816; b=vROXVmTOc9cTE3zFV4neTKtvcXG5WKU0CG0LRE9Wp+41tRliR2oR6qam+Cm0zzbWb1 3jpZrxPnWeBfzRn0bp5Ya7Xyz2T3KhO2wB4x+jV+dfhb9eTU0CjkvL9i8InFcBkKo6qs a8eDNraiBkA4+II5hldVFrgUAwQbSXLeZThx5lg0sdQW8eT4voGpDHS9a/xapsB8lbOT 0Ddmo5uVY0mPGPjKADw/lS1eVX8k8hedP179Qr7dsayy+FkeXB/tPnmSuApe2VcNldLs g0/I3cSc9xU6VNHanZwpjgi17c2mNCX4jAqzl3Lz6vHpJCt9FYl+PDHcqYlo7T6gO6eu LE7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=6ooeiqIJYucCd6InGcHeXC5I3i60jhHR/HhpXokEQA4=; b=uIPYbzbfVIZx0aln4u5moxZ+FTk7A+IzPt1BBn+xZhSYEqPIS8GPJMGFOK6pcGvzGW QP9KL40+gvX4Wsj465dzXKsZ09iY+4x4QAZ0VuTin3IC5y8WoaAu8EoZaNH4EfX2fOk8 r+qZ5MDa2OavppTNVF1R12gbfWU+8bGZNu3B6heOtSWQzv2Lq4GkhZ1RUJ9X+/m7CTEC jKmI0Wn1jrO1uZftu4SrTHrnubOuScHn5ATw2wvK4flmW6sCCho4f3rJKsQfo8bNPF84 eZh3eVwP2JOXxUzAElzFm29m8QvoZ0iY8gf3Fj4RnteWksDMPoRFBNmn1iMdfu6846pm vUnA== ARC-Authentication-Results: i=1; mx.google.com; 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 t5-v6si3320643pgr.690.2018.06.07.08.12.36; Thu, 07 Jun 2018 08:12:51 -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; 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 S935925AbeFGPLa (ORCPT + 99 others); Thu, 7 Jun 2018 11:11:30 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41473 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964998AbeFGPDB (ORCPT ); Thu, 7 Jun 2018 11:03:01 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbQ-0005Zv-6z; Thu, 07 Jun 2018 15:09:24 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbC-0003DM-BB; Thu, 07 Jun 2018 15:09:10 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "syzkaller" , "Doug Ledford" , "Yishai Hadas" , "Leon Romanovsky" , "Noa Osherovich" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 341/410] RDMA/mlx5: Fix integer overflow while resizing CQ In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Leon Romanovsky commit 28e9091e3119933c38933cb8fc48d5618eb784c8 upstream. The user can provide very large cqe_size which will cause to integer overflow as it can be seen in the following UBSAN warning: ======================================================================= UBSAN: Undefined behaviour in drivers/infiniband/hw/mlx5/cq.c:1192:53 signed integer overflow: 64870 * 65536 cannot be represented in type 'int' CPU: 0 PID: 267 Comm: syzkaller605279 Not tainted 4.15.0+ #90 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014 Call Trace: dump_stack+0xde/0x164 ? dma_virt_map_sg+0x22c/0x22c ubsan_epilogue+0xe/0x81 handle_overflow+0x1f3/0x251 ? __ubsan_handle_negate_overflow+0x19b/0x19b ? lock_acquire+0x440/0x440 mlx5_ib_resize_cq+0x17e7/0x1e40 ? cyc2ns_read_end+0x10/0x10 ? native_read_msr_safe+0x6c/0x9b ? cyc2ns_read_end+0x10/0x10 ? mlx5_ib_modify_cq+0x220/0x220 ? sched_clock_cpu+0x18/0x200 ? lookup_get_idr_uobject+0x200/0x200 ? rdma_lookup_get_uobject+0x145/0x2f0 ib_uverbs_resize_cq+0x207/0x3e0 ? ib_uverbs_ex_create_cq+0x250/0x250 ib_uverbs_write+0x7f9/0xef0 ? cyc2ns_read_end+0x10/0x10 ? print_irqtrace_events+0x280/0x280 ? ib_uverbs_ex_create_cq+0x250/0x250 ? uverbs_devnode+0x110/0x110 ? sched_clock_cpu+0x18/0x200 ? do_raw_spin_trylock+0x100/0x100 ? __lru_cache_add+0x16e/0x290 __vfs_write+0x10d/0x700 ? uverbs_devnode+0x110/0x110 ? kernel_read+0x170/0x170 ? sched_clock_cpu+0x18/0x200 ? security_file_permission+0x93/0x260 vfs_write+0x1b0/0x550 SyS_write+0xc7/0x1a0 ? SyS_read+0x1a0/0x1a0 ? trace_hardirqs_on_thunk+0x1a/0x1c entry_SYSCALL_64_fastpath+0x1e/0x8b RIP: 0033:0x433549 RSP: 002b:00007ffe63bd1ea8 EFLAGS: 00000217 ======================================================================= Cc: syzkaller Fixes: bde51583f49b ("IB/mlx5: Add support for resize CQ") Reported-by: Noa Osherovich Reviewed-by: Yishai Hadas Signed-off-by: Leon Romanovsky Signed-off-by: Doug Ledford Signed-off-by: Ben Hutchings --- drivers/infiniband/hw/mlx5/cq.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/infiniband/hw/mlx5/cq.c +++ b/drivers/infiniband/hw/mlx5/cq.c @@ -956,7 +956,12 @@ static int resize_user(struct mlx5_ib_de if (ucmd.reserved0 || ucmd.reserved1) return -EINVAL; - umem = ib_umem_get(context, ucmd.buf_addr, entries * ucmd.cqe_size, + /* check multiplication overflow */ + if (ucmd.cqe_size && SIZE_MAX / ucmd.cqe_size <= entries - 1) + return -EINVAL; + + umem = ib_umem_get(context, ucmd.buf_addr, + (size_t)ucmd.cqe_size * entries, IB_ACCESS_LOCAL_WRITE, 1); if (IS_ERR(umem)) { err = PTR_ERR(umem);