]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Bluetooth: btrtl: validate firmware patch bounds
authorLaxman Acharya Padhya <acharyalaxman8848@gmail.com>
Fri, 10 Jul 2026 17:25:03 +0000 (23:10 +0545)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 13 Jul 2026 14:08:06 +0000 (10:08 -0400)
rtlbt_parse_firmware() copies patch_length - 4 bytes before appending the
firmware version. A malformed firmware patch shorter than the version field
can make this subtraction underflow and turn the copy into an oversized
read and write during Bluetooth setup.

The existing patch_offset + patch_length check can also wrap on 32-bit
architectures. Validate the patch length and range without arithmetic
overflow before allocating or copying the patch.

Fixes: db33c77dddc2 ("Bluetooth: btrtl: Create separate module for Realtek BT driver")
Cc: stable@vger.kernel.org
Signed-off-by: Laxman Acharya Padhya <acharyalaxman8848@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
drivers/bluetooth/btrtl.c

index 49ecb18fea45f4152e0d755bf03cf7ed11b075dc..7f54d2d2d13a045f80264a7dc945e1d76064c13a 100644 (file)
@@ -797,8 +797,9 @@ static int rtlbt_parse_firmware(struct hci_dev *hdev,
        }
 
        BT_DBG("length=%x offset=%x index %d", patch_length, patch_offset, i);
-       min_size = patch_offset + patch_length;
-       if (btrtl_dev->fw_len < min_size)
+       if (patch_length < sizeof(epatch_info->fw_version) ||
+           patch_offset > btrtl_dev->fw_len ||
+           patch_length > btrtl_dev->fw_len - patch_offset)
                return -EINVAL;
 
        /* Copy the firmware into a new buffer and write the version at