hid-appleir: Fix kernel panic due to null pointer
PATCH v2 1/1 hid-appleir: Fix kernel panic due to null pointer
Fixes a null pointer in appleir_input_configured due to reading into wrong size array. Changed the variable to input_dev->keycodemax.
--- drivers/hid/hid-appleir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-appleir.c +1 -1
@@ -272,7 +272,7 @@ static void appleir_input_configured(struct hid_device *hid, input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP );memcpy (appleir->keymap, appleir_key_table,sizeof (appleir->keymap)); -for (i =0 ; i <ARRAY_SIZE (appleir_key_table); i++) +for (i =0 ; i < appleir->keymap; i++)set_bit (appleir->keymap[i], input_dev->keybit);clear_bit (KEY_RESERVED , input_dev->keybit); }
Signature · 1 line
1.9.1
Quoted 2 lines · Nicholas Krause
Fixes a null pointer in
appleir_input_configureddue to reading into wrong size array. Changed the variable toinput_dev->keycodemax.
This is a stale changelog from the previous buggy version.
Quoted 10 lines
Signed-off-by Nicholas Krause <[email protected]>--- drivers/hid/hid-appleir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-appleir.c +0
-0
drivers/hid/hid-appleir.c static void appleir_input_configured(struct hid_device *hid, · line 275
Quoted 5 lines
drivers/hid/hid-appleir.c +1
-1@@ -272,7 +272,7 @@ static void appleir_input_configured(struct hid_device *hid, input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP );memcpy (appleir->keymap, appleir_key_table,sizeof (appleir->keymap)); -for (i =0 ; i <ARRAY_SIZE (appleir_key_table); i++) +for (i =0 ; i < appleir->keymap; i++)
This is wrong. appleir->keymap is an array, and you want to count its elements.
Third time is the charm perhaps?
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 19 lines · Jiri Kosina
Quoted 2 lines · Nicholas Krause
Fixes a null pointer in
appleir_input_configureddue to reading into wrong size array. Changed the variable toinput_dev->keycodemax.This is a stale changelog from the previous buggy version.
Quoted 12 lines
Signed-off-by Nicholas Krause <[email protected]>--- drivers/hid/hid-appleir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-appleir.c +0
-0@@ -272,7 +272,7 @@ static void appleir_input_configured(struct hid_device *hid, input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP );
Quoted 7 lines
drivers/hid/hid-appleir.c static void appleir_input_configured(struct hid_device *hid, · line 275
Quoted 3 lines
drivers/hid/hid-appleir.c +1
-1memcpy (appleir->keymap, appleir_key_table,sizeof (appleir->keymap)); -for (i =0 ; i <ARRAY_SIZE (appleir_key_table); i++) +for (i =0 ; i < appleir->keymap; i++)This is wrong.
appleir->keymapis an array, and you want to count its elements.
But where the claim of 'null pointer' is coming from (or reading/writing past the array for that matter)?
Replacing appleir_key_table with appleir->keymap is a noop anyway because:
unsigned short keymap[ARRAY_SIZE(appleir_key_table)];
although one may argue is slightly nicer since it is used in memcpy line earlier.
Signature · 1 line
Mateusz Guzik
Quoted 25 lines · Mateusz Guzik
Quoted 17 lines
Quoted 2 lines
Fixes a null pointer in
appleir_input_configureddue to reading into wrong size array. Changed the variable toinput_dev->keycodemax.This is a stale changelog from the previous buggy version.
Quoted 12 lines
Signed-off-by Nicholas Krause <[email protected]>--- drivers/hid/hid-appleir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-appleir.c +0
-0@@ -272,7 +272,7 @@ static void appleir_input_configured(struct hid_device *hid, input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP );Quoted 7 lines
drivers/hid/hid-appleir.c static void appleir_input_configured(struct hid_device *hid, · line 275
Quoted 3 lines
drivers/hid/hid-appleir.c +1
-1memcpy (appleir->keymap, appleir_key_table,sizeof (appleir->keymap)); -for (i =0 ; i <ARRAY_SIZE (appleir_key_table); i++) +for (i =0 ; i < appleir->keymap; i++)This is wrong.
appleir->keymapis an array, and you want to count its elements.
Quoted 6 lines
But where the claim of 'null pointer' is coming from (or reading/writing past the array for that matter)?
Replacing
appleir_key_tablewithappleir->keymapis a noop anyway because:
unsigned short keymap[ARRAY_SIZE(appleir_key_table)];
It's not really equivalent. ARRAY_SIZE counts the number of short-sized elements, sizeof() counts the number of bytes that fit into the data structure (which is twice as much, as sizeof(unsigned short) == 2).
Signature · 2 lines
Jiri Kosina SUSE Labs
So I am wondering them should I can it to sizeof(appleir_keymap)? Nick
Quoted 41 lines · Jiri Kosina
Quoted 25 lines · Mateusz Guzik
Quoted 17 lines
Quoted 2 lines
Fixes a null pointer in
appleir_input_configureddue to reading into wrong size array. Changed the variable toinput_dev->keycodemax.This is a stale changelog from the previous buggy version.
Quoted 12 lines
Signed-off-by Nicholas Krause <[email protected]>--- drivers/hid/hid-appleir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hid/hid-appleir.c +0
-0@@ -272,7 +272,7 @@ static void appleir_input_configured(struct hid_device *hid, input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP );Quoted 7 lines
drivers/hid/hid-appleir.c static void appleir_input_configured(struct hid_device *hid, · line 275
Quoted 3 lines
drivers/hid/hid-appleir.c +1
-1memcpy (appleir->keymap, appleir_key_table,sizeof (appleir->keymap)); -for (i =0 ; i <ARRAY_SIZE (appleir_key_table); i++) +for (i =0 ; i < appleir->keymap; i++)This is wrong.
appleir->keymapis an array, and you want to count its elements.Quoted 6 lines
But where the claim of 'null pointer' is coming from (or reading/writing past the array for that matter)?
Replacing
appleir_key_tablewithappleir->keymapis a noop anyway because:
unsigned short keymap[ARRAY_SIZE(appleir_key_table)];It's not really equivalent.
ARRAY_SIZEcounts the number of short-sized elements,sizeof()counts the number of bytes that fit into the data structure (which is twice as much, as sizeof(unsigned short) == 2).--
Jiri Kosina
SUSE Labs