Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp157875pxx; Wed, 28 Oct 2020 01:02:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6zA92bPrxzwdMvcpMQttdAyJa4XKnovA9tQ/k3IMnsI+kBgFAHb44WUutyMAbRP1+ZIu2 X-Received: by 2002:a17:906:f8d2:: with SMTP id lh18mr6643408ejb.457.1603872179591; Wed, 28 Oct 2020 01:02:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603872179; cv=none; d=google.com; s=arc-20160816; b=tBDocKrBFmtQBl0nWwp8ErdsQ6tparrB8HrXvjk07KqJSetSelRlEhhUEupe5VAmhj r1sPKBY/2hZZhnUkU2rXvs2T9E4s61sZjlIvL/pcLxDAiQ8m69bfH8s/EUWHJZ3Btzjn rhY7H8zifYRASOHt6oOgiEK1ITMt4qNodPavDK0kOTcRypgakb/lBFfB0tKd7e/fV1Bd PORvgY9LjhlEiz5C9rRIG2QAHKrZd9WRjRR9pm+7MKu9jNPK23TKd/A9xzSlm7z+wr/z XSwB0JFipRlKVqqinbQ2IzDZhL9dj8mIKr7xHvHVJDWhqMlpLtvkPw77oRH04E6Rx1Md mjbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LbNohCsNaujNzYhSp1vjvCx1J4uhL212dGGemSPUtYY=; b=qTpHNLi7RQEh07OWlCZ5aZjSzEoZM8DKAMT7NdyHJ4MXbVPcwF6dcLLOuLR4192mqr Vyu+qnZv7QUd+5eSAe6phO0GnvSTL7dVvMK7HH7OD5ZjwgGEphzYUEpy6ouIviiEA+kh OKJNK5igX8leYSOaje217JOffYofWhRi7rBlEq66Uqh/f3aPpCwzRFkup5elff9YfU8w zzlsuuIswQfEa/2Z3EGmC4bWTxdY1UBT86y/cjBr0nwBPMVZ9kUzJVA01BLAwa4IaeTq qr8S/piY2ITm9KSxWjGw2BXHB7cZpuB3aLk05rJofXx9DXFJbYSGsz6+0FKZwFQ3bqAo hCTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rlD4DIkW; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si2953320edn.245.2020.10.28.01.02.37; Wed, 28 Oct 2020 01:02:59 -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=rlD4DIkW; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409497AbgJ0N45 (ORCPT + 99 others); Tue, 27 Oct 2020 09:56:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:43354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S368092AbgJ0N44 (ORCPT ); Tue, 27 Oct 2020 09:56:56 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A969B21655; Tue, 27 Oct 2020 13:56:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807016; bh=sfL6G2Y/z9x8rEL+SjrEfC/mODkBAD3Iysx7cVHV0YQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rlD4DIkWgX4wpEk5/ZqVqrX/zMlWOaQ+E0VOe4IA8M9vPEQWIAXYnmAdCfA8ka96x K6voVgufpyiAVTdIpcnCe5c4FvB7CnS41vSF+Yy/RbSLL2TRLeRlofwBrh/6nGFxct vuc/i1WZeAU+ZtwOKuhmbnyclv3iUWLN/kABMqBY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Krzysztof Halasa , Xie He , Jakub Kicinski Subject: [PATCH 4.4 012/112] net: hdlc: In hdlc_rcv, check to make sure dev is an HDLC device Date: Tue, 27 Oct 2020 14:48:42 +0100 Message-Id: <20201027134901.139013070@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie He [ Upstream commit 01c4ceae0a38a0bdbfea6896f41efcd985a9c064 ] The hdlc_rcv function is used as hdlc_packet_type.func to process any skb received in the kernel with skb->protocol == htons(ETH_P_HDLC). The purpose of this function is to provide second-stage processing for skbs not assigned a "real" L3 skb->protocol value in the first stage. This function assumes the device from which the skb is received is an HDLC device (a device created by this module). It assumes that netdev_priv(dev) returns a pointer to "struct hdlc_device". However, it is possible that some driver in the kernel (not necessarily in our control) submits a received skb with skb->protocol == htons(ETH_P_HDLC), from a non-HDLC device. In this case, the skb would still be received by hdlc_rcv. This will cause problems. hdlc_rcv should be able to recognize and drop invalid skbs. It should first make sure "dev" is actually an HDLC device, before starting its processing. This patch adds this check to hdlc_rcv. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: Krzysztof Halasa Signed-off-by: Xie He Link: https://lore.kernel.org/r/20201020013152.89259-1-xie.he.0141@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/wan/hdlc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/drivers/net/wan/hdlc.c +++ b/drivers/net/wan/hdlc.c @@ -57,7 +57,15 @@ int hdlc_change_mtu(struct net_device *d static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *p, struct net_device *orig_dev) { - struct hdlc_device *hdlc = dev_to_hdlc(dev); + struct hdlc_device *hdlc; + + /* First make sure "dev" is an HDLC device */ + if (!(dev->priv_flags & IFF_WAN_HDLC)) { + kfree_skb(skb); + return NET_RX_SUCCESS; + } + + hdlc = dev_to_hdlc(dev); if (!net_eq(dev_net(dev), &init_net)) { kfree_skb(skb);