]> git.baikalelectronics.ru Git - kernel.git/commit
i2c: core: check returned size of emulated smbus block read
authorMans Rullgard <mans@mansr.com>
Sat, 13 Jun 2020 10:41:09 +0000 (11:41 +0100)
committerWolfram Sang <wsa@kernel.org>
Fri, 26 Jun 2020 08:18:35 +0000 (10:18 +0200)
commit0a0e7d3111aff01895d436820ace8630d071d0f2
tree4b57793c3250f1b123fed6df1d86978617a0d21e
parent5c3261070869d3b5792f92718f4f1f06843da0eb
i2c: core: check returned size of emulated smbus block read

If the i2c bus driver ignores the I2C_M_RECV_LEN flag (as some of
them do), it is possible for an I2C_SMBUS_BLOCK_DATA read issued
on some random device to return an arbitrary value in the first
byte (and nothing else).  When this happens, i2c_smbus_xfer_emulated()
will happily write past the end of the supplied data buffer, thus
causing Bad Things to happen.  To prevent this, check the size
before copying the data block and return an error if it is too large.

Fixes: 1a902662c4cb ("i2c: Emulate SMBus block read over I2C")
Signed-off-by: Mans Rullgard <mans@mansr.com>
[wsa: use better errno]
Signed-off-by: Wolfram Sang <wsa@kernel.org>
drivers/i2c/i2c-core-smbus.c