Skip to content

Commit 16c4cb1

Browse files
Harry Pangregkh
authored andcommitted
usb: core: safely deal with the dynamic quirk lists
Applying dynamic usbcore quirks in early booting when the slab is not yet ready would cause kernel panic of null pointer dereference because the quirk_count has been counted as 1 while the quirk_list was failed to allocate. i.e., [ 1.044970] BUG: unable to handle kernel NULL pointer dereference at (null) [ 1.044995] IP: [<ffffffffb0953ec7>] usb_detect_quirks+0x88/0xd1 [ 1.045016] PGD 0 [ 1.045026] Oops: 0000 [#1] PREEMPT SMP [ 1.046986] gsmi: Log Shutdown Reason 0x03 [ 1.046995] Modules linked in: [ 1.047008] CPU: 0 PID: 81 Comm: kworker/0:3 Not tainted 4.4.154 torvalds#28 [ 1.047016] Hardware name: Google Coral/Coral, BIOS Google_Coral.10068.27.0 12/04/2017 [ 1.047028] Workqueue: usb_hub_wq hub_event [ 1.047037] task: ffff88017a321c80 task.stack: ffff88017a384000 [ 1.047044] RIP: 0010:[<ffffffffb0953ec7>] [<ffffffffb0953ec7>] usb_detect_quirks+0x88/0xd1 To tackle this odd, let's balance the quirk_count to 0 when the kcalloc call fails, and defer the quirk setting into a lower level callback which ensures that the kernel memory management has been initialized. Fixes: 027bd6c ("usb: core: Add "quirks" parameter for usbcore") Signed-off-by: Harry Pan <harry.pan@intel.com> Acked-by: Kai-Heng Feng <kai.heng.feng@canonical.com> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5c54fca commit 16c4cb1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/usb/core/quirks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static int quirks_param_set(const char *val, const struct kernel_param *kp)
5858
quirk_list = kcalloc(quirk_count, sizeof(struct quirk_entry),
5959
GFP_KERNEL);
6060
if (!quirk_list) {
61+
quirk_count = 0;
6162
mutex_unlock(&quirk_mutex);
6263
return -ENOMEM;
6364
}
@@ -154,7 +155,7 @@ static struct kparam_string quirks_param_string = {
154155
.string = quirks_param,
155156
};
156157

157-
module_param_cb(quirks, &quirks_param_ops, &quirks_param_string, 0644);
158+
device_param_cb(quirks, &quirks_param_ops, &quirks_param_string, 0644);
158159
MODULE_PARM_DESC(quirks, "Add/modify USB quirks by specifying quirks=vendorID:productID:quirks");
159160

160161
/* Lists of quirky USB devices, split in device quirks and interface quirks.

0 commit comments

Comments
 (0)