Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3928412imm; Mon, 8 Oct 2018 11:50:31 -0700 (PDT) X-Google-Smtp-Source: ACcGV63EOYiSIurOdOc46xD0aAUAv4Qoe0xHkrp8LnuF6HfJh33Y4iVKRdz1GMTzhsasi3shGsKT X-Received: by 2002:a17:902:263:: with SMTP id 90-v6mr25104801plc.190.1539024631675; Mon, 08 Oct 2018 11:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024631; cv=none; d=google.com; s=arc-20160816; b=AVuEjPv60AAQg0wbi7a5u8BNrQ8Yb863JDN7EWxnenwogh7dPXlckTnP3qDmPQAv1d nTl3TMdUkiWEX0NEDhPUm8tMA1nzJrM2mPvQ8lawEL+N5ofKRm1Ja/1Q3I81H1Rj2mPc 3swEUtuRSWYli15/V0bP35gbzh89exUCGb7OUPJsl70A2KbZg0WT+o1x5MuosPiYHX1b fFKJVUT+0PXz+2WK+ZzhQsI07Y4j8Yr78xA4F4nzMhDoRGYVfkDYZ6y7XKBzrt3obwR4 EaYvoeK8F7RyBYh8g96e07ftB7aR/TgoHCAdFcrvpu/7+6o+iUKx3X7E9HFKjkusjKaO bHfA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2hHRGo8oRV4eCJwG0Qj3AOAdRY8JbCYrHtTfcgnTFu8=; b=xK6v3P9LBeD272J6E65ZfspkrltSs+vNLi1lo93MZl89FxHAJBCmBxOhsfP9v31PrN uPL/PVGWaBUZ791b22vZ8SRZqeCdP7OKW/SXmJtihgbjAm2ZwUk0DhnqUR4A2bqXM2Sc QD39EZmQExshknmaWw2O4XMvBYMkJI09eaSZX3ynXG5sYP8JJNGlpQCnNd7vofUEHFbZ siVJGmjqNYBwmuECAa8PjvCGpJEksRE6KwYGx96IOLwRm6QTT7kx+7vDhZr69uGTd3pl Q9t92tHD4JHIP1+blQml8Vv+tWlN9RhYBfIp9sLtPTqNzu+m/nYMB7/U5yfLwLVkhy3g CAog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mJkUZZbo; 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 e3-v6si19178520plk.114.2018.10.08.11.50.16; Mon, 08 Oct 2018 11:50:31 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=mJkUZZbo; 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 S1732015AbeJICDN (ORCPT + 99 others); Mon, 8 Oct 2018 22:03:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:52644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731711AbeJICDM (ORCPT ); Mon, 8 Oct 2018 22:03:12 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 06C0C204FD; Mon, 8 Oct 2018 18:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024605; bh=fw+0HZinCheJNotCIExv8crgn5Gz1CDW6F9F2Al9YhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJkUZZbowmMCkxqtq+YE+2biKsy0lfhSkt0c4jhpISmNtByq2F3e+O9DoEvQqdPkc O1RdBBTX5SfqO0vTAQ83eB2lhxnftiov6FFBQFkXa3oqAkMCBiTOyOl9BmvpJDwrBT +ovxvyQcseKxj7zj68GKcliu7ayfIvy6v+FfBvwc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Pelletier , Mike Christie , Matthew Wilcox , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.18 086/168] scsi: iscsi: target: Set conn->sess to NULL when iscsi_login_set_conn_values fails Date: Mon, 8 Oct 2018 20:31:06 +0200 Message-Id: <20181008175623.328903028@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vincent Pelletier [ Upstream commit 7915919bb94e12460c58e27c708472e6f85f6699 ] Fixes a use-after-free reported by KASAN when later iscsi_target_login_sess_out gets called and it tries to access conn->sess->se_sess: Disabling lock debugging due to kernel taint iSCSI Login timeout on Network Portal [::]:3260 iSCSI Login negotiation failed. ================================================================== BUG: KASAN: use-after-free in iscsi_target_login_sess_out.cold.12+0x58/0xff [iscsi_target_mod] Read of size 8 at addr ffff880109d070c8 by task iscsi_np/980 CPU: 1 PID: 980 Comm: iscsi_np Tainted: G O 4.17.8kasan.sess.connops+ #4 Hardware name: To be filled by O.E.M. To be filled by O.E.M./Aptio CRB, BIOS 5.6.5 05/19/2014 Call Trace: dump_stack+0x71/0xac print_address_description+0x65/0x22e ? iscsi_target_login_sess_out.cold.12+0x58/0xff [iscsi_target_mod] kasan_report.cold.6+0x241/0x2fd iscsi_target_login_sess_out.cold.12+0x58/0xff [iscsi_target_mod] iscsi_target_login_thread+0x1086/0x1710 [iscsi_target_mod] ? __sched_text_start+0x8/0x8 ? iscsi_target_login_sess_out+0x250/0x250 [iscsi_target_mod] ? __kthread_parkme+0xcc/0x100 ? parse_args.cold.14+0xd3/0xd3 ? iscsi_target_login_sess_out+0x250/0x250 [iscsi_target_mod] kthread+0x1a0/0x1c0 ? kthread_bind+0x30/0x30 ret_from_fork+0x35/0x40 Allocated by task 980: kasan_kmalloc+0xbf/0xe0 kmem_cache_alloc_trace+0x112/0x210 iscsi_target_login_thread+0x816/0x1710 [iscsi_target_mod] kthread+0x1a0/0x1c0 ret_from_fork+0x35/0x40 Freed by task 980: __kasan_slab_free+0x125/0x170 kfree+0x90/0x1d0 iscsi_target_login_thread+0x1577/0x1710 [iscsi_target_mod] kthread+0x1a0/0x1c0 ret_from_fork+0x35/0x40 The buggy address belongs to the object at ffff880109d06f00 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 456 bytes inside of 512-byte region [ffff880109d06f00, ffff880109d07100) The buggy address belongs to the page: page:ffffea0004274180 count:1 mapcount:0 mapping:0000000000000000 index:0x0 compound_mapcount: 0 flags: 0x17fffc000008100(slab|head) raw: 017fffc000008100 0000000000000000 0000000000000000 00000001000c000c raw: dead000000000100 dead000000000200 ffff88011b002e00 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff880109d06f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff880109d07000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff880109d07080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff880109d07100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff880109d07180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ================================================================== Signed-off-by: Vincent Pelletier [rebased against idr/ida changes and to handle ret review comments from Matthew] Signed-off-by: Mike Christie Cc: Matthew Wilcox Reviewed-by: Matthew Wilcox Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/target/iscsi/iscsi_target_login.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c @@ -310,11 +310,9 @@ static int iscsi_login_zero_tsih_s1( return -ENOMEM; } - ret = iscsi_login_set_conn_values(sess, conn, pdu->cid); - if (unlikely(ret)) { - kfree(sess); - return ret; - } + if (iscsi_login_set_conn_values(sess, conn, pdu->cid)) + goto free_sess; + sess->init_task_tag = pdu->itt; memcpy(&sess->isid, pdu->isid, 6); sess->exp_cmd_sn = be32_to_cpu(pdu->cmdsn);