Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2013816pxp; Mon, 7 Mar 2022 06:53:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbHJb8jDrau2IfkSSbATDM0Ow6NFuNFGbX/5p8zuMGuEgH+MVryse7QokG8L/ec/58zROo X-Received: by 2002:a17:907:a079:b0:6da:a632:ea89 with SMTP id ia25-20020a170907a07900b006daa632ea89mr9330862ejc.404.1646664791111; Mon, 07 Mar 2022 06:53:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646664791; cv=none; d=google.com; s=arc-20160816; b=Zd0XVTkTFmx51iQ/bJB+CJ7fH0LptBX/aTYrElfpeLPvfotbMo8coipX0mS9Tm+/uq rWQPY2C094XLYOxskRlKLTZs7rA6ZULzmUdMuLvgshMU0jm0IjlVvgDd3JSBHfbJ01sw HyzSjaF5TSZnuwf+zlGCzLhxtFK9zb7C3ro6fAo8kYFiRYSBoI4ZUFL4sDhP6h299QJF Yl4719QcdysSvvd+/cBPFFDQ4hu9Wrj25CXpMsusU0wSXPw3iR7yYVDsKv1C6Hwqy/3f DNwZbHb+C3E0WzV1B8resPo9GyaE+kyRTNghCYJ6qLg5A8QJed4hQRIUKT6X5CK+mZM1 MRfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=rTv1OK3pcVOMqz2au39t/YJtsuT0g7fbkB9OluMCE48=; b=QpVS1wh5b1/kovAgx00ffJuFxNUhUcihfiSHAkSepiKmqHgX8fU1D1AAfptqpp1CCX lCq0PZNlaY2pVFzLayXc0lZXZvHv0SkOUwJ1bB+eE8NU30luo2SCzjdbgmzIHWIJ09ZC y1nTqUnyCO/IUNQ8FPSkwG69V6/1U+JnzwwaSY/CMNEZa2VpfY1aQ3MEetb6gLEqXQCW su3tNzw16Rkkdw0/QVIJsV7tHP8cFNP7PRenxi4lA21nYlsFLPlQw4fkgCOSEUkiLVwr 2/hsabspt+jNj926YhOsyMkxVp8vFXhmNil3s1nUPWTBXJraWWNRJOBVWP7Qd9RQga/W JUUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc31-20020a1709078a1f00b006da7ac2043fsi10115759ejc.224.2022.03.07.06.52.46; Mon, 07 Mar 2022 06:53:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236749AbiCGL44 (ORCPT + 99 others); Mon, 7 Mar 2022 06:56:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233302AbiCGL4x (ORCPT ); Mon, 7 Mar 2022 06:56:53 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 235B76574; Mon, 7 Mar 2022 03:55:59 -0800 (PST) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KBxcb0R6jz1GBys; Mon, 7 Mar 2022 19:51:11 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Mar 2022 19:55:57 +0800 Received: from [10.174.178.220] (10.174.178.220) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Mar 2022 19:55:56 +0800 Subject: Re: [PATCH 1/2] iscsi_tcp: Fix NULL pointer dereference in iscsi_sw_tcp_conn_get_param() To: Mike Christie , Lee Duncan , Chris Leech , "James E . J . Bottomley" , "Martin K . Petersen" , , , CC: Wu Bo , Zhiqiang Liu , References: <20220304025608.1874516-1-haowenchao@huawei.com> From: Wenchao Hao Message-ID: Date: Mon, 7 Mar 2022 19:55:56 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.220] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/3/3 23:03, Mike Christie wrote: > On 3/3/22 8:56 PM, Wenchao Hao wrote: >> kernel might crash in iscsi_sw_tcp_conn_get_param() because it dereference >> an invalid address. >> >> The initialization of iscsi_conn's dd_data is after device_register() of >> struct iscsi_cls_conn, so iscsi_conn's dd_data might not initialized when >> iscsi_sw_tcp_conn_get_param() is called. >> > > We are actually doing sysfs/device addition wrong. > > We should be doing the 2 step setup where in step 1 we alloc/init. > When everything is allocated and initialized, then we should do > device_add which exposes us to sysfs. On the teardown side, we are > then supposed to do 2 steps where the remove function does device_del > which waits until sysfs accesses are completed. We can then tear > the structs down and free them and call device_put. > I reviewed the teardown flow of iscsi_cls_conn, it has already written as what you saied. > The exposure to NL would be similar where it goes into the wrapper > around device_add. However, see my comments on the other patch where > I don't think we can hit the bug you mention because every nl cmd > that calls into the drivers is done under the rx_queue_mutex. > > I think we should separate the iscsi_create_conn function like we > do for sessions. This is going to be a little more involved because > you need to also convert iscsi_tcp_conn_setup and the drivers since > we can call into the drivers for the get_conn_param callout. > . > I hesitated about when should we call device_add(). I think there are two places to call it. The first one is in iscsi_conn_setup(), after some initialization of conn, it keeps same with previous's implement and need not to change drivers' code. What's more, the change can fix iscsi_tcp's NULL pointer access. While this change can not make sure the LLDs related sources are already initialized when iscsi_cls_conn is exposed to sysfs. It means LLDs' callback are still responsible to check if the resources are accessible. Another one is in create_conn callback for each driver's iscsi_transport. This need us to change each driver's code. I send 2 patches which make changes in iscsi_conn_setup(), it's ok with iscsi_tcp, would you help to review them?