Skip to content

Commit

Permalink
media: af9035: prevent buffer overflow on write
Browse files Browse the repository at this point in the history
When less than 3 bytes are written to the device, memcpy is called with
negative array size which leads to buffer overflow and kernel panic. This
patch adds a condition and returns -EOPNOTSUPP instead.
Fixes bugzilla issue 64871

[mchehab+samsung@kernel.org: fix a merge conflict and changed the
 condition to match the patch's comment, e. g. len == 3 could
 also be valid]
Signed-off-by: Jozef Balga <jozef.balga@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
  • Loading branch information
Jozef Balga authored and Mauro Carvalho Chehab committed Aug 29, 2018
1 parent 4fbf51e commit 312f73b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/media/usb/dvb-usb-v2/af9035.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
if (msg[0].addr == state->af9033_i2c_addr[1])
reg |= 0x100000;

ret = af9035_wr_regs(d, reg, &msg[0].buf[3],
msg[0].len - 3);
ret = (msg[0].len >= 3) ? af9035_wr_regs(d, reg,
&msg[0].buf[3],
msg[0].len - 3)
: -EOPNOTSUPP;
} else {
/* I2C write */
u8 buf[MAX_XFER_SIZE];
Expand Down

0 comments on commit 312f73b

Please sign in to comment.