Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp785730ybl; Wed, 8 Jan 2020 05:55:43 -0800 (PST) X-Google-Smtp-Source: APXvYqycfUDJNqB5MikyQlsotcX0B+KQcYSaWoNe2JNtBu9rDi8udGFohmcq2TTQxsY5+BSMS/UX X-Received: by 2002:a9d:21f4:: with SMTP id s107mr4385622otb.102.1578491743355; Wed, 08 Jan 2020 05:55:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578491743; cv=none; d=google.com; s=arc-20160816; b=qw9+dNjunJOckE0E4eGpo3oK0AuTnKmlYufQjfRSxuKfmGM1IOolYpAWEQSZBpaXhv J6yhDXPH3RzX2EMheIlo4kk1zYCVoEhS7mtI7Tw81wxjlvmeiH+ZlH9tPn/Tt2r0+nGn AsPiwXsY8h2M1Hs304oY79y1OL83bNL1/tFWPE7voTA0bxzeKjpj01Wv+cTEgEKCGvSR xOvmVbZXjhgobja1AsY2bijc1Yeq30kUtwAOHQJ3PxQ7RTV8/NgYPXJnE/vQcEejLRoB Y80OUaVy4gdb1FzjeAfqjHd33n4UFv9QSIS6iWYHdmdYnwZjxggzrtW4/VOyX714nGJl I4/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=PAnmpqN4fHbzf9qkOThLi4Dt6JeQkclc4p0oPKwxO0A=; b=bmMavpzqFh5xhFK9uBeBAQ6n11cb/t1iV8Qp8IadG5NVCPDMWcmllfGuggSNMnS2hs gXHoosFmZJXeOC3xqNDS8YTIRn3ec+bYoJj8zZZzhQ2jpcZkQOIWOPF5ItzaAjw/IT8Y YxZJhGEU6dG9EzB0DaP8fVDtmpVWPhJmAJqcH4jlE8ugT9ECSTi9IZK/IJArF9mdzByb TEb5iHT5VlpGuLjnlWPhf0HAwxudWgeS0CMyj8gIclbMtJ5l3laoZt/JZrzXA6JN5b75 +uUfJNtmavR8Y2Pqnq1CDWEg1UbWk0xR3kESArrJMg0iAWHiMvV2pu3MBVbLLl3Oneyz bj9g== 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 a7si1893425otp.284.2020.01.08.05.55.29; Wed, 08 Jan 2020 05:55:43 -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 S1727437AbgAHLxt (ORCPT + 99 others); Wed, 8 Jan 2020 06:53:49 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:2235 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726290AbgAHLxs (ORCPT ); Wed, 8 Jan 2020 06:53:48 -0500 Received: from lhreml708-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 3E7AA4C5978AABF20FD3; Wed, 8 Jan 2020 11:53:47 +0000 (GMT) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by lhreml708-cah.china.huawei.com (10.201.108.49) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 8 Jan 2020 11:53:46 +0000 Received: from [127.0.0.1] (10.202.226.43) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 8 Jan 2020 11:53:46 +0000 Subject: Re: [PATCH v1] driver core: Use list_del_init to replace list_del at device_links_purge() To: Luo Jiaxing , , , , , CC: , , "linux-scsi@vger.kernel.org" , "Martin K . Petersen" References: <1578483244-50723-1-git-send-email-luojiaxing@huawei.com> From: John Garry Message-ID: <875eb2dc-a0d3-72e5-a27b-48fa38687c8c@huawei.com> Date: Wed, 8 Jan 2020 11:53:45 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <1578483244-50723-1-git-send-email-luojiaxing@huawei.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.43] X-ClientProxiedBy: lhreml729-chm.china.huawei.com (10.201.108.80) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/01/2020 11:34, Luo Jiaxing wrote: + linux-scsi, Martin > We found that enabling kernel compilation options CONFIG_SCSI_ENCLOSURE and > CONFIG_ENCLOSURE_SERVICES, repeated initialization and deletion of the same > SCSI device will cause system panic, as follows: > [72.425705] Unable to handle kernel paging request at virtual address > dead000000000108 > ... > [72.595093] Call trace: > [72.597532] device_del + 0x194 / 0x3a0 > [72.601012] enclosure_remove_device + 0xbc / 0xf8 > [72.605445] ses_intf_remove + 0x9c / 0xd8 > [72.609185] device_del + 0xf8 / 0x3a0 > [72.612576] device_unregister + 0x14 / 0x30 > [72.616489] __scsi_remove_device + 0xf4 / 0x140 > [72.620747] scsi_remove_device + 0x28 / 0x40 > [72.624745] scsi_remove_target + 0x1c8 / 0x220 please share the full crash stack frame and the commands used to trigger it. Some people prefer the timestamp removed also. > > After analysis, we see that in the error scenario, the ses module has the > following calling sequence: > device_register() -> device_del() -> device_add() -> device_del(). > The first call to device_del() is fine, but the second call to device_del() > will cause a system panic. > > Through disassembly, we locate that panic happen when device_links_purge() > call list_del() to remove device_links.needs_suppliers from list, and > list_del() will set this list entry's prev and next pointers to poison. > So if INIT_LIST_HEAD() is not re-executed before the next list_del(), It > will cause the system to access a memory address which is posioned. > > Therefore, replace list_del() with list_del_init() can avoid such issue. > > Fixes: e2ae9bcc4aaa ("driver core: Add support for linking devices during device addition") > Signed-off-by: Luo Jiaxing > Reviewed-by: John Garry This tag was only implicitly granted, but I thought that the fix looked ok, so: Reviewed-by: John Garry > --- > drivers/base/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 42a6724..7b9b0d6 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -1103,7 +1103,7 @@ static void device_links_purge(struct device *dev) > struct device_link *link, *ln; > > mutex_lock(&wfs_lock); > - list_del(&dev->links.needs_suppliers); > + list_del_init(&dev->links.needs_suppliers); > mutex_unlock(&wfs_lock); > > /* >