Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1980394imm; Thu, 24 May 2018 03:59:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoQhkjXgTTn+QgI0pu9Z1Ol42bNsKMFQwWQ94+tHVaM6DuGt5GRkeHirkq8Tw5bDqNB1jZ6 X-Received: by 2002:a17:902:1e3:: with SMTP id b90-v6mr6715874plb.273.1527159582364; Thu, 24 May 2018 03:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527159582; cv=none; d=google.com; s=arc-20160816; b=x0aa+rhMAs6m7vO7KAoUyn7ccPXLgWE3L9a9KtzQxDD9/o9LMuG2cynQ0sv7qIhHGA 221DNWLFX6gSmmrMbwIeOF11EfZ+mPfw5U6ZttatA3kXxFMJ41Te82/4nEj03IZ14N+r +CdLfAwnW2tRf/sM0jYOVjVMvqpX1TREvuEBzriy/HYMywNRd/fuI6oRUxu5/tAcHZYa rDT7B7Z4Nl6SxGKkv19Prfow0YE+9pxNq3HZ1GMVxgMWy7d69kK/nl/TF2Pfvz/RnHgT tKShVfnW7ZyUx0ww8S/3vHCm0upbQ5JqbtJuHFqcOT9MOHHzcUrJtR6eKmsYZLEAPRrC NfYA== 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=C2A5XktI+y7F4qTqLdCw2GgBT1Z8P0Hh1q04wD8VqpQ=; b=HboYDRjHcQOtk6hgp1+H4oJEnC3U07+2ZSvI4nd7/bzSWePcZBlwZ4sd01EdCke0fL CEgVlJK2byE4GDlW6Meib4ir44TAmv+FPN+3x7QiDcj/AOVogv8NpfEKGJN30reqqy4U 1ww0W0lB6JFR5RbkzvX3RnDh7RV6F4TrU5aQVB68OxVfJUCopxvZKFNKBvPAbg/cF9FR YmtbpRLdLN+LgB47ITRNez9/8yD8iK79kzoWiaATfK8ue9g49DUrp3PPXTzbmhNlKVtO 9CJurJYeFDh36DKVfbzGCALNNd/iABdNcdFZg0s0ru5L0OexFiarUzsE7CDkXFQlpjFh +NDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aWD9dY2d; 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 a4-v6si20771207plp.219.2018.05.24.03.59.27; Thu, 24 May 2018 03:59:42 -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=aWD9dY2d; 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 S1030457AbeEXK6k (ORCPT + 99 others); Thu, 24 May 2018 06:58:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:35950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030226AbeEXJz4 (ORCPT ); Thu, 24 May 2018 05:55:56 -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 B1D61208A6; Thu, 24 May 2018 09:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155756; bh=2VqaeIW2FxRNZwctVsPHicMw9gtJ4t08k/VsdS2fsUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aWD9dY2doTCtHLq3Zs/8byilFpVS2f5qDZwBJmTty2Fy0xdBRZkXzmoAQ7rtkAkdh HwVR+Nhxm8RFrG1FvIiYZ8QWHK+Tbq365JXbv/nkLVgSrS6qEm5eR7mGg9i64LIpwd Za4b6ollEDGvsSdQgnKcu9PRBv2HRDGJMO8pk4lA= 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.14 105/165] scsi: qla2xxx: Avoid triggering undefined behavior in qla2x00_mbx_completion() Date: Thu, 24 May 2018 11:38:31 +0200 Message-Id: <20180524093626.262374201@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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.14-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 @@ -2821,7 +2822,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