Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp108081ybm; Tue, 26 May 2020 12:00:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6J24jkXhWtGbK+Sm20L5e+SNqy8iQT40muwIn8g2qTxi1J7O82De9F4PVNZo3yxVotxfz X-Received: by 2002:a50:f09a:: with SMTP id v26mr21505519edl.343.1590519624238; Tue, 26 May 2020 12:00:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590519624; cv=none; d=google.com; s=arc-20160816; b=pMr3HHkxCKDV/+LYp569FVs4S2Uwwbjet3hesVSlewGU4/+q3ImRP3ltP82cigZHlF wN6/OzK35qbyivNuhWaXxJpSYcKGjMDESZLyzmr+zB/FXe2pa5YF550obQT5xeOFuftI ZzHTCVcUzcP5vT3rFcD1kg3gimrN0mQQOEXIZ3o0S7wqBNlx2nLSSHgC5+1HQxx27kKW 69GQbxaLkA+d63xeFIdhPYlMcSNFOLu60cDmu6u7QNQ5U0ho1hJGTtOV8FfmE2IuUmYX q/CkqLR8nH2NiH0fqoQ74Znc1S5Vj6NL7MIJCahjWhVjeu9omUnIqNICHKrCKULcVokS 8NgA== 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=EKVUcY7iDtuRnuxd89mImSMzABYv50r6owO4yN4rxC8=; b=hpVATWyRy5b9cKEEcn1jE8Ia1cUJI1ewdBzOTlRRMkqCY5fGb5bC4zrg3MqlR5K0I+ sBNGh2TYIg2Zkyi2q47k8tunsMS4TJDz2QJ31TA/rM/OCv57R4wGq2hPyr6ddj2rNAjv YUvTnTv50fBeqr0Fq2VePeB0vuTcWXmg4e5FEjLRSyz28Z3nGzt09Nmg8KHb/l/d6Vwm TgDK3MhGns9vqgRil82y0+OxtTdHHFySUH07DxYcPNJZ0kPS7F6p2NzB7ehs6+aGkSbU zorYqSM+yNXYVcDk/bSTVzLidMVz0cooACx6hYJowrS0P6cAEbBUMAJaI7so2Z9E95Xt VEKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VVX9Y6PO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id se24si388102ejb.652.2020.05.26.12.00.00; Tue, 26 May 2020 12:00:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VVX9Y6PO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390067AbgEZS5S (ORCPT + 99 others); Tue, 26 May 2020 14:57:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:50362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390024AbgEZS5M (ORCPT ); Tue, 26 May 2020 14:57:12 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 17E582084C; Tue, 26 May 2020 18:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590519431; bh=HS4dO0GbWK+cbuD9M/sp6XBeeNJS7vmNUhMjPvYwcpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VVX9Y6POQKSjBFfM1kmdnfBX+DdFEudoDC2sr1612Ebb1cdIHq83Dh1blYCKEV0ns WaXU8xTPRn7X7blBYceSZXkgx6yHUuh7mLFxk+bf0kGNqSPD4zo2ZLLCm85AMeyoDN VdAg3gMGHGpzyqhsKcVqmCZvFyKJbqjYuu36QUig= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, greg@kroah.com Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , "David S. Miller" , Giuliano Procida Subject: [PATCH 4.4 48/65] l2tp: initialise sessions refcount before making it reachable Date: Tue, 26 May 2020 20:53:07 +0200 Message-Id: <20200526183922.661550701@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526183905.988782958@linuxfoundation.org> References: <20200526183905.988782958@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Guillaume Nault commit 9ee369a405c57613d7c83a3967780c3e30c52ecc upstream. Sessions must be fully initialised before calling l2tp_session_add_to_tunnel(). Otherwise, there's a short time frame where partially initialised sessions can be accessed by external users. Backporting Notes l2tp_core.c: moving code that had been converted from atomic to refcount_t by an earlier change (which isn't being included in this patch series). Fixes: dbdbc73b4478 ("l2tp: fix duplicate session creation") Signed-off-by: Guillaume Nault Signed-off-by: David S. Miller Signed-off-by: Giuliano Procida Signed-off-by: Greg Kroah-Hartman --- net/l2tp/l2tp_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1853,6 +1853,8 @@ struct l2tp_session *l2tp_session_create l2tp_session_set_header_len(session, tunnel->version); + l2tp_session_inc_refcount(session); + err = l2tp_session_add_to_tunnel(tunnel, session); if (err) { kfree(session); @@ -1860,10 +1862,6 @@ struct l2tp_session *l2tp_session_create return ERR_PTR(err); } - /* Bump the reference count. The session context is deleted - * only when this drops to zero. - */ - l2tp_session_inc_refcount(session); l2tp_tunnel_inc_refcount(tunnel); /* Ensure tunnel socket isn't deleted */