From patchwork Thu Mar 9 22:33:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 13168429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47531C61DA4 for ; Thu, 9 Mar 2023 22:34:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbjCIWeF (ORCPT ); Thu, 9 Mar 2023 17:34:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231377AbjCIWdr (ORCPT ); Thu, 9 Mar 2023 17:33:47 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F69AE190D; Thu, 9 Mar 2023 14:33:45 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 329Lxdax014203; Thu, 9 Mar 2023 22:33:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=T0ZFWsIIIYlq1z3p2EKUZTbxUrsbjFhpoba9Q3GZwgw=; b=I0GuwcjcnkvpqifwJZA0ZLd6SplvKHpVsUtaitTneMIvpwjrDOGENpJjET3QH+WM7vls Xgx2K+Cf60eda+KWLzIDnpnbUGaWcZhSJe5C4XgTj3LCnE7vDU2HYoTf7LZC9qYLqha7 tQn7tqZr2PPwZNfywQMAxP+u+PgbC+zQHZKggV9TSC9VlAcxl254tAt4In8lOdcUAKyL APLEI62l4IRWHQcSV2+NesDAMMVXP6UJuy4f8EIZgtF0YnV5aFciNXOnvkkf1rVWg/sA fw54ipRDl2U+OkcI0cSJGVRM39zs76gMqz73kcS/djpPAkLsi1vyKrL0j6e/b1M4mIBX fg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p418y436m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Mar 2023 22:33:35 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 329M78Pd020848; Thu, 9 Mar 2023 22:33:34 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p6fua4rge-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 09 Mar 2023 22:33:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ftioIQMI+WR/E1Nq7NiytqQSHpq5iOzK1P7xsKCowwjTnEolw/soFXKhQTBn7IeWCw/3AApWyCAUdtD1Hg1murAof7E5nA+o5Clqgfg+w9T06VwhUKeoVV+0kYjk3k3EdaUviURrtH6I0vpnv42Pb45Gz4LrDBrNpiQExEFPNCVHFUJxmOTAFEbNMWXypMjubCJI8R4mGg2UYsMZID06BwpH41oZdnx5INVW3R2nqgnnR83A8i3MKuPlzhl62Df0pVrN2CA35JPoQLjzZCaRU1mE9AqWSo0f4H3jwK8CflgC96T7eXkPue+2RYI98ca/Fi6r5MB6JDp/eqPClj/Inw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T0ZFWsIIIYlq1z3p2EKUZTbxUrsbjFhpoba9Q3GZwgw=; b=ZZsUuE5A3Cid4wpy+UfMxKAEhCkO9qgfCtpXfe4b7LwgWn703rUP4xjAyFc5OIpiMbGpIAkE4ksMQglf9DJTr/xMHzgVhDxq9Q2se7yShVpy9d8WW3pVjAdRw1XHt7NT6cjyqPbbXMOcgMi/JNKZ6OiO/YxasiFbSo7gq7F32Tr09w6HUlvOqDLuoOMbfC5W83/PPpn9SxvSpcVRwuUSoFytTxu8XDcWI15UUU0WfrvtZqz/2p2gtbO7rL9EbNKLTxah70PbyZgUw7RxW0x33Nx7wMfzJvCghS44qGC5pRTRo0W7AKdk39KkP4YhieZBsOV9feO+wC729UqRlwAjqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T0ZFWsIIIYlq1z3p2EKUZTbxUrsbjFhpoba9Q3GZwgw=; b=gF2ZpHEE2SfnXV3/64S4lFpnhZkQ67AOMIUgZjU/zcgpnG96iY/VAcr7g395de4cEfY+UpwhoLazOpt0jdhc2OZdxRkUZyo1Dxb1TeuTJ/fI5G7s6yOorFoG+1SHfuqpGMP1ovaUW6fukevtCsdpTdCpYzFNsUpwhebNY62iC7A= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by PH8PR10MB6479.namprd10.prod.outlook.com (2603:10b6:510:22d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17; Thu, 9 Mar 2023 22:33:32 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::7dd7:8d22:104:8d64]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::7dd7:8d22:104:8d64%7]) with mapi id 15.20.6178.019; Thu, 9 Mar 2023 22:33:32 +0000 From: Mike Christie To: mlombard@redhat.com, martin.petersen@oracle.com, mgurtovoy@nvidia.com, sagi@grimberg.me, d.bogdanov@yadro.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Forza , Mike Christie Subject: [PATCH 12/18] scsi: target: iscsit: free cmds before session free Date: Thu, 9 Mar 2023 16:33:06 -0600 Message-Id: <20230309223312.94595-13-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230309223312.94595-1-michael.christie@oracle.com> References: <20230309223312.94595-1-michael.christie@oracle.com> X-ClientProxiedBy: DM6PR03CA0054.namprd03.prod.outlook.com (2603:10b6:5:100::31) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|PH8PR10MB6479:EE_ X-MS-Office365-Filtering-Correlation-Id: c0001b87-9347-405e-ae5c-08db20ee4fea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mu1I19GBNFplHhdVFRqazlMXerI+bReIafMU9kEwPEks97E5zqc7urKCX41afY/LVKNO3C4ZKFidX1+nZhLoq5R1cLzmdNy5KBhRQEVB+5Ccg27uwLYfo+c9lnOQvFVkPWFWleaG4eLcY9CdNetzxZ/Z3cFPbOBNHzvIRnxQZ3ifcdoyBLY9Bq1XAjbtgGiuhPDygotaY3z4hjbQpxK30S8fsJwXN3ufmYMOXjhkBMdVVLFyDmP0TACLWI0bXY4HUu6sygI0+3canIB4oNW0drK9Um7S79PcRHgxPvXrej3jH7oChmgoisXJQUvb4XKbHIDNY9tlPFYYI9Zm+3Q/mI4N9CAIi9/EqPCVxZ38pFNwaAWiAsW1x5O+NIqJG4JsEf1p+4OmNHWPbXFjfWSdmDwwNXUyg5Cypqzp3e8ljrVk5NwF08wT7O/PxqXzfFNvCjPz/nDcNZcTD7XrNrePvcIKhRUSV9jFf7YlWgzL9joLU8wjiGzvYcpWiNiQY0kZS6JPNw2X39mNwjTSP6mQA2Q74fUjeYr/f6uHo3zrwCCPQrPwrYMnc2ld/00YDN2wqO82ymaZAN2XHFIqCIGgoxoEKPJI2dY/qIvZpLyHutVKOYCPQ78ZG4Hz9E9wpqGpayjP9KUAUg8+VQbqgAHT3A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR10MB1466.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(136003)(39860400002)(346002)(366004)(396003)(376002)(451199018)(2906002)(5660300002)(36756003)(66476007)(26005)(8936002)(4326008)(66556008)(41300700001)(1076003)(8676002)(316002)(86362001)(54906003)(478600001)(6486002)(66946007)(6666004)(6512007)(107886003)(6506007)(38100700002)(186003)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FwQ1ToksX9XnqG9KWe4boW1gZE30mVu3Yf4nenMzG9W4c5W4I00dNsmateERKBr4yRjinBEygazM5lIv3TTDOuI1YCpwG+3OKJ9lpQSIieE5/ulP9ZR9LUXBYMmdGaT5ao9fX4xVuCaZe0bqTLY2OtvHhgTB0DTOvIcL+CqsJv0aIw0My8Zz/YmJs9THBkcJvZoKhWFOfbTJxBZMGS0GGyR9vgYr0xoJS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14vVaOtW3NuPoUXigOPlUMBtM3FaLkuZdmgxJREoYuhVDhtgGMl75OM6722EF5N2g9+wHQ+MBVbETBg4X/IDkY2+h8WBkI5gXecgoa9c6LN81IaWKbh7ZykXQAKU+Yi6AdVv6lqDCSZj9Dcem5iBYJYsaivcFUuU31Sb6IA/n+RjFzZpTt53TkVtLWGN/C7DVpmdywO5NyAPClueFE6p+dbJ1jOmAMwts= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0001b87-9347-405e-ae5c-08db20ee4fea X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 22:33:31.9548 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hQKGTVmhIojy+ABN7ERof/1gnVsP+dQwM6nJylpJv8KgnwC7I8UJAbWDc2P28sx4b5ZNHCxMqKo77/LbFEY1VwCqwlcBW8v+hRGss3Ds9+s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6479 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-09_12,2023-03-09_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303090180 X-Proofpoint-GUID: QCzXNn0VEMhzi-da-aAXCemrG17SGaeS X-Proofpoint-ORIG-GUID: QCzXNn0VEMhzi-da-aAXCemrG17SGaeS Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org From: Dmitry Bogdanov Commands from recovery entries are freed after its session has been closed. That leads to use-after-free at command free or NPE with such call trace: Time2Retain timer expired for SID: 1, cleaning up iSCSI session. BUG: kernel NULL pointer dereference, address: 0000000000000140 RIP: 0010:sbitmap_queue_clear+0x3a/0xa0 Call Trace: target_release_cmd_kref+0xd1/0x1f0 [target_core_mod] transport_generic_free_cmd+0xd1/0x180 [target_core_mod] iscsit_free_cmd+0x53/0xd0 [iscsi_target_mod] iscsit_free_connection_recovery_entries+0x29d/0x320 [iscsi_target_mod] iscsit_close_session+0x13a/0x140 [iscsi_target_mod] iscsit_check_post_dataout+0x440/0x440 [iscsi_target_mod] call_timer_fn+0x24/0x140 Move cleanup of recovery enrties to before session freeing. Reported-by: Forza Signed-off-by: Dmitry Bogdanov Signed-off-by: Mike Christie Reviewed-by: Maurizio Lombardi --- drivers/target/iscsi/iscsi_target.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 2e9c0d7b36a9..cd9ef668a054 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -4546,6 +4546,9 @@ int iscsit_close_session(struct iscsit_session *sess, bool can_sleep) iscsit_stop_time2retain_timer(sess); spin_unlock_bh(&se_tpg->session_lock); + if (sess->sess_ops->ErrorRecoveryLevel == 2) + iscsit_free_connection_recovery_entries(sess); + /* * transport_deregister_session_configfs() will clear the * struct se_node_acl->nacl_sess pointer now as a iscsi_np process context @@ -4569,9 +4572,6 @@ int iscsit_close_session(struct iscsit_session *sess, bool can_sleep) transport_deregister_session(sess->se_sess); - if (sess->sess_ops->ErrorRecoveryLevel == 2) - iscsit_free_connection_recovery_entries(sess); - iscsit_free_all_ooo_cmdsns(sess); spin_lock_bh(&se_tpg->session_lock);