Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp621674imm; Fri, 3 Aug 2018 08:48:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeflRYJntJQc8RhvYIFW0H/EzrJ3mNMj88HsIuVN+voFGMzFtpEJjN1K8ie20SB+FoqwiZ3 X-Received: by 2002:a17:902:8f8c:: with SMTP id z12-v6mr4069144plo.4.1533311322835; Fri, 03 Aug 2018 08:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533311322; cv=none; d=google.com; s=arc-20160816; b=RpX4YFrkEuNtVlITnNKYNj7MvrkmcLvfDoT6Vb7IdyIkDLFQFBbPrCRK/birUoxYJb qQUXTAj8FhSZzg6UO/6lIleRhhKh8zNg40pd1X6YX8IS2xcsLYXF+WZutlmw68IvMbm+ TZLgNagYW9dkGgADJy8YUj5Lfras5m4p/7VLQ8MibfxCRNHhx/Ca26wf+50Y+KIc9KGO kgq17/W2+9uyqn9lm7sY4mdxGy2nGK4KmoVJz3GOuQFcHAbeGal8LYRNzbsF/YriLWWQ c3j2Yfyp7Kn00w53NRuoav274cZ/rveKsGirDR/SVKDfrafCFLEwzXzOpjHZmlkgeYow BSKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=WvTaeaFhQK/Kd0U/0nsrMELgavPAg/AdvLNEWHEBtA4=; b=a/DrB8ML4h/afKktcoz7N3zqMk8JnOY1OYP8azYa35pVPGcHLjkjkIQH5nLPr8lRm2 9ybF5GgzY9NmOuG4OG468eYxnq3jzffr7mCumb9U3p4W04yxN7AL0Wl92U2uiUsMRQzE ZwKP9muosytd0ZuA6ZgmaxJGC8VNgxonJmxC1RQFgbq+gfTukEY7i23lp8iLrR+uKq41 cVaL+9dOO6bW3gtVejQez6zNOYX+TWgEkUqT7jWT2MwVZt9ra8hu0+L7OQcuNJt8UMyL 0kTnQTOZpK9lwzgLKjl0DwgJ4Lk1RivezGXlBBBDnLC7JPUpoPK0+oZknvu7ytedY63w sZhg== 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 u2-v6si4435459pge.585.2018.08.03.08.48.27; Fri, 03 Aug 2018 08:48: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; 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 S1727841AbeHCRoa convert rfc822-to-8bit (ORCPT + 99 others); Fri, 3 Aug 2018 13:44:30 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:51635 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727171AbeHCRoa (ORCPT ); Fri, 3 Aug 2018 13:44:30 -0400 Received: from DGGEMA404-HUB.china.huawei.com (unknown [172.30.72.54]) by Forcepoint Email with ESMTP id 9B4E7C8167EA8; Fri, 3 Aug 2018 23:47:32 +0800 (CST) Received: from DGGEMA505-MBS.china.huawei.com ([169.254.4.134]) by DGGEMA404-HUB.china.huawei.com ([10.3.20.45]) with mapi id 14.03.0399.000; Fri, 3 Aug 2018 23:47:23 +0800 From: gaowanlong To: "dgilbert@interlog.com" , "Martin K. Petersen" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: "Wencongyang (UVP)" , "Wanghui (John)" , guijianfeng , "lipengfei (Y)" , qiaonuohan , gaowanlong Subject: RE: [bug report] memory corruption panic caused by SG_IO ioctl() Thread-Topic: [bug report] memory corruption panic caused by SG_IO ioctl() Thread-Index: AQHUKwavsqCWlMBaZkezmRbxcAFdZKStmuKAgACOUwA= Date: Fri, 3 Aug 2018 15:47:22 +0000 Message-ID: References: ,<93359d1a-930f-5279-3ca8-800d5930562d@interlog.com> In-Reply-To: <93359d1a-930f-5279-3ca8-800d5930562d@interlog.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.45.154.227] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Doug, On 2018-08-03 04:46 AM, Wanlong Gao wrote: > Hi Martinand all folks, > > >> Recently we find a kernel panic with memory corruption caused by SG_IO ioctl(), >> and it can be easily reproduced by running following reproducer about >> minutes,any idea? > Which kernel? We've tested with 4.17.11 and 4.18.rc7 and both reproduced. > And what are the underlying devices (e.g. does /dev/sg0 refer to a SATA disk, > a real SCSI disk (SAS for example), USB mass storage, etc)? We tested in a qemu-kvm guest and the sg0 refer to a virtual SATA disk. > Also can you get a copy of the kernel panic? Since the call traces are different every time it reproduced, that I didn't paste the call trace or the vmcore, but this reproducer is very useful and I believe you can reproduce it easily using the following code. Thanks, Wanlong > Doug Gilbert > > C reproducer: > > // autogenerated by syzkaller (http://github.com/google/syzkaller) > > #define _GNU_SOURCE > > #include > > #include > > #include > > #include > > #include > > #include > > #include > > #include > > #include > > static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) > > { > > if (a0 == 0xc || a0 == 0xb) { > > char buf[128]; > > sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, > (uint8_t)a2); > > return open(buf, O_RDWR, 0); > > } else { > > char buf[1024]; > > char* hash; > > strncpy(buf, (char*)a0, sizeof(buf) - 1); > > buf[sizeof(buf) - 1] = 0; > > while ((hash = strchr(buf, '#'))) { > > *hash = '0' + (char)(a1 % 10); > > a1 /= 10; > > } > > return open(buf, a2, 0); > > } > > } > > static void execute_one(); > > extern unsigned long long procid; > > void loop() > > { > > while (1) { > > execute_one(); > > } > > } > > uint64_t r[1] = {0xffffffffffffffff}; > > void execute_one() > > { > > long res = 0; > > memcpy((void*)0x20000040, "/dev/sg#", 9); > > res = syz_open_dev(0x20000040, 0, 0); > > if (res != -1) > > r[0] = res; > > *(uint32_t*)0x200002c0 = 0x53; > > *(uint32_t*)0x200002c4 = 0; > > *(uint8_t*)0x200002c8 = 0xd; > > *(uint8_t*)0x200002c9 = 0; > > *(uint16_t*)0x200002ca = 0; > > *(uint32_t*)0x200002cc = 0x95; > > *(uint64_t*)0x200002d0 = 0x20000080; > > *(uint64_t*)0x200002d8 = 0x20000000; > > memcpy((void*)0x20000000, > "\x08\xf0\xa8\x77\xd3\xbe\x87\x5d\xda\x65\x79\x3f\xc7", 13); > > *(uint64_t*)0x200002e0 = 0x20000180; > > *(uint32_t*)0x200002e8 = 0x8001; > > *(uint32_t*)0x200002ec = 0x10024; > > *(uint32_t*)0x200002f0 = -1; > > *(uint64_t*)0x200002f4 = 0x20000280; > > *(uint8_t*)0x200002fc = 0; > > *(uint8_t*)0x200002fd = 0; > > *(uint8_t*)0x200002fe = 0; > > *(uint8_t*)0x200002ff = 0; > > *(uint16_t*)0x20000300 = 0; > > *(uint16_t*)0x20000302 = 0; > > *(uint32_t*)0x20000304 = 0; > > *(uint32_t*)0x20000308 = 0; > > *(uint32_t*)0x2000030c = 0; > > syscall(__NR_ioctl, r[0], 0x2285, 0x200002c0); > > } > > int main() > > { > > syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); > > for (;;) { > > loop(); > > } > > } >