From: Hayes Wang <hayeswang@realtek.com>
To: <netdev@vger.kernel.org>
Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>,
<pmalani@chromium.org>, <grundler@chromium.org>,
Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH net-next 2/4] r8152: add checking fw_offset field of struct fw_mac
Date: Mon, 21 Oct 2019 11:41:11 +0800 [thread overview]
Message-ID: <1394712342-15778-332-Taiwan-albertk@realtek.com> (raw)
In-Reply-To: <1394712342-15778-330-Taiwan-albertk@realtek.com>
Make sure @fw_offset field of struct fw_mac is more than the size
of struct fw_mac.
Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
drivers/net/usb/r8152.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 55a7674a0c06..090ddd5fb973 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -3399,7 +3399,7 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type)
static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
{
- u16 fw_reg, bp_ba_addr, bp_en_addr, bp_start;
+ u16 fw_reg, bp_ba_addr, bp_en_addr, bp_start, fw_offset;
bool rc = false;
u32 length, type;
int i, max_bp;
@@ -3461,13 +3461,19 @@ static bool rtl8152_is_fw_mac_ok(struct r8152 *tp, struct fw_mac *mac)
goto out;
}
+ fw_offset = __le16_to_cpu(mac->fw_offset);
+ if (fw_offset < sizeof(*mac)) {
+ dev_err(&tp->intf->dev, "fw_offset too small\n");
+ goto out;
+ }
+
length = __le32_to_cpu(mac->blk_hdr.length);
- if (length < __le16_to_cpu(mac->fw_offset)) {
+ if (length < fw_offset) {
dev_err(&tp->intf->dev, "invalid fw_offset\n");
goto out;
}
- length -= __le16_to_cpu(mac->fw_offset);
+ length -= fw_offset;
if (length < 4 || (length & 3)) {
dev_err(&tp->intf->dev, "invalid block length\n");
goto out;
--
2.21.0
next prev parent reply other threads:[~2019-10-21 3:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-21 3:41 [PATCH net-next 0/4] r8152: PHY firmware Hayes Wang
2019-10-21 3:41 ` [PATCH net-next 1/4] r8152: rename fw_type_1 with fw_mac Hayes Wang
2019-10-28 16:48 ` Grant Grundler
2019-10-21 3:41 ` Hayes Wang [this message]
2019-10-21 3:41 ` [PATCH net-next 3/4] r8152: move r8153_patch_request forward Hayes Wang
2019-10-21 3:41 ` [PATCH net-next 4/4] r8152: support firmware of PHY NC for RTL8153A Hayes Wang
2019-10-22 3:36 ` Jakub Kicinski
2019-10-22 5:56 ` Hayes Wang
2019-10-22 18:35 ` [PATCH net-next 0/4] r8152: PHY firmware Jakub Kicinski
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=1394712342-15778-332-Taiwan-albertk@realtek.com \
--to=hayeswang@realtek.com \
--cc=grundler@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.com \
--cc=pmalani@chromium.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;
as well as URLs for NNTP newsgroup(s).