Received: by 10.192.165.156 with SMTP id m28csp1614388imm; Tue, 17 Apr 2018 02:21:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx480OIhKRF97RlEE71fnzzeR/qQ/frlxPse3RrDPPsTqYV2ycJAe59GrcGv4Oji3ZjiBZ6aJ X-Received: by 10.101.75.12 with SMTP id r12mr1158484pgq.36.1523956918373; Tue, 17 Apr 2018 02:21:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b129si11246985pgc.387.2018.04.17.02.21.44; Tue, 17 Apr 2018 02:21:58 -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=fail header.i=@natalenko.name header.s=dkim-20170712 header.b=YUUFIuQ9; arc=fail (signature failed); 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=natalenko.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752696AbeDQJUA (ORCPT + 99 others); Tue, 17 Apr 2018 05:20:00 -0400 Received: from vulcan.natalenko.name ([104.207.131.136]:35484 "EHLO vulcan.natalenko.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752048AbeDQJT4 (ORCPT ); Tue, 17 Apr 2018 05:19:56 -0400 ARC-Authentication-Results: i=1; auth=pass smtp.auth=oleksandr@natalenko.name smtp.mailfrom=oleksandr@natalenko.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=natalenko.name; s=dkim-20170712; t=1523956797; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvY8HO0+Nssvn2xR4xFCiW8lZXXG3VIQ8j+5mXg2HH8=; b=YUUFIuQ92F3TOx5HDA995pIFeM7eut7cVKXqJkcg8qKxjWdcAHz8tkbJ96kqIg3GuZcU9w Kukc5c46uBftowVSeVYngDQ5lHiSy7LwqP3MiHQcY/zSlzpXO46PnIl03r6iqNQRUJ9w9Y 2atlNSY/4c4Wokx6MIe8jsmTOsJhDRg= ARC-Seal: i=1; s=arc-20170712; d=natalenko.name; t=1523956797; a=rsa-sha256; cv=none; b=u8qd9GU4zrkC0hvhDKRHCOEorwwSzTa7yGshAVTarUbpyRX7iZB0/CQJqSsakYPm96y0TQSOEPfFbUmAEPM3bvT8dYcOqQWKJx6V9yfYwQQDn42gd/gfzk5G81PkCtMWjOEQPhNhlFSbWJQcNp3Jm/QrKGFZ/Faw+6Dee9f+ZxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=natalenko.name; s=arc-20170712; t=1523956797; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvY8HO0+Nssvn2xR4xFCiW8lZXXG3VIQ8j+5mXg2HH8=; b=c2zAAmsSqvoo0rsQGXWAqH3t/rkh2wCWgap4cALdqSb8GJ/6E16Zj74hYDGKDZiaCeAYTO HXjUJnKm2Xmwool/bwH1HeXq0TgD8DDP6HziR/5yvsw+lkKavHYcVMikzwChcS4dWlwg66 GAjFn0ecRZt9F5muhb9ddjk6EXDzB8M= Received: from mail.natalenko.name (vulcan.natalenko.name [IPv6:fe80::5400:ff:fe0c:dfa0]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by vulcan.natalenko.name (Postfix) with ESMTPSA id 2B18C33B51C; Tue, 17 Apr 2018 11:19:57 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 vulcan.natalenko.name 2B18C33B51C Authentication-Results: vulcan.natalenko.name; dmarc=fail (p=none dis=none) header.from=natalenko.name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 17 Apr 2018 11:19:57 +0200 From: Oleksandr Natalenko To: Kees Cook Cc: Jens Axboe , Bart Van Assche , Paolo Valente , David Windsor , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, LKML , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , linux-block@vger.kernel.org, keescook@google.com Subject: Re: usercopy whitelist woe in scsi_sense_cache In-Reply-To: References: <10360653.ov98egbaqx@natalenko.name> <2864697.7uzmEJovl2@natalenko.name> Message-ID: <8faec18239a6104b250d9668bb1d3abc@natalenko.name> X-Sender: oleksandr@natalenko.name User-Agent: Roundcube Webmail/1.3.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi. 17.04.2018 05:12, Kees Cook wrote: >> Turning off HARDENED_USERCOPY and turning on KASAN, I see the same >> report: >> >> [ 38.274106] BUG: KASAN: slab-out-of-bounds in >> _copy_to_user+0x42/0x60 >> [ 38.274841] Read of size 22 at addr ffff8800122b8c4b by task >> smartctl/1064 >> [ 38.275630] >> [ 38.275818] CPU: 2 PID: 1064 Comm: smartctl Not tainted >> 4.17.0-rc1-ARCH+ #266 >> [ 38.276631] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), >> BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 >> [ 38.277690] Call Trace: >> [ 38.277988] dump_stack+0x71/0xab >> [ 38.278397] ? _copy_to_user+0x42/0x60 >> [ 38.278833] print_address_description+0x6a/0x270 >> [ 38.279368] ? _copy_to_user+0x42/0x60 >> [ 38.279800] kasan_report+0x243/0x360 >> [ 38.280221] _copy_to_user+0x42/0x60 >> [ 38.280635] sg_io+0x459/0x660 >> ... >> >> Though we get slightly more details (some we already knew): >> >> [ 38.301330] Allocated by task 329: >> [ 38.301734] kmem_cache_alloc_node+0xca/0x220 >> [ 38.302239] scsi_mq_init_request+0x64/0x130 [scsi_mod] >> [ 38.302821] blk_mq_alloc_rqs+0x2cf/0x370 >> [ 38.303265] blk_mq_sched_alloc_tags.isra.4+0x7d/0xb0 >> [ 38.303820] blk_mq_init_sched+0xf0/0x220 >> [ 38.304268] elevator_switch+0x17a/0x2c0 >> [ 38.304705] elv_iosched_store+0x173/0x220 >> [ 38.305171] queue_attr_store+0x72/0xb0 >> [ 38.305602] kernfs_fop_write+0x188/0x220 >> [ 38.306049] __vfs_write+0xb6/0x330 >> [ 38.306436] vfs_write+0xe9/0x240 >> [ 38.306804] ksys_write+0x98/0x110 >> [ 38.307181] do_syscall_64+0x6d/0x1d0 >> [ 38.307590] entry_SYSCALL_64_after_hwframe+0x44/0xa9 >> [ 38.308142] >> [ 38.308316] Freed by task 0: >> [ 38.308652] (stack is not available) >> [ 38.309060] >> [ 38.309243] The buggy address belongs to the object at >> ffff8800122b8c00 >> [ 38.309243] which belongs to the cache scsi_sense_cache of size 96 >> [ 38.310625] The buggy address is located 75 bytes inside of >> [ 38.310625] 96-byte region [ffff8800122b8c00, ffff8800122b8c60) > > With a hardware watchpoint, I've isolated the corruption to here: > > bfq_dispatch_request+0x2be/0x1610: > __bfq_dispatch_request at block/bfq-iosched.c:3902 > 3900 if (rq) { > 3901 inc_in_driver_start_rq: > 3902 bfqd->rq_in_driver++; > 3903 start_rq: > 3904 rq->rq_flags |= RQF_STARTED; > 3905 } > > Through some race condition(?), rq_in_driver is also sense_buffer, and > it can get incremented. > … > I still haven't figured this out, though... any have a moment to look > at this? By any chance, have you tried to simplify the reproducer environment, or it still needs my complex layout to trigger things even with KASAN? Regards, Oleksandr