linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: cyapa_gen6: fix out-of-bounds stack access
@ 2020-10-26 16:13 Arnd Bergmann
  2020-12-14 23:00 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2020-10-26 16:13 UTC (permalink / raw)
  To: Dmitry Torokhov, Dudley Du
  Cc: Arnd Bergmann, Gustavo A. R. Silva, linux-input, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc -Warray-bounds warns about a serious bug in
cyapa_pip_retrieve_data_structure:

drivers/input/mouse/cyapa_gen6.c: In function 'cyapa_pip_retrieve_data_structure.constprop':
include/linux/unaligned/access_ok.h:40:17: warning: array subscript -1 is outside array bounds of 'struct retrieve_data_struct_cmd[1]' [-Warray-bounds]
   40 |  *((__le16 *)p) = cpu_to_le16(val);
drivers/input/mouse/cyapa_gen6.c:569:13: note: while referencing 'cmd'
  569 |  } __packed cmd;
      |             ^~~

Apparently the '-2' was added to the pointer instead of the value,
writing garbage into the stack next to this variable.

Fixes: c2c06c41f700 ("Input: cyapa - add gen6 device module support")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/input/mouse/cyapa_gen6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/mouse/cyapa_gen6.c b/drivers/input/mouse/cyapa_gen6.c
index 7eba66fbef58..812edfced86e 100644
--- a/drivers/input/mouse/cyapa_gen6.c
+++ b/drivers/input/mouse/cyapa_gen6.c
@@ -573,7 +573,7 @@ static int cyapa_pip_retrieve_data_structure(struct cyapa *cyapa,
 
 	memset(&cmd, 0, sizeof(cmd));
 	put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &cmd.head.addr);
-	put_unaligned_le16(sizeof(cmd), &cmd.head.length - 2);
+	put_unaligned_le16(sizeof(cmd) - 2, &cmd.head.length);
 	cmd.head.report_id = PIP_APP_CMD_REPORT_ID;
 	cmd.head.cmd_code = PIP_RETRIEVE_DATA_STRUCTURE;
 	put_unaligned_le16(read_offset, &cmd.read_offset);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] input: cyapa_gen6: fix out-of-bounds stack access
  2020-10-26 16:13 [PATCH] input: cyapa_gen6: fix out-of-bounds stack access Arnd Bergmann
@ 2020-12-14 23:00 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2020-12-14 23:00 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Dudley Du, Arnd Bergmann, Gustavo A. R. Silva, linux-input, linux-kernel

On Mon, Oct 26, 2020 at 05:13:29PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc -Warray-bounds warns about a serious bug in
> cyapa_pip_retrieve_data_structure:
> 
> drivers/input/mouse/cyapa_gen6.c: In function 'cyapa_pip_retrieve_data_structure.constprop':
> include/linux/unaligned/access_ok.h:40:17: warning: array subscript -1 is outside array bounds of 'struct retrieve_data_struct_cmd[1]' [-Warray-bounds]
>    40 |  *((__le16 *)p) = cpu_to_le16(val);
> drivers/input/mouse/cyapa_gen6.c:569:13: note: while referencing 'cmd'
>   569 |  } __packed cmd;
>       |             ^~~
> 
> Apparently the '-2' was added to the pointer instead of the value,
> writing garbage into the stack next to this variable.
> 
> Fixes: c2c06c41f700 ("Input: cyapa - add gen6 device module support")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied, thank you.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-14 23:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 16:13 [PATCH] input: cyapa_gen6: fix out-of-bounds stack access Arnd Bergmann
2020-12-14 23:00 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).