public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Kalle Valo <kvalo@codeaurora.org>,
	Hu Jiahui <kirin.say@gmail.com>,
	Eric Dumazet <edumazet@google.com>
Cc: security@kernel.org, linux-wireless@vger.kernel.org,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH v2] airo: Fix read overflows sending packets
Date: Wed, 27 May 2020 20:58:08 +0300	[thread overview]
Message-ID: <20200527175808.peynuk7a6webysv3@kili.mountain> (raw)
In-Reply-To: <CANn89i+Pv6ANBWx-wy-aRXsPgDs=ERzumBvB2g3xiC7OfXXGwA@mail.gmail.com>

The problem is that we always copy a minimum of ETH_ZLEN (60) bytes from
skb->data even when skb->len is less than ETH_ZLEN so it leads to a read
overflow.

The fix is to pad skb->data with zeroes so that it's never less than
ETH_ZLEN bytes.

Cc: <stable@vger.kernel.org>
Reported-by: Hu Jiahui <kirin.say@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: remove an unnecessary if statement
    increment the ->tx_dropped count on failure
    fix found two more instances of the same bug.
    fix typo in the "Cc: <stable@vger.kernel.org>" tag

 drivers/net/wireless/cisco/airo.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/cisco/airo.c b/drivers/net/wireless/cisco/airo.c
index 8363f91df7ea..c80712e61ccf 100644
--- a/drivers/net/wireless/cisco/airo.c
+++ b/drivers/net/wireless/cisco/airo.c
@@ -1925,6 +1925,11 @@ static netdev_tx_t mpi_start_xmit(struct sk_buff *skb,
 		airo_print_err(dev->name, "%s: skb == NULL!",__func__);
 		return NETDEV_TX_OK;
 	}
+	if (skb_padto(skb, ETH_ZLEN)) {
+		dev->stats.tx_dropped++;
+		return NETDEV_TX_OK;
+	}
+
 	npacks = skb_queue_len (&ai->txq);
 
 	if (npacks >= MAXTXQ - 1) {
@@ -1975,8 +1980,7 @@ static int mpi_send_packet (struct net_device *dev)
 		return 0;
 	}
 
-	/* check min length*/
-	len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+	len = skb->len;
 	buffer = skb->data;
 
 	ai->txfids[0].tx_desc.offset = 0;
@@ -2118,7 +2122,6 @@ static void airo_end_xmit(struct net_device *dev) {
 static netdev_tx_t airo_start_xmit(struct sk_buff *skb,
 					 struct net_device *dev)
 {
-	s16 len;
 	int i, j;
 	struct airo_info *priv = dev->ml_priv;
 	u32 *fids = priv->fids;
@@ -2127,6 +2130,10 @@ static netdev_tx_t airo_start_xmit(struct sk_buff *skb,
 		airo_print_err(dev->name, "%s: skb == NULL!", __func__);
 		return NETDEV_TX_OK;
 	}
+	if (skb_padto(skb, ETH_ZLEN)) {
+		dev->stats.tx_dropped++;
+		return NETDEV_TX_OK;
+	}
 
 	/* Find a vacant FID */
 	for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
@@ -2140,10 +2147,8 @@ static netdev_tx_t airo_start_xmit(struct sk_buff *skb,
 			return NETDEV_TX_BUSY;
 		}
 	}
-	/* check min length*/
-	len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
         /* Mark fid as used & save length for later */
-	fids[i] |= (len << 16);
+	fids[i] |= (skb->len << 16);
 	priv->xmit.skb = skb;
 	priv->xmit.fid = i;
 	if (down_trylock(&priv->sem) != 0) {
@@ -2185,7 +2190,6 @@ static void airo_end_xmit11(struct net_device *dev) {
 static netdev_tx_t airo_start_xmit11(struct sk_buff *skb,
 					   struct net_device *dev)
 {
-	s16 len;
 	int i, j;
 	struct airo_info *priv = dev->ml_priv;
 	u32 *fids = priv->fids;
@@ -2201,6 +2205,10 @@ static netdev_tx_t airo_start_xmit11(struct sk_buff *skb,
 		airo_print_err(dev->name, "%s: skb == NULL!", __func__);
 		return NETDEV_TX_OK;
 	}
+	if (skb_padto(skb, ETH_ZLEN)) {
+		dev->stats.tx_dropped++;
+		return NETDEV_TX_OK;
+	}
 
 	/* Find a vacant FID */
 	for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
@@ -2214,10 +2222,8 @@ static netdev_tx_t airo_start_xmit11(struct sk_buff *skb,
 			return NETDEV_TX_BUSY;
 		}
 	}
-	/* check min length*/
-	len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
         /* Mark fid as used & save length for later */
-	fids[i] |= (len << 16);
+	fids[i] |= (skb->len << 16);
 	priv->xmit11.skb = skb;
 	priv->xmit11.fid = i;
 	if (down_trylock(&priv->sem) != 0) {
-- 
2.11.0


  reply	other threads:[~2020-05-27 17:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <EED43E20-9B88-42EC-80B0-0245F0FAF980@gmail.com>
2020-05-27 13:36 ` [PATCH resend] airo: Fix read overflow in mpi_send_packet() Dan Carpenter
2020-05-27 16:52   ` Eric Dumazet
2020-05-27 17:58     ` Dan Carpenter [this message]
2020-05-27 18:08       ` [PATCH v2] airo: Fix read overflows sending packets Eric Dumazet
2020-05-27 18:48         ` [PATCH v3] " Dan Carpenter
2020-05-28 14:41           ` Sasha Levin
2020-05-28 15:55           ` Eric Dumazet
2020-05-29 17:40           ` Kalle Valo

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=20200527175808.peynuk7a6webysv3@kili.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=edumazet@google.com \
    --cc=kirin.say@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=security@kernel.org \
    /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