linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Xie He <xie.he.0141@gmail.com>,
	Eric Dumazet <edumazet@google.com>,
	Martin Schiller <ms@dev.tdt.de>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 17/17] drivers/net/wan: lapb: Corrected the usage of skb_cow
Date: Mon, 27 Jul 2020 19:24:20 -0400	[thread overview]
Message-ID: <20200727232420.717684-17-sashal@kernel.org> (raw)
In-Reply-To: <20200727232420.717684-1-sashal@kernel.org>

From: Xie He <xie.he.0141@gmail.com>

[ Upstream commit 8754e1379e7089516a449821f88e1fe1ebbae5e1 ]

This patch fixed 2 issues with the usage of skb_cow in LAPB drivers
"lapbether" and "hdlc_x25":

1) After skb_cow fails, kfree_skb should be called to drop a reference
to the skb. But in both drivers, kfree_skb is not called.

2) skb_cow should be called before skb_push so that is can ensure the
safety of skb_push. But in "lapbether", it is incorrectly called after
skb_push.

More details about these 2 issues:

1) The behavior of calling kfree_skb on failure is also the behavior of
netif_rx, which is called by this function with "return netif_rx(skb);".
So this function should follow this behavior, too.

2) In "lapbether", skb_cow is called after skb_push. This results in 2
logical issues:
   a) skb_push is not protected by skb_cow;
   b) An extra headroom of 1 byte is ensured after skb_push. This extra
      headroom has no use in this function. It also has no use in the
      upper-layer function that this function passes the skb to
      (x25_lapb_receive_frame in net/x25/x25_dev.c).
So logically skb_cow should instead be called before skb_push.

Cc: Eric Dumazet <edumazet@google.com>
Cc: Martin Schiller <ms@dev.tdt.de>
Signed-off-by: Xie He <xie.he.0141@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/wan/hdlc_x25.c  | 4 +++-
 drivers/net/wan/lapbether.c | 8 +++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
index bf78073ee7fd9..e2a83f4cd3bb6 100644
--- a/drivers/net/wan/hdlc_x25.c
+++ b/drivers/net/wan/hdlc_x25.c
@@ -62,8 +62,10 @@ static int x25_data_indication(struct net_device *dev, struct sk_buff *skb)
 {
 	unsigned char *ptr;
 
-	if (skb_cow(skb, 1))
+	if (skb_cow(skb, 1)) {
+		kfree_skb(skb);
 		return NET_RX_DROP;
+	}
 
 	skb_push(skb, 1);
 	skb_reset_network_header(skb);
diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index 0f1217b506ad2..65b2202647411 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -128,10 +128,12 @@ static int lapbeth_data_indication(struct net_device *dev, struct sk_buff *skb)
 {
 	unsigned char *ptr;
 
-	skb_push(skb, 1);
-
-	if (skb_cow(skb, 1))
+	if (skb_cow(skb, 1)) {
+		kfree_skb(skb);
 		return NET_RX_DROP;
+	}
+
+	skb_push(skb, 1);
 
 	ptr  = skb->data;
 	*ptr = X25_IFACE_DATA;
-- 
2.25.1


      parent reply	other threads:[~2020-07-27 23:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 23:24 [PATCH AUTOSEL 5.4 01/17] usb: hso: Fix debug compile warning on sparc32 Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 02/17] selftests: fib_nexthop_multiprefix: fix cleanup() netns deletion Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 03/17] qed: Disable "MFW indication via attention" SPAM every 5 minutes Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 04/17] selftests: net: ip_defrag: modprobe missing nf_defrag_ipv6 support Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 05/17] habanalabs: prevent possible out-of-bounds array access Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 06/17] nfc: s3fwrn5: add missing release on skb in s3fwrn5_recv_frame Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 07/17] scsi: core: Run queue in case of I/O resource contention failure Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 08/17] parisc: add support for cmpxchg on u8 pointers Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 09/17] net: ethernet: ravb: exit if re-initialization fails in tx timeout Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 10/17] drivers/net/wan/x25_asy: Fix to make it work Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 11/17] Revert "i2c: cadence: Fix the hold bit setting" Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 12/17] x86/unwind/orc: Fix ORC for newly forked tasks Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 13/17] x86/stacktrace: Fix reliable check for empty user task stacks Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 14/17] cxgb4: add missing release on skb in uld_send() Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 15/17] xen-netfront: fix potential deadlock in xennet_remove() Sasha Levin
2020-07-27 23:24 ` [PATCH AUTOSEL 5.4 16/17] RISC-V: Set maximum number of mapped pages correctly Sasha Levin
2020-07-27 23:24 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200727232420.717684-17-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ms@dev.tdt.de \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=xie.he.0141@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).