Input: goodix - reject a bak_ref length that cannot hold the checksum
Subsystems (4)
PATCH 1/1 Input: goodix - reject a bak_ref length that cannot hold the checksum
driver_num and sensor_num are taken from the touchscreen config. A config with driver_num 1 and sensor_num 0 yields a bak_ref length of 0, for which devm_kzalloc() returns ZERO_SIZE_PTR. That pointer passes the !ts->bak_ref check and the subsequent ts->bak_ref[ts->bak_ref_len - 1] = 1 writes before the allocation.
Reject a length that leaves no room for the trailing checksum before allocating, and skip saving a bak_ref that was never allocated. Without the second check a rejected length leaves bak_ref NULL while bak_ref_len still holds the bogus value, and goodix_save_bak_ref() then writes through the same index on suspend.
--- drivers/input/touchscreen/goodix_fwupload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/input/touchscreen/goodix_fwupload.c +3 -1
@@ -281,6 +281,8 @@ static int goodix_prepare_bak_ref(struct goodix_ts_data *ts) driver_num, sensor_num, have_key); ts->bak_ref_len = (driver_num * (sensor_num -2 ) +2 ) *2 ; +if (ts->bak_ref_len <2 ) +return -EINVAL ; ts->bak_ref =devm_kzalloc (&ts->client->dev, ts->bak_ref_len,GFP_KERNEL );
@@ -409,7 +411,7 @@ void goodix_save_bak_ref(struct goodix_ts_data *ts)int error;u8 val; -if (!ts->firmware_name) +if (!ts->firmware_name || !ts->bak_ref)return ; error =goodix_i2c_read (ts->client,GOODIX_REG_STATUS , &val,1 );
Signature · 1 line
2.50.1
Quoted 12 lines · Liu Chao
driver_numandsensor_numare taken from the touchscreen config. A config withdriver_num1 andsensor_num0 yields abak_reflength of 0, for whichdevm_kzalloc()returnsZERO_SIZE_PTR. That pointer passes the !ts->bak_ref check and the subsequent ts->bak_ref[ts->bak_ref_len - 1] = 1 writes before the allocation.Reject a length that leaves no room for the trailing checksum before allocating, and skip saving a
bak_refthat was never allocated. Without the second check a rejected length leavesbak_refNULL whilebak_ref_lenstill holds the bogus value, andgoodix_save_bak_ref()then writes through the same index on suspend.
Quoted 3 lines
Fixes 09182ed20c04 ("Input: goodix - add support for controllers without flash")Signed-off-by Liu Chao <[email protected]>
Applied, thank you.
Signature · 1 line
Dmitry