input: fix data race __ps2_command
Subsystems (2)
PATCH 1/1 input: fix data race __ps2_command
The data race happens on ps2dev->cmdcnt and ps2dev->cmdbuf contents. __ps2_command reads that data concurrently with the interrupt handler. As the result, for example, if a response arrives just after the timeout, __ps2_command can copy out garbage from ps2dev->cmdbuf but then see that ps2dev->cmdcnt is 0 and return success.
Stop the interrupt handler with serio_pause_rx() before reading the results.
The data race was found with KernelThreadSanitizer (KTSAN).
--- drivers/input/serio/libps2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/input/serio/libps2.c +4 -2
@@ -234,17 +234,19 @@ int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) !(ps2dev->flags & PS2_FLAG_CMD), timeout); } +serio_pause_rx (ps2dev->serio);if (param)for (i =0 ; i < receive; i++) param[i] = ps2dev->cmdbuf[(receive -1 ) - i];if (ps2dev->cmdcnt && (command !=PS2_CMD_RESET_BAT || ps2dev->cmdcnt !=1 )) - goto out; - + goto out_paused; rc =0 ; + goto out_paused; out:serio_pause_rx (ps2dev->serio); +out_paused: ps2dev->flags =0 ;serio_continue_rx (ps2dev->serio);
Signature · 1 line
2.5.0.457.gab17608
Quoted 32 lines · On Monday 07 September 2015 16:04:35 Dmitry Vyukov wrote:
The data race happens on
ps2dev->cmdcntandps2dev->cmdbufcontents.__ps2_commandreads that data concurrently with the interrupt handler. As the result, for example, if a response arrives just after the timeout,__ps2_commandcan copy out garbage fromps2dev->cmdbufbut then see thatps2dev->cmdcntis 0 and return success.Stop the interrupt handler with
serio_pause_rx()before reading the results.The data race was found with KernelThreadSanitizer (KTSAN).
Signed-off-by Dmitry Vyukov <[email protected]>--- drivers/input/serio/libps2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/input/serio/libps2.c +1
-2@@ -234,17 +234,19 @@ int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) !(ps2dev->flags & PS2_FLAG_CMD), timeout); } +serio_pause_rx (ps2dev->serio);if (param)for (i =0 ; i < receive; i++) param[i] = ps2dev->cmdbuf[(receive -1 ) - i];if (ps2dev->cmdcnt && (command !=PS2_CMD_RESET_BAT || ps2dev->cmdcnt !=1 )) - goto out; -
drivers/input/serio/libps2.c int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) · line 252
Quoted 10 lines
drivers/input/serio/libps2.c +3
-0+ goto out_paused; rc =0 ; + goto out_paused; out:serio_pause_rx (ps2dev->serio); +out_paused: ps2dev->flags =0 ;serio_continue_rx (ps2dev->serio);
Hi! Was this patch queued? Or is there any problem with it? Because I did not see any response for more weeks on any mailing list.
Signature · 6 lines
Pali Rohár [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html