From patchwork Wed Aug 1 06:09:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10551727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B6D113B8 for ; Wed, 1 Aug 2018 06:10:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B9582A4E3 for ; Wed, 1 Aug 2018 06:10:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F7542A4ED; Wed, 1 Aug 2018 06:10:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CDAA2A4E8 for ; Wed, 1 Aug 2018 06:10:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733202AbeHAHxt (ORCPT ); Wed, 1 Aug 2018 03:53:49 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41665 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733057AbeHAHxs (ORCPT ); Wed, 1 Aug 2018 03:53:48 -0400 Received: by mail-pf1-f194.google.com with SMTP id y10-v6so7285398pfn.8 for ; Tue, 31 Jul 2018 23:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MKaP/zsQ/C9AJcu/cT5JowGOCZDXJ5vFUW/yzanzt98=; b=A/c6gMsLbsnGEkuqw8WWXkR+JVe+3224Ry7whkTAUwED5Io0yvkVcU2moVWuejXNz2 KceOk2G1XAWWR813xYJhgeLxv6sac8lrtfetkN4a/rxmcp4hZC0rdUGyg0bH3bNuyc5d EQPFRwL6+YAWvdhQoNB4AckGgQDzenWYID3tg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MKaP/zsQ/C9AJcu/cT5JowGOCZDXJ5vFUW/yzanzt98=; b=N4ZPdEqqbZUGtU9BHM0DRqzrku4+7S9MZb2dL1LevgAKjcMchJ0b9wYU9SQZItAhXy Afc5oLQ9aM5Qs2xNOYouJgmREoEKXVMbzDYwJ9RN89DuGJ+uebOEc7XPqNu47Daxj9AJ 00HBN0FlMimHOX6TKEn0vTu8190mfG+eVkSZJixWD/r/aadzoN3eYZFe4E0K1wP0fXi2 kGxAdrt7DHVGQdw55kqbRr/O7nnKaojHlTrt9oL5JZMx2dkarEz96eiugdcoihHKCiXg Y26JEj+n7jI9MPGvcjaQU0En2rvDIn7LOMwWJl8IOvXMWxMfjCdbaycYmcRQP+0jVZSz OIFA== X-Gm-Message-State: AOUpUlHeLsQoQSNCQQuaychID2+3wdGCwW+xW3U+b8vhiPwqUZypWkic B3uyVVXayvmHjVUOaTz+giECB6Dn4mY= X-Google-Smtp-Source: AAOMgpeu5y1TFl/5snJUKbTMbCYh+XvcT6/9oucwuptuDWc5ZRY34aiA9bZphlQKPGAtx+6zRFGIQw== X-Received: by 2002:a63:4306:: with SMTP id q6-v6mr22586380pga.181.1533103791865; Tue, 31 Jul 2018 23:09:51 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id q85-v6sm31433124pfa.151.2018.07.31.23.09.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Jul 2018 23:09:49 -0700 (PDT) From: Kees Cook To: Rasmus Villemoes Cc: Kees Cook , Leon Romanovsky , stable@vger.kernel.org, syzkaller , Jason Gunthorpe , Leon Romanovsky , Bart Van Assche , Doug Ledford , Dan Carpenter , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] RDMA/mlx5: Fix shift overflow in mlx5_ib_create_wq Date: Tue, 31 Jul 2018 23:09:47 -0700 Message-Id: <20180801060947.16670-4-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180801060947.16670-1-keescook@chromium.org> References: <20180801060947.16670-1-keescook@chromium.org> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Leon Romanovsky [ 61.182439] UBSAN: Undefined behaviour in drivers/infiniband/hw/mlx5/qp.c:5366:34 [ 61.183673] shift exponent 4294967288 is too large for 32-bit type 'unsigned int' [ 61.185530] CPU: 0 PID: 639 Comm: qp Not tainted 4.18.0-rc1-00037-g4aa1d69a9c60-dirty #96 [ 61.186981] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-2.fc27 04/01/2014 [ 61.188315] Call Trace: [ 61.188661] dump_stack+0xc7/0x13b [ 61.190427] ubsan_epilogue+0x9/0x49 [ 61.190899] __ubsan_handle_shift_out_of_bounds+0x1ea/0x22f [ 61.197040] mlx5_ib_create_wq+0x1c99/0x1d50 [ 61.206632] ib_uverbs_ex_create_wq+0x499/0x820 [ 61.213892] ib_uverbs_write+0x77e/0xae0 [ 61.248018] vfs_write+0x121/0x3b0 [ 61.249831] ksys_write+0xa1/0x120 [ 61.254024] do_syscall_64+0x7c/0x2a0 [ 61.256178] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 61.259211] RIP: 0033:0x7f54bab70e99 [ 61.262125] Code: 00 f3 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 [ 61.268678] RSP: 002b:00007ffe1541c318 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 [ 61.271076] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f54bab70e99 [ 61.273795] RDX: 0000000000000070 RSI: 0000000020000240 RDI: 0000000000000003 [ 61.276982] RBP: 00007ffe1541c330 R08: 00000000200078e0 R09: 0000000000000002 [ 61.280035] R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004005c0 [ 61.283279] R13: 00007ffe1541c420 R14: 0000000000000000 R15: 0000000000000000 Cc: # 4.7 Fixes: 79b20a6c3014 ("IB/mlx5: Add receive Work Queue verbs") Cc: syzkaller Reported-by: Noa Osherovich Signed-off-by: Leon Romanovsky Signed-off-by: Kees Cook --- drivers/infiniband/hw/mlx5/qp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index a4f1f638509f..7fc156db643d 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -5365,7 +5365,10 @@ static int set_user_rq_size(struct mlx5_ib_dev *dev, rwq->wqe_count = ucmd->rq_wqe_count; rwq->wqe_shift = ucmd->rq_wqe_shift; - rwq->buf_size = (rwq->wqe_count << rwq->wqe_shift); + if (check_shift_overflow(rwq->wqe_count, rwq->wqe_shift, + &rwq->buf_size)) + return -EINVAL; + rwq->log_rq_stride = rwq->wqe_shift; rwq->log_rq_size = ilog2(rwq->wqe_count); return 0;