Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp3665861ima; Mon, 4 Feb 2019 03:06:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN6TbgP66K8oxtAdMslm1OynRUbhQihDtcOqhaXWf4dmSAQ6vknMR0W2Mkv32COMDtFnX/H2 X-Received: by 2002:a62:33c1:: with SMTP id z184mr50175742pfz.104.1549278366671; Mon, 04 Feb 2019 03:06:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549278366; cv=none; d=google.com; s=arc-20160816; b=GhSU5Y+d82qebAf3yBiLQs31dpv3oj/Q5kHfGZLrPcS8+O4Hvz7/4OQQ7ULEPNa8r6 9K/E2eo+IaAYI5uBCKUTZnc33ExFNZ7OKkUYyJz7oT3N+jcHTJPkPd796/SjtIWmfRnl dQ6FgIlBhi5uelYlxJM7MgAJFUDABrz7PRg52qVLz5km+L1/ze058FAzg13Hht4U8tMA I6VIQhv5K8mr5CGS0Wsj59vCmMqQ4YIjhhMfmcWEP+cIsL5HMrCVJ16bxCU74/O1t4ZI K7YtXwTNj404qVeOO8dzJ6rGbezFq8IH97BBJsVTjTXu7FMN4JA/DdWu3NPC2/eu1E+f L1Zg== 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=NlI8LgC2H1D4WVJD4pWppbFRL/RBbA3EFyzU0g+E830=; b=cqzg+4aajmIqJLrM4s0R14Uob9v0nk6IQhrb1Yg8tZCRqh5Vjp85U9IfDNgaKsDPjG bnJP3sxjWT4cef+jGBP4FhHc6NDE8txbGNCP0Lz7cAk9IuUFq/pvqEyz+tG1jhVTK1KB eRIzmlzXD+FH1+51vpkeBm+PgoT5PQSPcP8tzYL6ZauaanwY0H+XqbLYCc2wKb643OC1 2P59JegDw4uSiEMIdk7MKNQoQPS2IQiy64DUPtQuc23/opSQPWgMb7Twjog1gRJrSjP6 LelejetbOCv++g3vkHmZTLqSShGLlCVEMwOF7MBe2ubac7lqx3vOEgfzuVs6oqEMicU5 yhGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HcGopKgW; 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 z128si15060338pgb.372.2019.02.04.03.05.50; Mon, 04 Feb 2019 03:06:06 -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=HcGopKgW; 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 S1731096AbfBDKoy (ORCPT + 99 others); Mon, 4 Feb 2019 05:44:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:42644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731072AbfBDKop (ORCPT ); Mon, 4 Feb 2019 05:44:45 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 725882075B; Mon, 4 Feb 2019 10:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549277084; bh=J2eEsZS0K8CPoKtQjgmXNBI97t07WF0U54Hq1EKyCTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HcGopKgWfat8+CNiBIKxTsOm1gb+qtCznVy57iOJ6a6xhUv23goQdwlBScZ1pUO0W AHIzHvxcKKJenqDakzN11Y07Snn1/xBC8wE2bBqaldu56TB1znmSWVt4dwyXEf9y4N jXbjpwGpY65RQYwZAFujZv/N592MqfIGdSUdO30U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , Lorenzo Bianconi , "David S. Miller" Subject: [PATCH 4.14 17/46] l2tp: remove l2specific_len dependency in l2tp_core Date: Mon, 4 Feb 2019 11:36:48 +0100 Message-Id: <20190204103611.723662578@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204103608.651205056@linuxfoundation.org> References: <20190204103608.651205056@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Bianconi commit 62e7b6a57c7b9bf3c6fd99418eeec05b08a85c38 upstream. Remove l2specific_len dependency while building l2tpv3 header or parsing the received frame since default L2-Specific Sublayer is always four bytes long and we don't need to rely on a user supplied value. Moreover in l2tp netlink code there are no sanity checks to enforce the relation between l2specific_len and l2specific_type, so sending a malformed netlink message is possible to set l2specific_type to L2TP_L2SPECTYPE_DEFAULT (or even L2TP_L2SPECTYPE_NONE) and set l2specific_len to a value greater than 4 leaking memory on the wire and sending corrupted frames. Reviewed-by: Guillaume Nault Tested-by: Guillaume Nault Signed-off-by: Lorenzo Bianconi Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/l2tp/l2tp_core.c | 34 ++++++++++++++++------------------ net/l2tp/l2tp_core.h | 11 +++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -758,11 +758,9 @@ void l2tp_recv_common(struct l2tp_sessio "%s: recv data ns=%u, session nr=%u\n", session->name, ns, session->nr); } + ptr += 4; } - /* Advance past L2-specific header, if present */ - ptr += session->l2specific_len; - if (L2TP_SKB_CB(skb)->has_seq) { /* Received a packet with sequence numbers. If we're the LNS, * check if we sre sending sequence numbers and if not, @@ -1084,21 +1082,20 @@ static int l2tp_build_l2tpv3_header(stru memcpy(bufp, &session->cookie[0], session->cookie_len); bufp += session->cookie_len; } - if (session->l2specific_len) { - if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) { - u32 l2h = 0; - if (session->send_seq) { - l2h = 0x40000000 | session->ns; - session->ns++; - session->ns &= 0xffffff; - l2tp_dbg(session, L2TP_MSG_SEQ, - "%s: updated ns to %u\n", - session->name, session->ns); - } + if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) { + u32 l2h = 0; - *((__be32 *) bufp) = htonl(l2h); + if (session->send_seq) { + l2h = 0x40000000 | session->ns; + session->ns++; + session->ns &= 0xffffff; + l2tp_dbg(session, L2TP_MSG_SEQ, + "%s: updated ns to %u\n", + session->name, session->ns); } - bufp += session->l2specific_len; + + *((__be32 *)bufp) = htonl(l2h); + bufp += 4; } return bufp - optr; @@ -1764,7 +1761,7 @@ int l2tp_session_delete(struct l2tp_sess EXPORT_SYMBOL_GPL(l2tp_session_delete); /* We come here whenever a session's send_seq, cookie_len or - * l2specific_len parameters are set. + * l2specific_type parameters are set. */ void l2tp_session_set_header_len(struct l2tp_session *session, int version) { @@ -1773,7 +1770,8 @@ void l2tp_session_set_header_len(struct if (session->send_seq) session->hdr_len += 4; } else { - session->hdr_len = 4 + session->cookie_len + session->l2specific_len; + session->hdr_len = 4 + session->cookie_len; + session->hdr_len += l2tp_get_l2specific_len(session); if (session->tunnel->encap == L2TP_ENCAPTYPE_UDP) session->hdr_len += 4; } --- a/net/l2tp/l2tp_core.h +++ b/net/l2tp/l2tp_core.h @@ -320,6 +320,17 @@ do { \ #define l2tp_session_dec_refcount(s) l2tp_session_dec_refcount_1(s) #endif +static inline int l2tp_get_l2specific_len(struct l2tp_session *session) +{ + switch (session->l2specific_type) { + case L2TP_L2SPECTYPE_DEFAULT: + return 4; + case L2TP_L2SPECTYPE_NONE: + default: + return 0; + } +} + #define l2tp_printk(ptr, type, func, fmt, ...) \ do { \ if (((ptr)->debug) & (type)) \