提交 a273c3f3 编写于 作者: J Jeff LaBundy 提交者: Zheng Zengkai

Input: add bounds checking to input_set_capability()

stable inclusion
from stable-v5.10.118
commit d5e88c2d76efa9d7bb7ceffaec60fe6c76c748d7
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L686

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d5e88c2d76efa9d7bb7ceffaec60fe6c76c748d7

--------------------------------

[ Upstream commit 409353cb ]

Update input_set_capability() to prevent kernel panic in case the
event code exceeds the bitmap for the given event type.
Suggested-by: NTomasz Moń <tomasz.mon@camlingroup.com>
Signed-off-by: NJeff LaBundy <jeff@labundy.com>
Reviewed-by: NTomasz Moń <tomasz.mon@camlingroup.com>
Link: https://lore.kernel.org/r/20220320032537.545250-1-jeff@labundy.comSigned-off-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 ecbd31ec
...@@ -47,6 +47,17 @@ static DEFINE_MUTEX(input_mutex); ...@@ -47,6 +47,17 @@ static DEFINE_MUTEX(input_mutex);
static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 }; 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, static inline int is_event_supported(unsigned int code,
unsigned long *bm, unsigned int max) unsigned long *bm, unsigned int max)
{ {
...@@ -1979,6 +1990,14 @@ EXPORT_SYMBOL(input_get_timestamp); ...@@ -1979,6 +1990,14 @@ EXPORT_SYMBOL(input_get_timestamp);
*/ */
void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code) 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) { switch (type) {
case EV_KEY: case EV_KEY:
__set_bit(code, dev->keybit); __set_bit(code, dev->keybit);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册