Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp699822imm; Thu, 26 Jul 2018 10:25:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcvrAnvIsLO7hSfh+QtLruiJOT83f6bo7oWICg/L6Fp6PtCbs6mQTx2XKVn96DKu06iOgiG X-Received: by 2002:a63:9f0a:: with SMTP id g10-v6mr2824316pge.324.1532625920762; Thu, 26 Jul 2018 10:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532625920; cv=none; d=google.com; s=arc-20160816; b=CUls3ROIvHNMqarFvRPCCh4tRvgiJoTn5PUhtw3W3Tk3q9KZkFNjLdDJ+2GwT77037 wjtodG7GZbuexuvIR/35jEhzzpzow6YNLIN4eRdEiD77eqOhXc+jbLCr+GiQFVWgiI2k hM2GQGtqNEmeLxGyj2mDDVGTcTT0Xuie6HNd1j5HkO24l25wMH8HblNr/vaJOpV6jH0a oOjUlKiYL2JV1jNq4Qh9tfUGnrfWDzRAXVQm+WTVbvs75y9TNMStwFA+MkH8sZh3YjaP Xd/38OFb8E4SlrOC9IPfPhnwaLeozrndlEfNLBDdO6q1JLIVwx/soy40ed5kTuGYA8km DORw== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=nAJhyGHf4giFZJ/HPE1Ac3TjNfxpAukc/SoFD4plR9U=; b=VwP99dsOCaZq6sTAHDi9cZ2647i60H2+bmxNli4tnKyb/iqesgsrZ4Hw+5vmKLejzd mpVBpWzTrQ2bTB6f4DUiCslplFzyHItap60cn6/w2XizF3mQHXgPln0mIIeqn3eTMuSX vB26ZwJ/TGgcMMyYREMKMYpsAJMPHk1fYX6EP8K09/WApiHmYEtwZlLiJ+qQRKYETQT9 yZ6cBn+ybZdLbvra/ikfXx206m3lX+iGSbwz8hGXbEpwSHhO5wEFk21bStfw8Kc1LM55 Pu438cD8DFXl/3uN21feU91t7Fl57Pe17JAR/nNfuU1WvrOaOVuyIzGyShV15Mw5jzrl f6Zg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p17-v6si1931258pfd.76.2018.07.26.10.25.05; Thu, 26 Jul 2018 10:25:20 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388522AbeGZSGD (ORCPT + 99 others); Thu, 26 Jul 2018 14:06:03 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45204 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731800AbeGZSGD (ORCPT ); Thu, 26 Jul 2018 14:06:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC82D4067F19; Thu, 26 Jul 2018 16:48:23 +0000 (UTC) Received: from [10.10.121.247] (ovpn-121-247.rdu2.redhat.com [10.10.121.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C50B111DCF1; Thu, 26 Jul 2018 16:48:22 +0000 (UTC) Subject: Re: [PATCH 18/26] target/iscsi: Allocate session IDs from an IDA To: Matthew Wilcox , linux-kernel@vger.kernel.org References: <20180621212835.5636-1-willy@infradead.org> <20180621212835.5636-19-willy@infradead.org> Cc: "Nicholas A. Bellinger" , Bart Van Assche , Hannes Reinecke , Kees Cook , Varun Prakash , Sagi Grimberg , Philippe Ombredanne , Greg Kroah-Hartman , Kate Stewart , Thomas Gleixner , "David S. Miller" , Denys Vlasenko , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org From: Mike Christie Message-ID: <5B59FB56.9090901@redhat.com> Date: Thu, 26 Jul 2018 11:48:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20180621212835.5636-19-willy@infradead.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 26 Jul 2018 16:48:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 26 Jul 2018 16:48:23 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mchristi@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/21/2018 04:28 PM, Matthew Wilcox wrote: > @@ -1163,11 +1157,9 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn, > goto old_sess_out; > if (conn->sess->se_sess) > transport_free_session(conn->sess->se_sess); > - if (conn->sess->session_index != 0) { > - spin_lock_bh(&sess_idr_lock); > - idr_remove(&sess_idr, conn->sess->session_index); > - spin_unlock_bh(&sess_idr_lock); This code looks buggy. We will probably NULL pointer oops before we hit it. It looks like the session_index check was supposed to detect when login fails in the middle of doing login, so that code probably wanted to do: idr_alloc(&sess_idr, NULL, 1, 0, GFP_NOWAIT); The problem is that iscsi_login_zero_tsih_s1 sets conn->sess early in iscsi_login_set_conn_values. If the function fails later like when we alloc the idr it does kfree(sess) and leaves the conn->sess pointer set. iscsi_login_zero_tsih_s1 then returns -Exyz and we then call iscsi_target_login_sess_out and access the freed memory above. So I am not sure what we want to do here for your patch since it is not adding any new bugs. Just merge your patch now and I can send a fix for the above bug over it? > - } > + /* Um, 0 is a valid ID. I suppose we never free it? */ > + if (conn->sess->session_index != 0) > + ida_free(&sess_ida, conn->sess->session_index); > kfree(conn->sess->sess_ops); > kfree(conn->sess); > conn->sess = NULL; >