From owner-svn-src-stable@FreeBSD.ORG Fri Dec 5 07:24:18 2014 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6952BA31; Fri, 5 Dec 2014 07:24:18 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4AE60DA7; Fri, 5 Dec 2014 07:24:18 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sB57OI83037683; Fri, 5 Dec 2014 07:24:18 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sB57OILB037682; Fri, 5 Dec 2014 07:24:18 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201412050724.sB57OILB037682@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Fri, 5 Dec 2014 07:24:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r275494 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Dec 2014 07:24:18 -0000 Author: mav Date: Fri Dec 5 07:24:17 2014 New Revision: 275494 URL: https://svnweb.freebsd.org/changeset/base/275494 Log: MFC r274795: Close race between cfiscsi_offline() and new connection arrival. Incoming connection should be either rejected or accepted and terminated. Modified: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Fri Dec 5 07:23:25 2014 (r275493) +++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Fri Dec 5 07:24:17 2014 (r275494) @@ -1064,6 +1064,8 @@ cfiscsi_session_terminate_tasks(struct c union ctl_io *io; int error, last, wait; + if (cs->cs_target == NULL) + return; /* No target yet, so nothing to do. */ io = ctl_alloc_io(cs->cs_target->ct_port.ctl_pool_ref); if (io == NULL) { CFISCSI_SESSION_WARN(cs, "can't allocate ctl_io"); @@ -1247,11 +1249,7 @@ cfiscsi_session_new(struct cfiscsi_softc } mtx_lock(&softc->lock); - cs->cs_id = softc->last_session_id + 1; - softc->last_session_id++; - mtx_unlock(&softc->lock); - - mtx_lock(&softc->lock); + cs->cs_id = ++softc->last_session_id; TAILQ_INSERT_TAIL(&softc->sessions, cs, cs_next); mtx_unlock(&softc->lock); @@ -1429,14 +1427,6 @@ cfiscsi_ioctl_handoff(struct ctl_iscsi * return; } - if (ct->ct_online == 0) { - ci->status = CTL_ISCSI_ERROR; - snprintf(ci->error_str, sizeof(ci->error_str), - "%s: port offline", __func__); - cfiscsi_target_release(ct); - return; - } - #ifdef ICL_KERNEL_PROXY if (cihp->socket > 0 && cihp->connection_id > 0) { snprintf(ci->error_str, sizeof(ci->error_str), @@ -1448,7 +1438,7 @@ cfiscsi_ioctl_handoff(struct ctl_iscsi * if (cihp->socket == 0) { mtx_lock(&cfiscsi_softc.lock); TAILQ_FOREACH(cs, &cfiscsi_softc.sessions, cs_next) { - if (cs->cs_id == cihp->socket) + if (cs->cs_id == cihp->connection_id) break; } if (cs == NULL) { @@ -1473,7 +1463,6 @@ cfiscsi_ioctl_handoff(struct ctl_iscsi * #ifdef ICL_KERNEL_PROXY } #endif - cs->cs_target = ct; /* * First PDU of Full Feature phase has the same CmdSN as the last @@ -1505,6 +1494,19 @@ cfiscsi_ioctl_handoff(struct ctl_iscsi * cihp->initiator_isid[2], cihp->initiator_isid[3], cihp->initiator_isid[4], cihp->initiator_isid[5]); + mtx_lock(&softc->lock); + if (ct->ct_online == 0) { + mtx_unlock(&softc->lock); + cfiscsi_session_terminate(cs); + cfiscsi_target_release(ct); + ci->status = CTL_ISCSI_ERROR; + snprintf(ci->error_str, sizeof(ci->error_str), + "%s: port offline", __func__); + return; + } + cs->cs_target = ct; + mtx_unlock(&softc->lock); + refcount_acquire(&cs->cs_outstanding_ctl_pdus); restart: if (!cs->cs_terminating) {