From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752088AbcEQWmG (ORCPT ); Tue, 17 May 2016 18:42:06 -0400 Received: from outbound.smtp.vt.edu ([198.82.183.121]:56323 "EHLO omr2.cc.vt.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751433AbcEQWmE (ORCPT ); Tue, 17 May 2016 18:42:04 -0400 X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.6+dev To: "James E.J. Bottomley" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: UBSAN whinge in scsi_devinfo.c From: Valdis Kletnieks Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==_Exmh_1463524920_1953P"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Date: Tue, 17 May 2016 18:42:00 -0400 Message-ID: <8999.1463524920@turing-police.cc.vt.edu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --==_Exmh_1463524920_1953P Content-Type: text/plain; charset=us-ascii Seen at boot in a UBSAN-enabled kernel: [ 2.936388] ================================================================================ [ 2.936392] UBSAN: Undefined behaviour in drivers/scsi/scsi_devinfo.c:457:21 [ 2.936396] index 8 is out of range for type 'char [8]' The code: 452 if (devinfo->compatible) { 453 /* 454 * Behave like the older version of get_device_flags. 455 */ 456 if (memcmp(devinfo->vendor, vskip, vmax) || 457 devinfo->vendor[vmax]) 458 continue; 459 if (memcmp(devinfo->model, mskip, mmax) || 460 devinfo->model[mmax]) 461 continue; 462 return devinfo; As near as I can tell, intentionally dereferencing past the end of the vendor or model strings is well into "just happens to work" - and I'm convinced this is actually buggy for entries that have 16-character model identifiers, as the next field is an 'unsigned flags'. And that's going to fail miserably on a big-endian machine where the flags aren't in the next byte that follows the 16 chars of model.... The entire splat: [ 2.936388] ================================================================================ [ 2.936392] UBSAN: Undefined behaviour in drivers/scsi/scsi_devinfo.c:457:21 [ 2.936396] index 8 is out of range for type 'char [8]' [ 2.936401] CPU: 0 PID: 98 Comm: kworker/u8:1 Not tainted 4.6.0-next-20160517-00001-gede618fce89c-dirty #279 [ 2.936412] Hardware name: Dell Inc. Latitude E6530/07Y85M, BIOS A17 08/19/2015 [ 2.936424] Workqueue: events_unbound async_run_entry_fn [ 2.936432] 0000000000000000 00000000ce26f4e7 ffff8802236eba38 ffffffffaa690aea [ 2.936439] ffff8802236eba50 00000000ce26f4e7 ffff8802236eba60 0000000000000008 [ 2.936446] ffff8802236eba50 ffffffffaa7087ad ffffffffabccafc0 ffff8802236ebaa8 [ 2.936449] Call Trace: [ 2.936459] [] dump_stack+0x7b/0xd1 [ 2.936464] [] ubsan_epilogue+0xd/0x40 [ 2.936468] [] __ubsan_handle_out_of_bounds+0x75/0xa0 [ 2.936472] [] ? percpu_down_read_trylock+0xa8/0xb0 [ 2.936478] [] scsi_dev_info_list_find+0x282/0x300 [ 2.936482] [] scsi_get_device_flags_keyed+0x21/0xb0 [ 2.936487] [] scsi_get_device_flags+0x10/0x20 [ 2.936492] [] scsi_probe_and_add_lun+0x502/0x1200 [ 2.936497] [] ? _raw_spin_unlock_irqrestore+0x87/0x90 [ 2.936503] [] __scsi_add_device+0x121/0x150 [ 2.936510] [] ata_scsi_scan_host+0x127/0x240 [ 2.936514] [] async_port_probe+0x4a/0x90 [ 2.936518] [] async_run_entry_fn+0x68/0x1b0 [ 2.936523] [] process_one_work+0x3bf/0xdb0 [ 2.936526] [] ? process_one_work+0x329/0xdb0 [ 2.936531] [] worker_thread+0x351/0xad0 [ 2.936536] [] ? process_one_work+0xdb0/0xdb0 [ 2.936540] [] kthread+0x142/0x1b0 [ 2.936549] [] ret_from_fork+0x1f/0x40 [ 2.936553] [] ? kthread_create_on_node+0x280/0x280 [ 2.936557] ================================================================================ --==_Exmh_1463524920_1953P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Exmh version 2.5 07/13/2001 iQIVAwUBVzueOAdmEQWDXROgAQJHphAAoy4MCZAAkdhtq2A8FBpmGnXl0JPV2+ZS Myrw9CnGzRKtbxDjbwBoSSpLQxicV/tP1DlVH6CUzQnfc012LYNtDCG5RsSxm2DE VYWxniLOvqCRjVK5I1dpIzNSxDDEgGjq2pvr+d6dgLW+ghX86MxugbrM+XXxRaWm p3Disz1mY6Y4f6QzbjnHA1h2D0ZdQ8+eCfRGRgzkpam/NzUA2oLOvoxDUFJ+igEG SsZ5DjzWktzK17pHdc1GeK7NdIaA2Xm3U6Hx+EYXHqzypCJaCLQjwCEFEeghqh1Y x9PhountwaqtETcfTOaoAirJn7br2EVkAW6CXGutEZudNohA6sfc52Jz/7OW8f/z bNIUZCOQGLPmK2RR33oGZTeI1hZZer4RvW1Aj/LYCWXYS5Jgazu3TSh6MFqQ2R5J UhqvOUYlMcFcn3mV2iQakhm2O/GFhyTVE5TtLVeR3ExrEAohOY7RyF9VHN/0zZCN C4A3TzmJ4yaxSOyVxcvUDdn3S1cumv/bRcBcv4+6Z4VrRtE1sreWMIghirm0XCTk v+8cZWY4uW8HU4UvqzuPniJ6N6Nw+ozdLTVNEgAFXUzTPvYlFMEetaaylMPuM6xL XssCfk6yxSBXIG83n84Bnj92UJyu1u03qQwxJdcpjTmgqmgwEcahpKO8AyUo4YFE gk+ZYtDzSL4= =I79x -----END PGP SIGNATURE----- --==_Exmh_1463524920_1953P--