linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Check whether getkeycode and setkeycode are still valide
@ 2010-03-21  2:56 Yong Wang
  2010-03-21  3:11 ` Dmitry Torokhov
  0 siblings, 1 reply; 5+ messages in thread
From: Yong Wang @ 2010-03-21  2:56 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input

If sparse keymap is freed before unregistering the device, there is a
window where userspace can issue EVIOCGKEYCODE or EVIOCSKEYCODE. When
that happens, kernel will crash. Noticed by Dmitry Torokhov.

Signed-off-by: Yong Wang <yong.y.wang@intel.com>
---
 drivers/input/input.c         |    6 ++++++
 drivers/input/sparse-keymap.c |    6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index e2aad0a..bfe4bdc 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -659,6 +659,9 @@ static int input_default_setkeycode(struct input_dev *dev,
 int input_get_keycode(struct input_dev *dev,
 		      unsigned int scancode, unsigned int *keycode)
 {
+	if (!dev->getkeycode)
+		return -ENODEV;
+
 	return dev->getkeycode(dev, scancode, keycode);
 }
 EXPORT_SYMBOL(input_get_keycode);
@@ -682,6 +685,9 @@ int input_set_keycode(struct input_dev *dev,
 	if (keycode > KEY_MAX)
 		return -EINVAL;
 
+	if (!dev->getkeycode || !dev->setkeycode)
+		return -ENODEV;
+
 	spin_lock_irqsave(&dev->event_lock, flags);
 
 	retval = dev->getkeycode(dev, scancode, &old_keycode);
diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c
index f64e004..25b8d7d 100644
--- a/drivers/input/sparse-keymap.c
+++ b/drivers/input/sparse-keymap.c
@@ -34,6 +34,9 @@ struct key_entry *sparse_keymap_entry_from_scancode(struct input_dev *dev,
 {
 	struct key_entry *key;
 
+	if (!dev->keycode)
+		return NULL;
+
 	for (key = dev->keycode; key->type != KE_END; key++)
 		if (code == key->code)
 			return key;
@@ -55,6 +58,9 @@ struct key_entry *sparse_keymap_entry_from_keycode(struct input_dev *dev,
 {
 	struct key_entry *key;
 
+	if (!dev->keycode)
+		return NULL;
+
 	for (key = dev->keycode; key->type != KE_END; key++)
 		if (key->type == KE_KEY && keycode == key->keycode)
 			return key;

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

end of thread, other threads:[~2010-03-22  5:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-21  2:56 [PATCH] Check whether getkeycode and setkeycode are still valide Yong Wang
2010-03-21  3:11 ` Dmitry Torokhov
2010-03-22  2:48   ` Yong Wang
2010-03-22  4:22     ` Dmitry Torokhov
2010-03-22  5:39       ` Yong Wang

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).