From patchwork Tue Jan 17 19:39:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 644933 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 E45A8C3DA78 for ; Tue, 17 Jan 2023 21:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbjAQVZz (ORCPT ); Tue, 17 Jan 2023 16:25:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229824AbjAQVRo (ORCPT ); Tue, 17 Jan 2023 16:17:44 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84CED49940 for ; Tue, 17 Jan 2023 11:39:55 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30HGScqW010515; Tue, 17 Jan 2023 19:39:45 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=DYDoH6vj6w8dZLgdh0Zy1wv3yi5fUsoM11mSU+ToZzg=; b=bq503Sb49VxBh5yItRfOTxjMuArH9aAnLLyT/43Cvvz30mcu/4J3qABO56rjcuQgVFWh +Yf6dwu2BYH1zUFIjNzDGUiYlJnKwx5IporeFfS98Fj2rZNh5RT8SVP7DxDsRXFMYq4z RIapZWeDF7KdNsoIHXMz8HZE2DdLN4wRXtg6IAD23a6KlPw6dzmEN2s00rfIVAGZ8bEa tGvS/2Tct28MEQke4yPdGAvniMhQ8cwe3V9rBfAp/BJeaVUOjY3R922dTkt3m/sGkYDk le4dD65Fm8g32CiNGy4dT7DD6NEIiaapxBlZsnksVN3YDVymbyICQXCxGjB/wk5yTK73 kA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3n3m0tnr0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Jan 2023 19:39:45 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30HIYWTe015222; Tue, 17 Jan 2023 19:39:44 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3n4rq4shf2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Jan 2023 19:39:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oYu3OFX+7IJp1aycPG3WP9KdJdClVs0OwRNX6sByTiLzKgpgyXCFPNdIeo2H+yzt2OHwrbUO1MzEm7f31XgOpdDtT1J1woJRjxKH7wdO8lwb6pWWcsoUre9lyjtJsVv5mT+EGwO6cvY3RB0Yd3Nd9olDZA77TMhG9keYEymEcJUQb243MnDFW8AsWsrwv3a826sal2FiylJ8T/2pV4MudMid2mjcroU1bWx4guaq/ZZ0rzV0/bG0NrW9Cwetn+WX56KJ85RR0dJm3aiKG5wv4tqyR8Wma1tlHp4BmljoXdKh13ozNKPib4TpJ3d2LS+G9wh6EQV7QNPdWnbrd75YTQ== 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=DYDoH6vj6w8dZLgdh0Zy1wv3yi5fUsoM11mSU+ToZzg=; b=RfDksMKVLF7DrRnM/kKUOeXWPNEmiPClhxn0xa5Ff7Dkq/y30UrJpfJmKJBjMeiswkSsXdIuJ9yqsh6xqm4dNhG9KUqiR7AIexUN5mQGfpYZ/bd9x+pL85gXPQBDHbkZEcYw/5CUEYfn40pk0GB/pymcqufTBXUakiyO8JOEg4tTlbvJjxMoLbmCju/0eJHOdrRh5YM8/WxM5EEejPYBrZ162ofe54qne0+4QppEoHXslYReiSK+O+nr1i3s8LH7h2uOQwhGjEcHZuQ1t3rCtNi6ZYeniKqEyr6r8aUI3ZId4sRYjHq4ISWKsE8abmY4cO9mQE2USy+POgXfRodqmg== 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=DYDoH6vj6w8dZLgdh0Zy1wv3yi5fUsoM11mSU+ToZzg=; b=RiL+TIW5Vat3P1lI0iPXwP8kEiF206oChydyf78hxeew0j6ojexdozYcm+p9xtlA4jy0ujHaarFlVPlt1JVbD2OBg6AWzwgtmmjRun71+wviD+2F8WZCjTmq3KubL6lUDnzzSyY5xLMCtA+bBAShyYJjaPM43K+hd4S5+R+uS7o= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by DS0PR10MB7222.namprd10.prod.outlook.com (2603:10b6:8:f2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.11; Tue, 17 Jan 2023 19:39:42 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::c888:aca:1eb9:ca4f]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::c888:aca:1eb9:ca4f%5]) with mapi id 15.20.6002.011; Tue, 17 Jan 2023 19:39:42 +0000 From: Mike Christie To: dinghui@sangfor.com.cn, haowenchao22@gmail.com, lduncan@suse.com, cleech@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, jejb@linux.ibm.com Cc: Mike Christie Subject: [PATCH v2 1/2] scsi: iscsi_tcp: Fix UAF during logout when accessing the shost ipaddress Date: Tue, 17 Jan 2023 13:39:36 -0600 Message-Id: <20230117193937.21244-2-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230117193937.21244-1-michael.christie@oracle.com> References: <20230117193937.21244-1-michael.christie@oracle.com> X-ClientProxiedBy: DM6PR07CA0100.namprd07.prod.outlook.com (2603:10b6:5:337::33) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|DS0PR10MB7222:EE_ X-MS-Office365-Filtering-Correlation-Id: d7910bde-1360-488e-66ef-08daf8c29413 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8iTi0tCcMsgYdQYG5eh5g2i/Dfat0vjWx+bbi14WY05QZD22Kye7SWPEMLkLLOpPm5gcISHs1z6fzpdGp2GW3rovJ19NChspKnTl9waRj7Hcx0bRD+ef0v/lB0bqlB26+e7GKbSBjmCm9a2EPCKQAPyoBeZQuFJF3t++mMRJBmQb1OQpN8xw6Jr3XaB7HP3HcTVPNJO6s2Vhs6WQtz3q8ELImiZj28LUpEuaRRWWfpJ+JG1a+n/WpCrKeW1kWA+KiWG4JRNrH3bpBCu3TFX9VZWln5Fx8f30wwImL9+jKXMSYuAdeXibhmQ1M2uVq2Cd+dY1ALXQqy4LGM2hS+UjraQqA3sIlc1duIiN/5Ez75FSvQD6IqPjyzE9f9E9D8/UciUjDCYaXZ2bm/KsAQ5am3SMLqwdPbu8WsC9DdEeToK2oc7ONvxTKGzvSHi2VNOw7xkSGf0c68C6/ST4nQUbAQ6F5eFr/TlcU1oIznTCbGYNjx6l4mHO6O5wQfCjKPivvzWTR7f+aiY1vqG3QM3IHA7PKPNqW0MkvJ+3C0RvIzeSvp3qG6O6xYBVGuK1RfGnzfN8jV4QpDnnm4b8GaJYi9thaOEnNwG2sufSTfM8CQ3OJ9RygXlW/xTF6B4odKO4ev4FZ6TBZ94RLegjv9wvmw== 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:(13230022)(136003)(376002)(396003)(346002)(366004)(39860400002)(451199015)(36756003)(83380400001)(107886003)(6506007)(6666004)(5660300002)(6512007)(186003)(2616005)(2906002)(1076003)(86362001)(26005)(38100700002)(316002)(41300700001)(66946007)(8676002)(66556008)(4326008)(478600001)(8936002)(66476007)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o6rZDHsWkm9GOaQlPMITgzXthJSvu6Jx1iG3Smrt+40m3uV0a6hu9wvfF5nghcNpNocMDpsAU8wNZm1rDEmQty9+7ZvRiDf+QfgXP9hh1ZjOSeA3yx1NQiKxzrxREfmFFy/47kPXTufVF9AOSIgMd6ARpC5gWtGWzK9L4p4f04N9Zcw2UYoHvUNeAVw6NExkPuxIGOr1PzEc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CjoytmXYoh/eucYzmBFtIUC7TexWBsgjThiKrgcKFyUnYlYnqsSBHslpCvyA5yiwQ03OBbdSnFUNYk0HzFn7gkx7vUsdcWGXoBRhFIL0AwhCYDQ6R0T6DOLgE3jRnVwqKertGkSq2JJ3gmBss9zNxhFaltjL3KEOpyI1QzcpIghCx0JiWOAMxgu9fIdPovXS+KzKMzd7CVBoWn1fWOpWpiS7zjlw5nkM6EwtY7F5icVbWZn4iaK0C5KyYSTUjXbEVicm8UJWQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7910bde-1360-488e-66ef-08daf8c29413 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2023 19:39:41.9552 (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: iWr3ALyc0+7NPNfm4cYBv8IrvdW24ay2rAkf/omk6jwLea7iF84ysLnyUCD8QXxQvpXhPT9LXJmP2fwLfS+OB7tkGNAaqhdsI3222Sp3jJ8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7222 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-17_10,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301170157 X-Proofpoint-GUID: 8PXZME-Y_2z6sAOMEMOec0z2aYISYZCf X-Proofpoint-ORIG-GUID: 8PXZME-Y_2z6sAOMEMOec0z2aYISYZCf Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Bug report and analysis from Ding Hui. During iscsi session logout, if another task accesses the shost ipaddress attr, we can get a KASAN UAF report like this: [ 276.942144] BUG: KASAN: use-after-free in _raw_spin_lock_bh+0x78/0xe0 [ 276.942535] Write of size 4 at addr ffff8881053b45b8 by task cat/4088 [ 276.943511] CPU: 2 PID: 4088 Comm: cat Tainted: G E 6.1.0-rc8+ #3 [ 276.943997] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020 [ 276.944470] Call Trace: [ 276.944943] [ 276.945397] dump_stack_lvl+0x34/0x48 [ 276.945887] print_address_description.constprop.0+0x86/0x1e7 [ 276.946421] print_report+0x36/0x4f [ 276.947358] kasan_report+0xad/0x130 [ 276.948234] kasan_check_range+0x35/0x1c0 [ 276.948674] _raw_spin_lock_bh+0x78/0xe0 [ 276.949989] iscsi_sw_tcp_host_get_param+0xad/0x2e0 [iscsi_tcp] [ 276.951765] show_host_param_ISCSI_HOST_PARAM_IPADDRESS+0xe9/0x130 [scsi_transport_iscsi] [ 276.952185] dev_attr_show+0x3f/0x80 [ 276.953005] sysfs_kf_seq_show+0x1fb/0x3e0 [ 276.953401] seq_read_iter+0x402/0x1020 [ 276.954260] vfs_read+0x532/0x7b0 [ 276.955113] ksys_read+0xed/0x1c0 [ 276.955952] do_syscall_64+0x38/0x90 [ 276.956347] entry_SYSCALL_64_after_hwframe+0x63/0xcd [ 276.956769] RIP: 0033:0x7f5d3a679222 [ 276.957161] Code: c0 e9 b2 fe ff ff 50 48 8d 3d 32 c0 0b 00 e8 a5 fe 01 00 0f 1f 44 00 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 0f 05 <48> 3d 00 f0 ff ff 77 56 c3 0f 1f 44 00 00 48 83 ec 28 48 89 54 24 [ 276.958009] RSP: 002b:00007ffc864d16a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 [ 276.958431] RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 00007f5d3a679222 [ 276.958857] RDX: 0000000000020000 RSI: 00007f5d3a4fe000 RDI: 0000000000000003 [ 276.959281] RBP: 00007f5d3a4fe000 R08: 00000000ffffffff R09: 0000000000000000 [ 276.959682] R10: 0000000000000022 R11: 0000000000000246 R12: 0000000000020000 [ 276.960126] R13: 0000000000000003 R14: 0000000000000000 R15: 0000557a26dada58 [ 276.960536] [ 276.961357] Allocated by task 2209: [ 276.961756] kasan_save_stack+0x1e/0x40 [ 276.962170] kasan_set_track+0x21/0x30 [ 276.962557] __kasan_kmalloc+0x7e/0x90 [ 276.962923] __kmalloc+0x5b/0x140 [ 276.963308] iscsi_alloc_session+0x28/0x840 [scsi_transport_iscsi] [ 276.963712] iscsi_session_setup+0xda/0xba0 [libiscsi] [ 276.964078] iscsi_sw_tcp_session_create+0x1fd/0x330 [iscsi_tcp] [ 276.964431] iscsi_if_create_session.isra.0+0x50/0x260 [scsi_transport_iscsi] [ 276.964793] iscsi_if_recv_msg+0xc5a/0x2660 [scsi_transport_iscsi] [ 276.965153] iscsi_if_rx+0x198/0x4b0 [scsi_transport_iscsi] [ 276.965546] netlink_unicast+0x4d5/0x7b0 [ 276.965905] netlink_sendmsg+0x78d/0xc30 [ 276.966236] sock_sendmsg+0xe5/0x120 [ 276.966576] ____sys_sendmsg+0x5fe/0x860 [ 276.966923] ___sys_sendmsg+0xe0/0x170 [ 276.967300] __sys_sendmsg+0xc8/0x170 [ 276.967666] do_syscall_64+0x38/0x90 [ 276.968028] entry_SYSCALL_64_after_hwframe+0x63/0xcd [ 276.968773] Freed by task 2209: [ 276.969111] kasan_save_stack+0x1e/0x40 [ 276.969449] kasan_set_track+0x21/0x30 [ 276.969789] kasan_save_free_info+0x2a/0x50 [ 276.970146] __kasan_slab_free+0x106/0x190 [ 276.970470] __kmem_cache_free+0x133/0x270 [ 276.970816] device_release+0x98/0x210 [ 276.971145] kobject_cleanup+0x101/0x360 [ 276.971462] iscsi_session_teardown+0x3fb/0x530 [libiscsi] [ 276.971775] iscsi_sw_tcp_session_destroy+0xd8/0x130 [iscsi_tcp] [ 276.972143] iscsi_if_recv_msg+0x1bf1/0x2660 [scsi_transport_iscsi] [ 276.972485] iscsi_if_rx+0x198/0x4b0 [scsi_transport_iscsi] [ 276.972808] netlink_unicast+0x4d5/0x7b0 [ 276.973201] netlink_sendmsg+0x78d/0xc30 [ 276.973544] sock_sendmsg+0xe5/0x120 [ 276.973864] ____sys_sendmsg+0x5fe/0x860 [ 276.974248] ___sys_sendmsg+0xe0/0x170 [ 276.974583] __sys_sendmsg+0xc8/0x170 [ 276.974891] do_syscall_64+0x38/0x90 [ 276.975216] entry_SYSCALL_64_after_hwframe+0x63/0xcd We can easily reproduce by two tasks: 1. while :; do iscsiadm -m node --login; iscsiadm -m node --logout; done 2. while :; do cat \ /sys/devices/platform/host*/iscsi_host/host*/ipaddress; done iscsid | cat --------------------------------+--------------------------------------- |- iscsi_sw_tcp_session_destroy | |- iscsi_session_teardown | |- device_release | |- iscsi_session_release ||- dev_attr_show |- kfree | |- show_host_param_ | ISCSI_HOST_PARAM_IPADDRESS | |- iscsi_sw_tcp_host_get_param | |- r/w tcp_sw_host->session (UAF) |- iscsi_host_remove | |- iscsi_host_free | This patch fixes the above bug by splitting the session removal into 2 parts: 1. removal from iSCSI class which includes sysfs and removal from host tracking. 2. freeing of session. During iscsi_tcp host and session removal we can remove the session from sysfs then remove the host from sysfs. At this point we know userspace is not accessing the kernel via sysfs so we can free the session and host. Signed-off-by: Mike Christie --- drivers/scsi/iscsi_tcp.c | 11 +++++++++-- drivers/scsi/libiscsi.c | 38 +++++++++++++++++++++++++++++++------- include/scsi/libiscsi.h | 2 ++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 5fb1f364e815..9c0c8f34ef67 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -982,10 +982,17 @@ static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session) if (WARN_ON_ONCE(session->leadconn)) return; + iscsi_session_remove(cls_session); + /* + * Our get_host_param needs to access the session, so remove the + * host from sysfs before freeing the session to make sure userspace + * is no longer accessing the callout. + */ + iscsi_host_remove(shost, false); + iscsi_tcp_r2tpool_free(cls_session->dd_data); - iscsi_session_teardown(cls_session); - iscsi_host_remove(shost, false); + iscsi_session_free(cls_session); iscsi_host_free(shost); } diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index d95f4bcdeb2e..6e811d753cb1 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -3104,17 +3104,32 @@ iscsi_session_setup(struct iscsi_transport *iscsit, struct Scsi_Host *shost, } EXPORT_SYMBOL_GPL(iscsi_session_setup); -/** - * iscsi_session_teardown - destroy session, host, and cls_session - * @cls_session: iscsi session +/* + * issi_session_remove - Remove session from iSCSI class. */ -void iscsi_session_teardown(struct iscsi_cls_session *cls_session) +void iscsi_session_remove(struct iscsi_cls_session *cls_session) { struct iscsi_session *session = cls_session->dd_data; - struct module *owner = cls_session->transport->owner; struct Scsi_Host *shost = session->host; iscsi_remove_session(cls_session); + /* + * host removal only has to wait for its children to be removed from + * sysfs, and iscsi_tcp needs to do iscsi_host_remove before freeing + * the session, so drop the session count here. + */ + iscsi_host_dec_session_cnt(shost); +} +EXPORT_SYMBOL_GPL(iscsi_session_remove); + +/** + * iscsi_session_free - Free iscsi session and it's resources + * @cls_session: iscsi session + */ +void iscsi_session_free(struct iscsi_cls_session *cls_session) +{ + struct iscsi_session *session = cls_session->dd_data; + struct module *owner = cls_session->transport->owner; iscsi_pool_free(&session->cmdpool); kfree(session->password); @@ -3132,10 +3147,19 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session) kfree(session->discovery_parent_type); iscsi_free_session(cls_session); - - iscsi_host_dec_session_cnt(shost); module_put(owner); } +EXPORT_SYMBOL_GPL(iscsi_session_free); + +/** + * iscsi_session_teardown - destroy session and cls_session + * @cls_session: iscsi session + */ +void iscsi_session_teardown(struct iscsi_cls_session *cls_session) +{ + iscsi_session_remove(cls_session); + iscsi_session_free(cls_session); +} EXPORT_SYMBOL_GPL(iscsi_session_teardown); /** diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 654cc3918c94..7523b6abd8e2 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -422,6 +422,8 @@ extern int iscsi_host_get_max_scsi_cmds(struct Scsi_Host *shost, extern struct iscsi_cls_session * iscsi_session_setup(struct iscsi_transport *, struct Scsi_Host *shost, uint16_t, int, int, uint32_t, unsigned int); +void iscsi_session_remove(struct iscsi_cls_session *cls_session); +void iscsi_session_free(struct iscsi_cls_session *cls_session); extern void iscsi_session_teardown(struct iscsi_cls_session *); extern void iscsi_session_recovery_timedout(struct iscsi_cls_session *); extern int iscsi_set_param(struct iscsi_cls_conn *cls_conn, From patchwork Tue Jan 17 19:39:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 643636 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 6D1D9C54E76 for ; Tue, 17 Jan 2023 21:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229446AbjAQVZx (ORCPT ); Tue, 17 Jan 2023 16:25:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjAQVRo (ORCPT ); Tue, 17 Jan 2023 16:17:44 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F08546739 for ; Tue, 17 Jan 2023 11:39:55 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30HGSh8L018443; Tue, 17 Jan 2023 19:39:45 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=Ls1Afuk+vREBx4X5LIJCcRdVZS5cGA//lszq4XVSrL0=; b=byFmYIcO+3R1zBepCJBx2j1uYy/T0chFz4oOvHuC53Fg7nmnjiSCPcXSsXZEpjvAakZ9 heEdmbzny7jYDFilJGA1rqZwDMq0LZe9QWXZdg1mxeu1dJySL9vhn3Gv22zqZrLxVDvL eDmYemBViJDDvCmYx/YVV/Nu2BXdBqIzWZO8TvDyYr+oI4hS79/61A8ZH+dWwjFgzyco eBcNSW3LCMPLMaXz8Y2B2Me+NwQ4Lw97/cC55lO5+7scnSVvNRS4o2/bdv3A5RbDPE0U C5k8ebmmBEOB/g0MgH75fzKNxV6F5uL+TUyDlwScjBoZ6oeKouexDSXJAQhrPSvl7f/3 8A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3n3k6c5rth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Jan 2023 19:39:45 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30HIYWTf015222; Tue, 17 Jan 2023 19:39:44 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3n4rq4shf2-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Jan 2023 19:39:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ggmn4oJoY8Uygu2zkKXkp6tckVjlrZlzERovZLyOc+b6A7IWPIMtAdbwbAr6ZZPn43esGn8ZVpgKElrT0srtYzztE60I5oHnyVVzc5e3cwLBJeRLBHlzRESRvyAkjzM7+SfhYWRWbfk/flgHapom+l8L7tpjfHi2aD+wiMStXiObH8s0V2ldrCSZ2gvG6JLxXKgbe6BsrxkPlM5czKvSYiwAv8I6u2S9NNy5mLpIyk2EnE0va/KcP3SyqAPFh0nL0W4tbSvDn7WXyZuhIoszOAuc34A+cqZ5tOVPqPeMwCU3/K0ooqq6z3okRnZthm8JTMJOTfQyAmQICL98JgQ8Lg== 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=Ls1Afuk+vREBx4X5LIJCcRdVZS5cGA//lszq4XVSrL0=; b=hcpm3cv3p0Xj+YdMMdnPEr8JfZTRKYQVaWQFbXzo7irFQQHy1MVgj94NCM7EX8LkgIAD7dWF8tA+myAaM08r5YSX445P99QQJs3HLB1fUcYZxWB101gHOo5IBLhPiaR2sr6XIJdGehyhFA465JucaGUoFWJlOHkJYE08W0HPGC4UF2UdZl+dZ9Mi5SFuL1Cv4k1JoIG509O/gkSE77azbirridXQdS36nwmIGD5xovVtF7AjZcoycxe4TB4x5N+YOOMTksn/Yk0H3EvfoZk9zNi+ukKN2bsER85vdBPw+g/qz1+Z2aS59d9GJ80joMxhw6mdAKAMQF4YFp1PFDTMDQ== 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=Ls1Afuk+vREBx4X5LIJCcRdVZS5cGA//lszq4XVSrL0=; b=b2DxLxtCANhizjZVN8CGpIiuSdBAd1DazTk8756nMdXG2arBeSQYOMTP8EHxsD71ITDCNLMli3rQfKmZfV99KuVlpQA0NP/peg+rwGoquMURWSXIYPWeVqKNIPfgu3btilq168cvPMafLDuDeVKeh1Bn0W0HSk5PUJXCs6k/vwQ= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by DS0PR10MB7222.namprd10.prod.outlook.com (2603:10b6:8:f2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.11; Tue, 17 Jan 2023 19:39:43 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::c888:aca:1eb9:ca4f]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::c888:aca:1eb9:ca4f%5]) with mapi id 15.20.6002.011; Tue, 17 Jan 2023 19:39:43 +0000 From: Mike Christie To: dinghui@sangfor.com.cn, haowenchao22@gmail.com, lduncan@suse.com, cleech@redhat.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, jejb@linux.ibm.com Cc: Mike Christie Subject: [PATCH v2 2/2] scsi: iscsi_tcp: Fix UAF during login when accessing the shost ipaddress Date: Tue, 17 Jan 2023 13:39:37 -0600 Message-Id: <20230117193937.21244-3-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230117193937.21244-1-michael.christie@oracle.com> References: <20230117193937.21244-1-michael.christie@oracle.com> X-ClientProxiedBy: DM6PR07CA0082.namprd07.prod.outlook.com (2603:10b6:5:337::15) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR10MB1466:EE_|DS0PR10MB7222:EE_ X-MS-Office365-Filtering-Correlation-Id: 300e4cea-7ca1-454c-6eec-08daf8c294c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CUkJilUqlpEhU2N5KSXCfebRs+lo+jUptghOXDYEzmPpFizWk1idhDBdXKoR6YeDN8tpapoaqaFWJqkl1FnfG2HGxzR4uu4bFNdOOEO85CSX3wzzoNLsT7QUG9wBOurkvgBpi9tcd49Ag9y79xcKstev2fPG14TnIrAajixb5EYb6yCRgKaZ+grgIeNbf2naCYPGS1Opc6i3QjbriPEKDKCC8aaon+75nPe0lA0qbJN+Shtsw7kNSuhA+BKo8cgUv/ACsNzY+UBb0O/KPbXfTyrs6+Ecc3yOlz/Lqs3FCEEZgd0EUgNQ96+CF+ZMKVGlpygW+N5axhvf0PtjWgsX+4AO0UU7GsI6d8Vz0eo9JjRuUmDaOBYw5tOzKEchEyySkZY2V9QSUEIUsKNIr7Jje7kb5QIBRX1n8szcstQi3nhkP6Y7KTTxLXdgVye4gc9A9LNlwRHcr4SWbOB1q0lsQiq9/TG1fAZqY3FEjpzYBNSeGfZsJotm5ahNQMwHFI1UwNUYuTlzIGNYUGz3Q5seQjJAv/94GKdemGZ7hsb9OL7Pb8pXte7tK4OxbRP2+GgacuouUMhvXSk7z4+8SYNNLaBwaQ8xLajjBZo96QdCRVfAhLt5YurTR8x69jVtEd5zKE4Uawm90ikQBKhfLNleyA== 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:(13230022)(136003)(376002)(396003)(346002)(366004)(39860400002)(451199015)(36756003)(83380400001)(107886003)(6506007)(6666004)(5660300002)(6512007)(186003)(2616005)(2906002)(1076003)(86362001)(26005)(38100700002)(316002)(41300700001)(66946007)(8676002)(66556008)(4326008)(478600001)(8936002)(66476007)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aBQIQswNIAggcMz7BfuGxMCTjVumwkrg5X99qPcyJi8w+EfO3Fuzh9fSaVOyk20tRfri6RV4jrv78Nv/BXUUbljdgHtwtNGLTCjtU/ajWHvG6jWA0HrZuhuIAPMIPuoMNS0teS6AQugoAeCnnCOWs0bR9Ye3FoyGn+xK5zHZI2LsXLi933fAiY+zQA8nt8T4HkZJxpxhvldxvy+yQVfexRDxyt2bZGAE4xsXnWq9cIXK9c53MCO/Bxvk7d/x7ZufRqKBEPA06yk6CM+aNgQiFTJZnTHUqZIsg7hBY5uBEeHO1qrQThjk53FO4lESaWr5leNS7arWnyB8NebT80+Q5y3l4kQ3et2WjLhOx7olyEORGAjRsCObNzmLfq9aAJY94jn2ibGsS/Xh28e2DH9h1S/jOUmW0SNOc28U1W80uLldmHEOHpQvic0pGsRNYpFwyR5aDI28VyqO6kbBkCXfDoqlLj4mR2MRh1fGt/S1XoE+zxWi7hImHNi1p9QJEG550r7V299cE2P0rq1pILzGb5zRzWTkofTIRB2c8Xsng7U1O4K3KEJY2cNr7KxXMq8/moIbVXnNJIMU+ysktPBrFamg6zYbBmCk80ce+fVYqE8QXl0g0wmFzu9eEuiK7uNo9tZpTNXNOA4h6LPnoF+E/qT9tcYthmReeRPPzHVKcRshIKVNGcGm2f2NTzQ8buJACq7A8wTJbrhGF9FWca7sUPBds2Ng/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z8r+sA7salQaEbXkjzyOAw+K8oUR+Jb6KVrPmdI0BZdphRWxhNEZD4e2NPy8EaWaR24RGX+4tCIzCSrJu1BWyM9/P43tvP4oYAxHnXCZasqTD5ZflzrI4vUuP/3AnWVqJUoXMqtkjR6EkKQXRgIIJJHbw/wxQkDFO38H8JqOWvJt1dNJQumAKREnJaSSvXCJgznB+KM8fefAV+iESI3sWw9flyj8uHVqZLEe34p8FkWSpMRkT8qTY4zLqc39n6Dkvx29qGQhrljCV352FhbPdVzzgVdyjI/TNo1IIsmQK+xT1Z8P6QM1ppShNkoReAzf19BIbWnjj0M87WSOwsr+06R+++f3EQZNb0LzTwbnleGMltB1qdCLPAqovC6lOu1GVgawsJPCzvaNgEvE9LD/g6T2qvAYdan6uMeKuQ+nkWbwtA6GzBT4pm4XA/IuVBhC9rpE55ov8Y5suOQlpZ0TcZ4ZgM1px0TYoAcaCvoxvpwuftCCoPep/tgyeTLmIrwrTjg5+0PWHDb4pGhBz1Kw9B2GPCTA3Sd7ImYDsMDlNkf3oY0KccTmiPYcdYbEEX3ugELVjx7TxEErITEJ6375ZuazC+f22PKNEbkWeGYPvTta8iazZlP6FRjbBRRcpmdAlU6gPMz60r4KJ0FSmNfyF8NDOsGGlQmpYniNTzRf9jVXdtIzaVsQVY+BYeDgQfHQWLTBYNiJAmmgqAiThLFGSRzc62PDzgZ/kCoLVqTxjQS1fs8iUe3Xdg5IWyolEFK27m243/ejgQY6tbpk+yJwSJ5CR0vrsYURb9RKd1aGztfJMbIHRFBtI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 300e4cea-7ca1-454c-6eec-08daf8c294c1 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2023 19:39:43.0957 (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: 0XYqQKzCJVp4jK2vSUixmSCR3r6RCXi+CaOMlMGn1erW974tgETw9Em0fQFi4/XlW2u9Z/UMBdLcoGCjn79h31dgKNqSkC5hGGHWHnddOLY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7222 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-17_10,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301170157 X-Proofpoint-GUID: ADnd-bhRT-kVuBSeFD-dk6rS9k7xOJUS X-Proofpoint-ORIG-GUID: ADnd-bhRT-kVuBSeFD-dk6rS9k7xOJUS Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If during iscsi_sw_tcp_session_create iscsi_tcp_r2tpool_alloc fails userspace could be accessing the host's ipaddress attr. If we then free the session via iscsi_session_teardown while userspace is still accessing the session we will hit a use after free bug. This patch has us set the tcp_sw_host->session after we have completed session creation and can no longer fail. Signed-off-by: Mike Christie --- drivers/scsi/iscsi_tcp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 9c0c8f34ef67..c3ad04ad66e0 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -848,7 +848,7 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param, char *buf) { struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(shost); - struct iscsi_session *session = tcp_sw_host->session; + struct iscsi_session *session; struct iscsi_conn *conn; struct iscsi_tcp_conn *tcp_conn; struct iscsi_sw_tcp_conn *tcp_sw_conn; @@ -858,6 +858,7 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost, switch (param) { case ISCSI_HOST_PARAM_IPADDRESS: + session = tcp_sw_host->session; if (!session) return -ENOTCONN; @@ -958,11 +959,13 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, if (!cls_session) goto remove_host; session = cls_session->dd_data; - tcp_sw_host = iscsi_host_priv(shost); - tcp_sw_host->session = session; if (iscsi_tcp_r2tpool_alloc(session)) goto remove_session; + + /* We are now fully setup so expose the session to sysfs. */ + tcp_sw_host = iscsi_host_priv(shost); + tcp_sw_host->session = session; return cls_session; remove_session: