diff -drupN a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c --- a/drivers/nfc/fdp/i2c.c 2018-08-06 17:23:04.000000000 +0300 +++ b/drivers/nfc/fdp/i2c.c 2022-06-12 05:28:14.000000000 +0300 @@ -177,6 +177,16 @@ static int fdp_nci_i2c_read(struct fdp_i /* Packet that contains a length */ if (tmp[0] == 0 && tmp[1] == 0) { phy->next_read_size = (tmp[2] << 8) + tmp[3] + 3; + /* + * Ensure next_read_size does not exceed sizeof(tmp) + * for reading that many bytes during next iteration + */ + if (phy->next_read_size > FDP_NCI_I2C_MAX_PAYLOAD) { + dev_dbg(&client->dev, "%s: corrupted packet\n", + __func__); + phy->next_read_size = 5; + goto flush; + } } else { phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD;