Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp710024imm; Thu, 26 Jul 2018 10:36:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf9sj/w6hIjt+7UeFrqW3g6P/s4L5mzhg+V4WziX8gGfeqgXht4rcbhg3BG17r3ZSyUgWp2 X-Received: by 2002:a62:6283:: with SMTP id w125-v6mr3047063pfb.108.1532626567451; Thu, 26 Jul 2018 10:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532626567; cv=none; d=google.com; s=arc-20160816; b=n9AYhNiEjhLa0jFyl/V15T6pto98ErB+ns2gqC4o7eT82h6tfuC9VLsAjS7AFOpglZ vYSLQjZSBNphqx252WzlbPx75kgjRce+7yxn24KDMvPsX0BaqvzwwUoob/QFjd0E+O9L wqXiwyFWvPvfzbw+USwJqEVAfU5mx8wORBGNrbBLJkEEFQJdqrhJhqqv3qN2EnuMMdGd uq7pxcZ4dtzotbVj5BbA9HyB9aRCBelukbJQD57A32uvNyRfta1J1xVYrfVkxZvsrKHR hqDBo0DzL+G4EVk+KxeCMs7Svt/KHatBXaLFn105vJ/FYbvLmHFdqFq5VAnAAWi3V80O 2UEw== 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=14M/fiUUpHNxLB7GnzhWKgdGMJWkU8D4CBWPG7B3Hh8=; b=Oaw4fhkgNfN9MohHx5S8bMacLDbQcrv9ZhI425Ew27QSx8mQlbtrGHUx7cXD+lNUgo PqcCeLnysUFcx7Cnv8dNJh8RdXKGQvAaWAphJHd1pTd1h0PvbBIq1nt4rzS1wuvDOLon I1L4H6KKEGJtsF5qitz4rpJm0+17WFVCrdqC/2cz8HR3TuXhYaHnOHHyqbFOIs+3pp7j MQ9OzTByK4EqKd4raOuW9hTCXqLlOq1rBDuCYRe55i5KR+7yO0GDw++a+gKFyNJHDYh/ 6rarzMCllGGG/PsxLD9bkfxiwVzE1Wx20aM92pP1J3bd2AaevMxEgCXTNOcvbUoo7VAp xitA== 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 g40-v6si1732654plb.169.2018.07.26.10.35.52; Thu, 26 Jul 2018 10:36:07 -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 S2388528AbeGZSIE (ORCPT + 99 others); Thu, 26 Jul 2018 14:08:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34604 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731732AbeGZSIE (ORCPT ); Thu, 26 Jul 2018 14:08:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6279B87927; Thu, 26 Jul 2018 16:50:24 +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 70BBA2142F20; Thu, 26 Jul 2018 16:50:23 +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> <5B59FB56.9090901@redhat.com> 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: <5B59FBCF.7080305@redhat.com> Date: Thu, 26 Jul 2018 11:50:23 -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: <5B59FB56.9090901@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 26 Jul 2018 16:50:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 26 Jul 2018 16:50:24 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 07/26/2018 11:48 AM, Mike Christie wrote: > 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. Sorry did not mean null pointer, but some crash due to accessing memory that was freed. > > 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; >> >