Received: by 10.223.176.5 with SMTP id f5csp2335978wra; Wed, 31 Jan 2018 22:08:17 -0800 (PST) X-Google-Smtp-Source: AH8x227NIsINw1nWzFM+WkzV+dMQ1rnH+GBvnU+tSOHksoQOTAl75JKKbl3FYZ/NbjAQCpXtJ5uv X-Received: by 10.98.210.5 with SMTP id c5mr35344798pfg.238.1517465297424; Wed, 31 Jan 2018 22:08:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517465297; cv=none; d=google.com; s=arc-20160816; b=Q0cK8U5QLfrygvkQT5rkXqujpHr/ICtZ72W57EYFNonj8ja71wtd5iuCGycIEUxi9F +UxKmU/rEjSeZdtSYte8VSmcK2xqJStZcoWEklPc19OvflKWmqus0rHkwLcTwZm/bsWR 6OvVYdQ6cDCIlJvMiSKYDJaGoI+EbPWmr0TGw7srX39MUeuVB1So78z319OLUqozSS1E yFJqGgiyJrqpLW0FTIIdnWCvRRFYFQHksk0m8Dx+qmdkrOsvvP/PyZKljKf4RHn1LgBl mD6M7eq8nwRJssTqywO5pmUtrHrmfKNnRDeJclihJC5qFAmbJ/7QEBXxi1e56NoJjTbS kzOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject:reply-to :arc-authentication-results; bh=9YAh6C97qeMHV3UEWs1lPq6V0A0qlsz5GFiwTURkCj8=; b=aNCw3sVcDBQRjfCzxp/St420Az6TXlAYgVeyF+aDYshY9wgEcqgR2AsH4eKs0ZojVm jXTDOL1RJ9Zh5sMqfAeZBw0r3frM77lmLBtRd5s/iWPUNLR2Xm62mEXsACL1vS2Mh351 zjbIigBphGV56dbIawPQhL0B3Crmj0fSMgxpBfT2D4kcXOTeIVxAZ7hszpV0fYBvpY52 xIuYanNxTcwa9FktY1rKve+9oDYcbWqYHQFkR8vjtkKFBAXUb8j3idp4EiYjw+YX67Py Ps8Br4ScfcDVcdj60sYamRffxX3bBP3OFbqDvelqCmkY8MLoa5w4AUj5/BsUr+G2a51F 6v8Q== ARC-Authentication-Results: i=1; mx.google.com; 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 e89si1162501pfm.109.2018.01.31.22.07.49; Wed, 31 Jan 2018 22:08:17 -0800 (PST) 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; 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 S1751509AbeBAGDv (ORCPT + 99 others); Thu, 1 Feb 2018 01:03:51 -0500 Received: from smtp.infotech.no ([82.134.31.41]:35123 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750978AbeBAGDr (ORCPT ); Thu, 1 Feb 2018 01:03:47 -0500 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id 19BB020419D; Thu, 1 Feb 2018 07:03:45 +0100 (CET) X-Virus-Scanned: by amavisd-new-2.6.6 (20110518) (Debian) at infotech.no Received: from smtp.infotech.no ([127.0.0.1]) by localhost (smtp.infotech.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aDmLpqMKTPxE; Thu, 1 Feb 2018 07:03:42 +0100 (CET) Received: from [192.168.48.23] (host-45-78-208-28.dyn.295.ca [45.78.208.28]) by smtp.infotech.no (Postfix) with ESMTPA id 804AC20414F; Thu, 1 Feb 2018 07:03:41 +0100 (CET) Reply-To: dgilbert@interlog.com Subject: Re: scsi: sg: assorted memory corruptions To: Dmitry Vyukov Cc: Bart Van Assche , "jejb@linux.vnet.ibm.com" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "martin.petersen@oracle.com" , "ben.hutchings@codethink.co.uk" , "syzkaller@googlegroups.com" References: <1516638634.2545.0.camel@wdc.com> <097921fa-52c5-8b2b-f564-4b24d9720478@interlog.com> From: Douglas Gilbert Message-ID: Date: Thu, 1 Feb 2018 01:03:40 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------908CB96317416B6C4B738BD1" Content-Language: en-CA Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------908CB96317416B6C4B738BD1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 2018-01-30 07:22 AM, Dmitry Vyukov wrote: > Uh, I've answered this a week ago, but did not notice that Doug > dropped everybody from CC. Reporting to all. > > On Mon, Jan 22, 2018 at 8:16 PM, Douglas Gilbert wrote: >> On 2018-01-22 02:06 PM, Dmitry Vyukov wrote: >>> >>> On Mon, Jan 22, 2018 at 7:57 PM, Douglas Gilbert >> Please show me the output of 'lsscsi -g' on your test machine. >> /dev/sg0 is often associated with /dev/sda which is often a SATA >> SSD (or a virtualized one) that holds the root file system. >> With the sg pass-through driver it is relatively easy to write >> random (user provided data) over the root file system which will >> almost certainly "root" the system. > > > This is pretty standard qemu vm started with: > > qemu-system-x86_64 -hda wheezy.img -net user,host=10.0.2.10 -net nic > -nographic -kernel arch/x86/boot/bzImage -append "console=ttyS0 > root=/dev/sda earlyprintk=serial " -m 2G -smp 4 > > # lsscsi -g > [0:0:0:0] disk ATA QEMU HARDDISK 0 /dev/sda /dev/sg0 With lk 4.15.0-rc9 I can run your test program (with some additions, see attachment) for 30 minutes against a scsi_debug simulated disk. You can easily replicate this test just run 'modprobe scsi_debug' and a third line should appear in your lsscsi output. The new device will most likely be /dev/sg2 . With lk 4.15.0 (release) running against a SAS SSD (SEAGATE ST200FM0073), the test has been running 20 minutes and counting without problems. That is using a LSI HBA with the mpt3sas driver. > [1:0:0:0] cd/dvd QEMU QEMU DVD-ROM 2.0. /dev/sr0 /dev/sg1 > > # readlink /sys/class/scsi_generic/sg0 > ../../devices/pci0000:00/0000:00:01.1/ata1/host0/target0:0:0/0:0:0:0/scsi_generic/sg0 > > # cat /sys/class/scsi_generic/sg0/device/vendor > ATA ^^^^^ That subsystem is the culprit IMO, most likely libata. Until you can show this test failing on something other than an ATA disk, then I will treat this issue as closed. Doug Gilbert >>>> Perhaps it misbehaves when it >>>> gets a SCSI command in the T10 range (i.e. not vendor specific) with >>>> a 9 byte cdb length. As far as I'm aware T10 (and the Ansi committee >>>> before it) have never defined a cdb with an odd length. >>>> >>>> For those that are not aware, the sg driver is a relatively thin >>>> shim over the block layer, the SCSI mid-level, and a low-level >>>> driver which may have another kernel driver stack underneath it >>>> (e.g. UAS (USB attached SCSI)). The previous report from syzkaller >>>> on the sg driver ("scsi: memory leak in sg_start_req") has resulted >>>> in one accepted patch on the block layer with probably more to >>>> come in the same area. >>>> >>>> Testing the patch Dmitry gave (with some added error checks which >>>> reported no problems) with the scsi_debug driver supplying /dev/sg0 >>>> I have not seen any problems running that test program. Again >>>> there might be a very slow memory leak, but if there is I don't >>>> believe it is in the sg driver. >>> >>> >>> Did you run it in a loop? First runs pass just fine for me too. >> >> >> Is thirty minutes long enough ?? > > > Yes, it certainly should be enough. Here is what I see: > > > # while ./a.out; do echo RUN; done > RUN > RUN > RUN > RUN > RUN > RUN > RUN > [ 371.977266] ================================================================== > [ 371.980158] BUG: KASAN: double-free or invalid-free in > __put_task_struct+0x1e7/0x5c0 > .... > > > Here is full execution trace of the write call if that will be of any help: > https://gist.githubusercontent.com/dvyukov/14ae64c3e753dedf9ab2608676ecf0b9/raw/9803d52bb1e317a9228e362236d042aaf0fa9d69/gistfile1.txt > > This is on upstream commit 0d665e7b109d512b7cae3ccef6e8654714887844. > Also attaching my config just in case. > --------------908CB96317416B6C4B738BD1 Content-Type: text/x-csrc; name="sg_syzk_next_cbd.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sg_syzk_next_cbd.c" // autogenerated by syzkaller (http://github.com/google/syzkaller) #include #include #include #include #include #include #include #include #define SG_NEXT_CMD_LEN 0x2283 static const char * usage = "sg_syzk_next_cdb # (e.g. '/dev/sg3') "; int main(int argc, const char * argv[]) { int res, err; int fd; long len = 9; char* p = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x47\x00\x00\x24\x00" "\x00\x00\x00\x00\x00\x1c\xbb\xac\x14\x00\xaa\xe0\x00\x00\x01" "\x00\x07\x07\x00\x00\x59\x08\x00\x00\x00\x80\xfe\x7f\x00\x00\x01"; const char * dev_name; struct stat a_stat; if (argc < 2) { fprintf(stderr, "Usage: %s\n", usage); return 1; } dev_name = argv[1]; if (0 != stat(dev_name, &a_stat)) { err = errno; fprintf(stderr, "Unable to stat %s, err: %s\n", dev_name, strerror(err)); return 1; } if ((a_stat.st_mode & S_IFMT) != S_IFCHR) { fprintf(stderr, "Expected %s, to be sg device\n", dev_name); return 1; } fd = open(dev_name, O_RDWR); if (fd < 0) { err = errno; fprintf(stderr, "open(%s) failed: %s [%d]\n", dev_name, strerror(err), err); } res = ioctl(fd, SG_NEXT_CMD_LEN, &len); if (res < 0) { err = errno; fprintf(stderr, "ioctl failed: %s [%d]\n", strerror(err), err); } res = write(fd, p, 46); if (res < 0) { err = errno; fprintf(stderr, "write failed: %s [%d]\n", strerror(err), err); } return 0; } --------------908CB96317416B6C4B738BD1--