Skip to content

Commit a666b6f

Browse files
palidvhart
authored andcommitted
dell-wmi: Fix access out of memory
Without this patch, dell-wmi is trying to access elements of dynamically allocated array without checking the array size. This can lead to memory corruption or a kernel panic. This patch adds the missing checks for array size. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
1 parent 557b454 commit a666b6f

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎drivers/platform/x86/dell-wmi.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,24 @@ static void dell_wmi_notify(u32 value, void *context)
163163
const struct key_entry *key;
164164
int reported_key;
165165
u16 *buffer_entry = (u16 *)obj->buffer.pointer;
166+
int buffer_size = obj->buffer.length/2;
166167

167-
if (dell_new_hk_type && (buffer_entry[1] != 0x10)) {
168+
if (buffer_size >= 2 && dell_new_hk_type && buffer_entry[1] != 0x10) {
168169
pr_info("Received unknown WMI event (0x%x)\n",
169170
buffer_entry[1]);
170171
kfree(obj);
171172
return;
172173
}
173174

174-
if (dell_new_hk_type || buffer_entry[1] == 0x0)
175+
if (buffer_size >= 3 && (dell_new_hk_type || buffer_entry[1] == 0x0))
175176
reported_key = (int)buffer_entry[2];
176-
else
177+
else if (buffer_size >= 2)
177178
reported_key = (int)buffer_entry[1] & 0xffff;
179+
else {
180+
pr_info("Received unknown WMI event\n");
181+
kfree(obj);
182+
return;
183+
}
178184

179185
key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev,
180186
reported_key);

0 commit comments

Comments
 (0)