Skip to content

Commit

Permalink
media: wl128x: prevent two potential buffer overflows
Browse files Browse the repository at this point in the history
Smatch marks skb->data as untrusted so it warns that "evt_hdr->dlen"
can copy up to 255 bytes and we only have room for two bytes.  Even
if this comes from the firmware and we trust it, the new policy
generally is just to fix it as kernel hardenning.

I can't test this code so I tried to be very conservative.  I considered
not allowing "evt_hdr->dlen == 1" because it doesn't initialize the
whole variable but in the end I decided to allow it and manually
initialized "asic_id" and "asic_ver" to zero.

Fixes: e8454ff ("[media] drivers:media:radio: wl128x: FM Driver Common sources")

Signed-off-by: Dan Carpenter <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
Dan Carpenter authored and mchehab committed Mar 29, 2019
1 parent 2e7682e commit 9c2ccc3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/media/radio/wl128x/fmdrv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ int fmc_send_cmd(struct fmdev *fmdev, u8 fm_op, u16 type, void *payload,
return -EIO;
}
/* Send response data to caller */
if (response != NULL && response_len != NULL && evt_hdr->dlen) {
if (response != NULL && response_len != NULL && evt_hdr->dlen &&
evt_hdr->dlen <= payload_len) {
/* Skip header info and copy only response data */
skb_pull(skb, sizeof(struct fm_event_msg_hdr));
memcpy(response, skb->data, evt_hdr->dlen);
Expand Down Expand Up @@ -583,6 +584,8 @@ static void fm_irq_handle_flag_getcmd_resp(struct fmdev *fmdev)
return;

fm_evt_hdr = (void *)skb->data;
if (fm_evt_hdr->dlen > sizeof(fmdev->irq_info.flag))
return;

/* Skip header info and copy only response data */
skb_pull(skb, sizeof(struct fm_event_msg_hdr));
Expand Down Expand Up @@ -1309,7 +1312,7 @@ static int load_default_rx_configuration(struct fmdev *fmdev)
static int fm_power_up(struct fmdev *fmdev, u8 mode)
{
u16 payload;
__be16 asic_id, asic_ver;
__be16 asic_id = 0, asic_ver = 0;
int resp_len, ret;
u8 fw_name[50];

Expand Down

0 comments on commit 9c2ccc3

Please sign in to comment.