Skip to content

Commit 5a16a3d

Browse files
hayesorzJakub Kicinski
authored andcommitted
r8152: add checking fw_offset field of struct fw_mac
Make sure @fw_offset field of struct fw_mac is more than the size of struct fw_mac. Signed-off-by: Hayes Wang <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a66edaa commit 5a16a3d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/net/usb/r8152.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,7 +3399,7 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type)
33993399

34003400
static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
34013401
{
3402-
u16 fw_reg, bp_ba_addr, bp_en_addr, bp_start;
3402+
u16 fw_reg, bp_ba_addr, bp_en_addr, bp_start, fw_offset;
34033403
bool rc = false;
34043404
u32 length, type;
34053405
int i, max_bp;
@@ -3461,13 +3461,19 @@ static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
34613461
goto out;
34623462
}
34633463

3464+
fw_offset = __le16_to_cpu(mac->fw_offset);
3465+
if (fw_offset < sizeof(*mac)) {
3466+
dev_err(&tp->intf->dev, "fw_offset too small\n");
3467+
goto out;
3468+
}
3469+
34643470
length = __le32_to_cpu(mac->blk_hdr.length);
3465-
if (length < __le16_to_cpu(mac->fw_offset)) {
3471+
if (length < fw_offset) {
34663472
dev_err(&tp->intf->dev, "invalid fw_offset\n");
34673473
goto out;
34683474
}
34693475

3470-
length -= __le16_to_cpu(mac->fw_offset);
3476+
length -= fw_offset;
34713477
if (length < 4 || (length & 3)) {
34723478
dev_err(&tp->intf->dev, "invalid block length\n");
34733479
goto out;

0 commit comments

Comments
 (0)