Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2021210imm; Thu, 24 May 2018 04:39:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr8+U1P5+3JRWSVse61K7fxQ6I0dgsIsCwvJ9daQVQ5hiz/Fl/UhtEjzudsMgXRWE8xGVuM X-Received: by 2002:a17:902:aa95:: with SMTP id d21-v6mr6938857plr.73.1527161962683; Thu, 24 May 2018 04:39:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527161962; cv=none; d=google.com; s=arc-20160816; b=d0a+zcC6KqXGtbrgGwLewdqUS8KWKlCTVW8DlKfi1k0PQReTVBgh6caJBwpyxd8etf l/Rj+mA2roJtiVMw3S3unHWtjkgbEI1i982xvqbkS4cXNQW7txb1Oj6py6mN1OTN/AZ2 3btZugDyI6Uj0t7WAB7yzP5nn35VcEXSxLurhJ4mXOCJ+wMkIjMGhPcwRw/I1oACgtRD Hc4Rw685fuFzOei+f0TmqMk/++hpNNRBAXachcOTpTiFBl6Yh8n/k7YDsFvqbZ0jZQrk +t7x2DI0TZ2ZNYrV84gwuiwQJIvBsKfmpJiziFVljrllWgbvmyOt3ooCIohFYqhoPiTP ySLA== 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=YhZiQLIFkGtZklukEdPobZycJzZAXEgoj5wJ392yTO0=; b=GeC8YYgaK+y8JBc0md4z9mM4fsLSnB5DtPvbv2sxNidnzjSLrjYZqeXS9+cD0g/SOQ 79wr+agyAFsfZkHD+F3UUlw6wvNWQdnAKfZtgKB20wcuQUvdkXWvgvK1UHOlT5g1LsvU 5e9KrMBQ4KuoPyJfU9zYV1Y9lAPvWRhpXMf+7Lu5J/a7LFebdL/eTH91ftLUO331E4/5 3RCzGMLBFeugLqGEZ4akD3MnYD6gP8+biyUi2FAUwzcO1qyBCRpVdk/eBRouN5fkM6Mp UiWO8vdDT4LcWKb/Jw2khlEBMtY8CJANxrBg0n3oayT7byqUgptB0YfA7tS+z3zIt5VW DRcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tK0rsKPY; 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 d18-v6si21322865plr.265.2018.05.24.04.39.08; Thu, 24 May 2018 04:39:22 -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=tK0rsKPY; 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 S1033178AbeEXLia (ORCPT + 99 others); Thu, 24 May 2018 07:38:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:37578 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967308AbeEXJtT (ORCPT ); Thu, 24 May 2018 05:49:19 -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 8EAF320894; Thu, 24 May 2018 09:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155359; bh=o9HCZu7nu8QxAfKp9zbKIRYJI8COirOZTiawiO5XWkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tK0rsKPY488vStt3oIOgx0w8QCQphXVYiiUxjzCpJrLXuRNj3Dax7X+XzfiCPe5XF zAvsBsv/vZzbuQtfd/1Q1bbtTvCGRdkpeLzoq7guLBs/AZ6DP9oaM63NYhjty55AN0 eeYfi1mC01+oQ3Lo2+kLluuib0ogmuGV1YcYoOEk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Meelis Roos , Bart Van Assche , Himanshu Madhani , Laurence Oberman , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 56/96] scsi: qla2xxx: Avoid triggering undefined behavior in qla2x00_mbx_completion() Date: Thu, 24 May 2018 11:38:39 +0200 Message-Id: <20180524093608.717835490@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche [ Upstream commit c02189e12ce3bf3808cb880569d3b10249f50bd9 ] A left shift must shift less than the bit width of the left argument. Avoid triggering undefined behavior if ha->mbx_count == 32. This patch avoids that UBSAN reports the following complaint: UBSAN: Undefined behaviour in drivers/scsi/qla2xxx/qla_isr.c:275:14 shift exponent 32 is too large for 32-bit type 'int' Call Trace: dump_stack+0x4e/0x6c ubsan_epilogue+0xd/0x3b __ubsan_handle_shift_out_of_bounds+0x112/0x14c qla2x00_mbx_completion+0x1c5/0x25d [qla2xxx] qla2300_intr_handler+0x1ea/0x3bb [qla2xxx] qla2x00_mailbox_command+0x77b/0x139a [qla2xxx] qla2x00_mbx_reg_test+0x83/0x114 [qla2xxx] qla2x00_chip_diag+0x354/0x45f [qla2xxx] qla2x00_initialize_adapter+0x2c2/0xa4e [qla2xxx] qla2x00_probe_one+0x1681/0x392e [qla2xxx] pci_device_probe+0x10b/0x1f1 driver_probe_device+0x21f/0x3a4 __driver_attach+0xa9/0xe1 bus_for_each_dev+0x6e/0xb5 driver_attach+0x22/0x3c bus_add_driver+0x1d1/0x2ae driver_register+0x78/0x130 __pci_register_driver+0x75/0xa8 qla2x00_module_init+0x21b/0x267 [qla2xxx] do_one_initcall+0x5a/0x1e2 do_init_module+0x9d/0x285 load_module+0x20db/0x38e3 SYSC_finit_module+0xa8/0xbc SyS_finit_module+0x9/0xb do_syscall_64+0x77/0x271 entry_SYSCALL64_slow_path+0x25/0x25 Reported-by: Meelis Roos Signed-off-by: Bart Van Assche Cc: Himanshu Madhani Reviewed-by: Laurence Oberman Acked-by: Himanshu Madhani Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/qla2xxx/qla_isr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/scsi/qla2xxx/qla_isr.c +++ b/drivers/scsi/qla2xxx/qla_isr.c @@ -272,7 +272,8 @@ qla2x00_mbx_completion(scsi_qla_host_t * struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; /* Read all mbox registers? */ - mboxes = (1 << ha->mbx_count) - 1; + WARN_ON_ONCE(ha->mbx_count > 32); + mboxes = (1ULL << ha->mbx_count) - 1; if (!ha->mcp) ql_dbg(ql_dbg_async, vha, 0x5001, "MBX pointer ERROR.\n"); else @@ -2516,7 +2517,8 @@ qla24xx_mbx_completion(scsi_qla_host_t * struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; /* Read all mbox registers? */ - mboxes = (1 << ha->mbx_count) - 1; + WARN_ON_ONCE(ha->mbx_count > 32); + mboxes = (1ULL << ha->mbx_count) - 1; if (!ha->mcp) ql_dbg(ql_dbg_async, vha, 0x504e, "MBX pointer ERROR.\n"); else