linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: add bounds checking to input_set_capability()
@ 2022-03-20  3:25 Jeff LaBundy
  2022-03-21  4:58 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff LaBundy @ 2022-03-20  3:25 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: linux-input, Jeff LaBundy, Tomasz Moń

Update input_set_capability() to prevent kernel panic in case the
event code exceeds the bitmap for the given event type.

Suggested-by: Tomasz Moń <tomasz.mon@camlingroup.com>
Signed-off-by: Jeff LaBundy <jeff@labundy.com>
Reviewed-by: Tomasz Moń <tomasz.mon@camlingroup.com>
---
 drivers/input/input.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 7c7e4042ec10..6428cdacf534 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -47,6 +47,17 @@ static DEFINE_MUTEX(input_mutex);
 
 static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
 
+static const unsigned int input_max_code[EV_CNT] = {
+	[EV_KEY] = KEY_MAX,
+	[EV_REL] = REL_MAX,
+	[EV_ABS] = ABS_MAX,
+	[EV_MSC] = MSC_MAX,
+	[EV_SW] = SW_MAX,
+	[EV_LED] = LED_MAX,
+	[EV_SND] = SND_MAX,
+	[EV_FF] = FF_MAX,
+};
+
 static inline int is_event_supported(unsigned int code,
 				     unsigned long *bm, unsigned int max)
 {
@@ -2110,6 +2121,14 @@ EXPORT_SYMBOL(input_get_timestamp);
  */
 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code)
 {
+	if (type < EV_CNT && input_max_code[type] &&
+	    code > input_max_code[type]) {
+		pr_err("%s: invalid code %u for type %u\n", __func__, code,
+		       type);
+		dump_stack();
+		return;
+	}
+
 	switch (type) {
 	case EV_KEY:
 		__set_bit(code, dev->keybit);
-- 
2.25.1


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

* Re: [PATCH] Input: add bounds checking to input_set_capability()
  2022-03-20  3:25 [PATCH] Input: add bounds checking to input_set_capability() Jeff LaBundy
@ 2022-03-21  4:58 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2022-03-21  4:58 UTC (permalink / raw)
  To: Jeff LaBundy; +Cc: linux-input, Tomasz Moń

On Sat, Mar 19, 2022 at 10:25:37PM -0500, Jeff LaBundy wrote:
> Update input_set_capability() to prevent kernel panic in case the
> event code exceeds the bitmap for the given event type.
> 
> Suggested-by: Tomasz Moń <tomasz.mon@camlingroup.com>
> Signed-off-by: Jeff LaBundy <jeff@labundy.com>
> Reviewed-by: Tomasz Moń <tomasz.mon@camlingroup.com>

Applied, thank you.

-- 
Dmitry

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

end of thread, other threads:[~2022-03-21  4:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-20  3:25 [PATCH] Input: add bounds checking to input_set_capability() Jeff LaBundy
2022-03-21  4:58 ` 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).