Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1072906pxb; Thu, 19 Nov 2020 23:47:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDtLoQal+iCXWxFoP5pUc5JyNMNQ279HbDwrT66rv8np0/hODxFELP7qWnLuaznL63vu61 X-Received: by 2002:a17:906:8691:: with SMTP id g17mr304020ejx.317.1605858434732; Thu, 19 Nov 2020 23:47:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605858434; cv=none; d=google.com; s=arc-20160816; b=m4cRPajsfskXzA3z8PJmDp05q1VCjEgqiCKIJj6sUTtXCMlMBPztycALP9lnVhp+EE SMSWL9VhMnZGJzwwvkDV3pUdNuGl8Phpui3Omwmu0cLZsmDG9uHUhGBD7Th/qfnRIfOY +I+IUQSatxHdVDElm2yZNyKKYEhdaIQVAkniODIHT9qKg8lYtLnfMTj5MgjB3Ad+qrx8 e+lCuZJbllBhZGxWBABQdWwTURB3DXv0oTbMKcZNEjpkMi/0jRZvxw2C9OuXZxoYexk5 ooMCloLzKr3UvJDl5hREABo711TTkckfQXQeJFezOpfKQPGlEohTB3SRrqa5WbRNCUGN yjjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=j4syES2dHpe0HH2nvMSWrIX1oediT16Di3VGEA8pHps=; b=yajbQevpXwFc88tNFq8sgl1A05wp5irrIiz88yqUd15bf1ZBaGviD/BQ7xELrWpLOC PG9wpVXfHxZ+/KRwJYqwmOxaeEtGZ/bor1bpv4aRiJ7Pnhjj5KnyESRf2K4qvGRIutgW oGjn0h4kePDiKnlOetAaSDHSonRGlgfnKZKK2c7MMwVmNe7iS6Fjg6ID3WVws8SMqUn+ rj+AZZw1XBAdZlqeixMFQB15T4T0mDah+lG57s9EH3DuGsEnvzYPgXaOIpxu7lKIcP/J HZ31tSJPHcabPA1oSZY+3pvmJdS+Ft2sV2tuzgaeFW3h5Hs8pm0WYNKt1aU+7nor3hSX S0Uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si1251048ejz.363.2020.11.19.23.46.52; Thu, 19 Nov 2020 23:47:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbgKTHoX (ORCPT + 99 others); Fri, 20 Nov 2020 02:44:23 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8561 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbgKTHoX (ORCPT ); Fri, 20 Nov 2020 02:44:23 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcpTD0j64zLrlb; Fri, 20 Nov 2020 15:44:00 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Fri, 20 Nov 2020 15:44:12 +0800 From: Qinglang Miao To: Lee Duncan , Chris Leech , "James E.J. Bottomley" , "Martin K. Petersen" CC: , , , Qinglang Miao Subject: [PATCH] scsi: iscsi: fix inappropriate use of put_device Date: Fri, 20 Nov 2020 15:48:52 +0800 Message-ID: <20201120074852.31658-1-miaoqinglang@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kfree(conn) is called inside put_device(&conn->dev) so that another one would cause use-after-free. Besides, device_unregister should be used here rather than put_device. Fixes: f3c893e3dbb5 ("scsi: iscsi: Fail session and connection on transport registration failure") Reported-by: Hulk Robot Signed-off-by: Qinglang Miao --- drivers/scsi/scsi_transport_iscsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 2eb3e4f93..2e68c0a87 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -2313,7 +2313,9 @@ iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid) return conn; release_conn_ref: - put_device(&conn->dev); + device_unregister(&conn->dev); + put_device(&session->dev); + return NULL; release_parent_ref: put_device(&session->dev); free_conn: -- 2.23.0