From patchwork Wed Aug 1 21:25:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10553045 X-Patchwork-Delegate: jgg@ziepe.ca 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 35C4F157D for ; Wed, 1 Aug 2018 21:26:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 232D92A4BD for ; Wed, 1 Aug 2018 21:26:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 165A02B603; Wed, 1 Aug 2018 21:26:04 +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 99FE22A4BD for ; Wed, 1 Aug 2018 21:26:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731944AbeHAXNq (ORCPT ); Wed, 1 Aug 2018 19:13:46 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45632 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727086AbeHAXNc (ORCPT ); Wed, 1 Aug 2018 19:13:32 -0400 Received: by mail-pf1-f194.google.com with SMTP id i26-v6so11698pfo.12 for ; Wed, 01 Aug 2018 14:25:48 -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=+NVEOnyXNrKanEw9EhoVnZyb+Cz5NkD5LpX8qX/bm1Q=; b=b0GjZuvWjbfctXy21dCfJgbs0FBKdHiEiu7dF29nwTZmn0AzI3URw8cFRz7ZVZYTeh Gnup3kdB/ScCFBV7YxxauTRP6IveEbrWzWiBZXpv5rZ2DycyPgPXwDFtW8+XvIgpOZvs dfdtOA++uSwqNxe9Da+HwJeOt2HUteocqH0mQ= 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=+NVEOnyXNrKanEw9EhoVnZyb+Cz5NkD5LpX8qX/bm1Q=; b=oHmupg7dMQbD9aooTa5sZyC0nZZcygjshsb3efCWumn92DNqxuh3/Y3UBMnmwMUzry 4t7woAGIznM8pV5MmNa3bNBygLb6uqtvIwGHL82WxwWJCCEQC2a9qlZrj/6jVL1g/ix7 Lu8LYC4ss5NJoA9bGIwVaaoDiScEF0Fh0MGJV9nS/pwnpztRppmkA2d3csUEfaxL0YiI f1iWMM18JvEDhTP3l2qOLQh9MXZGC0VlnpqRarM3eSRut6xzyGb9SmPR7eFrpI35eAVU HHMMb/RWfdKLYuTW1peRYSJKYvXtUKRM7p2l8CzGJpndSGoPBCthC0G05VWfFxuxzDQO dwQQ== X-Gm-Message-State: AOUpUlG+sJO0ZiXIjO6Q+eZ0fMB+hCVYI8Wr9m/mGc/55KShMthmYlWV 0dk++HC1Y27TOiaCD7Vjd0vHeA== X-Google-Smtp-Source: AAOMgpcqocHiWSKQufPfZnfALwbd7dh++MyWo6XlS9jjd5qobvOOpFpGeySCxi1MdUgpVsqZD7swyA== X-Received: by 2002:a63:5866:: with SMTP id i38-v6mr36895pgm.63.1533158748113; Wed, 01 Aug 2018 14:25:48 -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 t19-v6sm13418pfk.182.2018.08.01.14.25.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Aug 2018 14:25:45 -0700 (PDT) From: Kees Cook To: Jason Gunthorpe Cc: Kees Cook , Leon Romanovsky , stable@vger.kernel.org, syzkaller , Rasmus Villemoes , Leon Romanovsky , Bart Van Assche , Doug Ledford , Dan Carpenter , Randy Dunlap , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next v4 3/3] RDMA/mlx5: Fix shift overflow in mlx5_ib_create_wq Date: Wed, 1 Aug 2018 14:25:41 -0700 Message-Id: <20180801212541.22889-4-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180801212541.22889-1-keescook@chromium.org> References: <20180801212541.22889-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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index a4f1f638509f..fa3c315f6d94 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -5365,7 +5365,9 @@ 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_shl_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;