From owner-svn-src-stable@freebsd.org Mon Apr 16 17:21:27 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A01B5F9579D; Mon, 16 Apr 2018 17:21:27 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 500537F8F3; Mon, 16 Apr 2018 17:21:27 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4B1602054F; Mon, 16 Apr 2018 17:21:27 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3GHLROo027333; Mon, 16 Apr 2018 17:21:27 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3GHLR8T027332; Mon, 16 Apr 2018 17:21:27 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201804161721.w3GHLR8T027332@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Mon, 16 Apr 2018 17:21:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r332619 - stable/11/sys/dev/iscsi X-SVN-Group: stable-11 X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: stable/11/sys/dev/iscsi X-SVN-Commit-Revision: 332619 X-SVN-Commit-Repository: base 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.25 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: Mon, 16 Apr 2018 17:21:27 -0000 Author: trasz Date: Mon Apr 16 17:21:26 2018 New Revision: 332619 URL: https://svnweb.freebsd.org/changeset/base/332619 Log: MFC r330740: Check for duplicates when modifying an iSCSI session. Previously we did this check on open, but "iscsictl -M", or an iSCSI redirect received by iscsid(8) could end up with two sessions with the same target name and portal. Modified: stable/11/sys/dev/iscsi/iscsi.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/iscsi/iscsi.c ============================================================================== --- stable/11/sys/dev/iscsi/iscsi.c Mon Apr 16 17:18:06 2018 (r332618) +++ stable/11/sys/dev/iscsi/iscsi.c Mon Apr 16 17:21:26 2018 (r332619) @@ -1960,6 +1960,7 @@ iscsi_ioctl_session_modify(struct iscsi_softc *sc, struct iscsi_session_modify *ism) { struct iscsi_session *is; + const struct iscsi_session *is2; iscsi_sanitize_session_conf(&ism->ism_conf); if (iscsi_valid_session_conf(&ism->ism_conf) == false) @@ -1968,14 +1969,42 @@ iscsi_ioctl_session_modify(struct iscsi_softc *sc, sx_xlock(&sc->sc_lock); TAILQ_FOREACH(is, &sc->sc_sessions, is_next) { ISCSI_SESSION_LOCK(is); - if (is->is_id == ism->ism_session_id) + if (is->is_id == ism->ism_session_id) { + /* Note that the session remains locked. */ break; + } ISCSI_SESSION_UNLOCK(is); } if (is == NULL) { sx_xunlock(&sc->sc_lock); return (ESRCH); } + + /* + * Prevent duplicates. + */ + TAILQ_FOREACH(is2, &sc->sc_sessions, is_next) { + if (is == is2) + continue; + + if (!!ism->ism_conf.isc_discovery != + !!is2->is_conf.isc_discovery) + continue; + + if (strcmp(ism->ism_conf.isc_target_addr, + is2->is_conf.isc_target_addr) != 0) + continue; + + if (ism->ism_conf.isc_discovery == 0 && + strcmp(ism->ism_conf.isc_target, + is2->is_conf.isc_target) != 0) + continue; + + ISCSI_SESSION_UNLOCK(is); + sx_xunlock(&sc->sc_lock); + return (EBUSY); + } + sx_xunlock(&sc->sc_lock); memcpy(&is->is_conf, &ism->ism_conf, sizeof(is->is_conf));