Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp48969imu; Thu, 8 Nov 2018 14:33:27 -0800 (PST) X-Google-Smtp-Source: AJdET5eaUBw/WvQrgj65CGa3kPGk1knefVORbLltWajbhMzKwjVGS1QfbRkxMgddXJMYkrT+2lJP X-Received: by 2002:a63:5308:: with SMTP id h8-v6mr5213895pgb.358.1541716407410; Thu, 08 Nov 2018 14:33:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716407; cv=none; d=google.com; s=arc-20160816; b=c6bD9yMEkrAewRDudedvUHkKclHjxPBErPgEsCnBUA+dhGk1fJLeuxoi4uy0041Y2s 1qmK7p+ZSaMF8uKs9Gx2Z+OVUS4fXuSUZA08Z+kvap5osmMOd3C164ChW39vgxENivZz 2SbxF9KVlVKSdgwI9NuKoMGfNLQmCG3upfmwYN46ypKrWoSsbhTEOaeA6VV14sB9zdZl 1EnVL5aekWU7P5AklU6p3STRneSGhBW+GXuJEmsbbbst3Oel0A7UrXouMwhivWWyxZPy UqZKaNI2fKIJ5+0CDcK2paTHEabxJ1dwFwkodNP/5qrtGeZThn4KQ1mRlKMuYUXFcA9w V5gQ== 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=cQi8oUqwriTxCcZife9CM1yjXa8VGOlDOUw+t+RNx/M=; b=kqc1aREzOFZ/QAL6Ee0WLQ72WtwHk92njeyIu1rCzoIyWBSi9dxEdlTs3+M/NnlWhX bL5+tWFUy6paKI0amwhkb6upThW+qCK0pAfT6tTZvWhjt9tzz9DjXX+QfpTMkd9RJ7J4 9I5J/3jitOVaeDMIHLjmPMDLhLMnUo7WI9NKfrtQNfcf/5NZyuPWhI4lr07QCwKD/c+2 WEi/L6kCXjSm5a6kfuNhEred92BIsH84vu5USef3M4ue2CmRJUbVmdgZlt2CEjrrsAZ+ SfMhSj97WbUZAti2QscMsoAP23MBU/gvEslj+HE77XkBLHb4VN/fsDdQzGWRQdGgtDOA 2ryQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ys1zEcHq; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si5526885plm.136.2018.11.08.14.33.12; Thu, 08 Nov 2018 14:33:27 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=Ys1zEcHq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730319AbeKIHhg (ORCPT + 99 others); Fri, 9 Nov 2018 02:37:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:56042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728654AbeKIHhf (ORCPT ); Fri, 9 Nov 2018 02:37:35 -0500 Received: from localhost (unknown [208.72.13.198]) (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 C8CCA20818; Thu, 8 Nov 2018 22:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714406; bh=1ZQIUfafpALwGjhV7vIQ/baY1BJv3QoWn+FjsXf3WQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ys1zEcHq16dS9mPPmml/TR9uD1OzyIToCcRhbtlgu1PN6X7kUUWVgW1BEZ7LccIMx lJmM9vw9fsc00HIGdDSx6YU0a5wO7YiOpPJb8OhYjMwjTbTXNFqBTROMiQiR6rNOcz 3OEATF4JeFEcEi2AWX5MoP1vX02RAxg3gOfvmT5A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 063/114] l2tp: hold socket before dropping lock in l2tp_ip{, 6}_recv() Date: Thu, 8 Nov 2018 13:51:18 -0800 Message-Id: <20181108215106.791041209@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit a3c18422a4b4e108bcf6a2328f48867e1003fd95 ] Socket must be held while under the protection of the l2tp lock; there is no guarantee that sk remains valid after the read_unlock_bh() call. Same issue for l2tp_ip and l2tp_ip6. Signed-off-by: Guillaume Nault Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/l2tp/l2tp_ip.c | 11 ++++++----- net/l2tp/l2tp_ip6.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c index 48ab93842322..c7e6098c924e 100644 --- a/net/l2tp/l2tp_ip.c +++ b/net/l2tp/l2tp_ip.c @@ -184,14 +184,15 @@ pass_up: read_lock_bh(&l2tp_ip_lock); sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id); + if (!sk) { + read_unlock_bh(&l2tp_ip_lock); + goto discard; + } + + sock_hold(sk); read_unlock_bh(&l2tp_ip_lock); } - if (sk == NULL) - goto discard; - - sock_hold(sk); - if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) goto discard_put; diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c index bcdab1cba773..5fe0a6f6af3d 100644 --- a/net/l2tp/l2tp_ip6.c +++ b/net/l2tp/l2tp_ip6.c @@ -196,14 +196,15 @@ pass_up: read_lock_bh(&l2tp_ip6_lock); sk = __l2tp_ip6_bind_lookup(&init_net, &iph->daddr, 0, tunnel_id); + if (!sk) { + read_unlock_bh(&l2tp_ip6_lock); + goto discard; + } + + sock_hold(sk); read_unlock_bh(&l2tp_ip6_lock); } - if (sk == NULL) - goto discard; - - sock_hold(sk); - if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) goto discard_put; -- 2.17.1