diff mbox series

[3/3] wifi: mwifiex: Sanity check tlv_len and tlv_bitmap_len

Message ID 587423b0737108effe82aefed4407daca39e9a51.1692829410.git.gustavoars@kernel.org
State Superseded
Headers show
Series wifi: mwifiex: Fix tlv_buf_left calculation and replace one-element array | expand

Commit Message

Gustavo A. R. Silva Aug. 23, 2023, 10:33 p.m. UTC
Add sanity checks for both `tlv_len` and `tlv_bitmap_len` before
decoding data from `event_buf`.

This prevents any malicious or buggy firmware from overflowing
`event_buf` through large values for `tlv_len` or `tlv_bitmap_len`.

Suggested-by: Dan Williams <dcbw@redhat.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 .../net/wireless/marvell/mwifiex/11n_rxreorder.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Justin Stitt Aug. 23, 2023, 10:38 p.m. UTC | #1
On Wed, Aug 23, 2023 at 3:33 PM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> Add sanity checks for both `tlv_len` and `tlv_bitmap_len` before
> decoding data from `event_buf`.
>
> This prevents any malicious or buggy firmware from overflowing
> `event_buf` through large values for `tlv_len` or `tlv_bitmap_len`.
>
> Suggested-by: Dan Williams <dcbw@redhat.com>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Justin Stitt <justinstitt@google.com>

> ---
>  .../net/wireless/marvell/mwifiex/11n_rxreorder.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
> index 735aac52bdc4..9ee3b9f1e9ce 100644
> --- a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
> +++ b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
> @@ -921,6 +921,14 @@ void mwifiex_11n_rxba_sync_event(struct mwifiex_private *priv,
>         while (tlv_buf_left > sizeof(*tlv_rxba)) {
>                 tlv_type = le16_to_cpu(tlv_rxba->header.type);
>                 tlv_len  = le16_to_cpu(tlv_rxba->header.len);
> +               if (size_add(sizeof(tlv_rxba->header), tlv_len) > tlv_buf_left) {
> +                       mwifiex_dbg(priv->adapter, WARN,
> +                                   "TLV size (%ld) overflows event_buf (%d)\n",
> +                                   size_add(sizeof(tlv_rxba->header), tlv_len),
> +                                   tlv_buf_left);
> +                       return;
> +               }
> +
>                 if (tlv_type != TLV_TYPE_RXBA_SYNC) {
>                         mwifiex_dbg(priv->adapter, ERROR,
>                                     "Wrong TLV id=0x%x\n", tlv_type);
> @@ -929,6 +937,14 @@ void mwifiex_11n_rxba_sync_event(struct mwifiex_private *priv,
>
>                 tlv_seq_num = le16_to_cpu(tlv_rxba->seq_num);
>                 tlv_bitmap_len = le16_to_cpu(tlv_rxba->bitmap_len);
> +               if (size_add(sizeof(*tlv_rxba), tlv_bitmap_len) > tlv_buf_left) {
> +                       mwifiex_dbg(priv->adapter, WARN,
> +                                   "TLV size (%ld) overflows event_buf (%d)\n",
> +                                   size_add(sizeof(*tlv_rxba), tlv_bitmap_len),
> +                                   tlv_buf_left);
> +                       return;
> +               }
> +
>                 mwifiex_dbg(priv->adapter, INFO,
>                             "%pM tid=%d seq_num=%d bitmap_len=%d\n",
>                             tlv_rxba->mac, tlv_rxba->tid, tlv_seq_num,
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
index 735aac52bdc4..9ee3b9f1e9ce 100644
--- a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
+++ b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
@@ -921,6 +921,14 @@  void mwifiex_11n_rxba_sync_event(struct mwifiex_private *priv,
 	while (tlv_buf_left > sizeof(*tlv_rxba)) {
 		tlv_type = le16_to_cpu(tlv_rxba->header.type);
 		tlv_len  = le16_to_cpu(tlv_rxba->header.len);
+		if (size_add(sizeof(tlv_rxba->header), tlv_len) > tlv_buf_left) {
+			mwifiex_dbg(priv->adapter, WARN,
+				    "TLV size (%ld) overflows event_buf (%d)\n",
+				    size_add(sizeof(tlv_rxba->header), tlv_len),
+				    tlv_buf_left);
+			return;
+		}
+
 		if (tlv_type != TLV_TYPE_RXBA_SYNC) {
 			mwifiex_dbg(priv->adapter, ERROR,
 				    "Wrong TLV id=0x%x\n", tlv_type);
@@ -929,6 +937,14 @@  void mwifiex_11n_rxba_sync_event(struct mwifiex_private *priv,
 
 		tlv_seq_num = le16_to_cpu(tlv_rxba->seq_num);
 		tlv_bitmap_len = le16_to_cpu(tlv_rxba->bitmap_len);
+		if (size_add(sizeof(*tlv_rxba), tlv_bitmap_len) > tlv_buf_left) {
+			mwifiex_dbg(priv->adapter, WARN,
+				    "TLV size (%ld) overflows event_buf (%d)\n",
+				    size_add(sizeof(*tlv_rxba), tlv_bitmap_len),
+				    tlv_buf_left);
+			return;
+		}
+
 		mwifiex_dbg(priv->adapter, INFO,
 			    "%pM tid=%d seq_num=%d bitmap_len=%d\n",
 			    tlv_rxba->mac, tlv_rxba->tid, tlv_seq_num,