lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 28 Sep 2015 08:50:25 +0200
From:	Sedat Dilek <sedat.dilek@...il.com>
To:	Jiri Kosina <jikos@...nel.org>
Cc:	Tejun Heo <tj@...nel.org>, Lai Jiangshan <jiangshanlai@...il.com>,
	LKML <linux-kernel@...r.kernel.org>, linux-input@...r.kernel.org,
	Paul McKenney <paulmck@...ux.vnet.ibm.com>
Subject: Re: [Linux v4.2] workqueue: llvmlinux: acpid: BUG: sleeping function
 called from invalid context at kernel/workqueue.c:2680

[ CC only relevant people plus Paul as he took care in another thread ]

First of all, sorry for flooding anybody or any mailing-list.

Of course, using LLVM/Clang for the Linux-kernel is still WIP, but
this does not mean using a different compiler does not find any
bugs...

Fascinated somehow of this problem I entered the "tracing" area.
I played a bit with tracing and irq-flags (hardirqs).

This is what I discovered now.

[ TEST-1 ]

--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -731,6 +731,7 @@ void usbhid_close(struct hid_device *hid)
         */
        spin_lock_irq(&usbhid->lock);
        if (!--hid->open) {
+               trace_hardirqs_off();
                spin_unlock_irq(&usbhid->lock);
                hid_cancel_delayed_stuff(usbhid);
                if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) {
@@ -1392,6 +1393,8 @@ static void usbhid_disconnect(struct usb_interface *intf)

 static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid)
 {
+       might_sleep();
+
        del_timer_sync(&usbhid->io_retry);
        cancel_work_sync(&usbhid->reset_work);
 }

This makes the BUG line go away - only changes in the HID area.

[ TEST-2 ]

--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -732,6 +732,7 @@ void usbhid_close(struct hid_device *hid)
        spin_lock_irq(&usbhid->lock);
        if (!--hid->open) {
                spin_unlock_irq(&usbhid->lock);
+               trace_hardirqs_off();
                hid_cancel_delayed_stuff(usbhid);
                if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) {
                        usb_kill_urb(usbhid->urbin);
@@ -1392,6 +1393,8 @@ static void usbhid_disconnect(struct usb_interface *intf)

 static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid)
 {
+       might_sleep();
+
        del_timer_sync(&usbhid->io_retry);
        cancel_work_sync(&usbhid->reset_work);
 }

This results in...

[   23.236024] BUG: sleeping function called from invalid context at
drivers/hid/usbhid/hid-core.c:1396
[   23.236148] in_atomic(): 0, irqs_disabled(): 1, pid: 1419, name: acpid
[   23.236233] 3 locks held by acpid/1419:
[   23.236235]  #0:  (&evdev->mutex){+.+...}, at: [<ffffffff8174c98c>]
evdev_release+0xbc/0xf0
[   23.236250]  #1:  (&dev->mutex#2){+.+...}, at: [<ffffffff817440a7>]
input_close_device+0x27/0x70
[   23.236264]  #2:  (hid_open_mut){+.+...}, at: [<ffffffffa008e388>]
usbhid_close+0x28/0xd0 [usbhid]
[   23.236277] irq event stamp: 3406
[   23.236280] hardirqs last  enabled at (3405): [<ffffffff8192ccd2>]
_raw_spin_unlock_irq+0x32/0x60
[   23.236286] hardirqs last disabled at (3406): [<ffffffffa008e3bd>]
usbhid_close+0x5d/0xd0 [usbhid]
[   23.236292] softirqs last  enabled at (2806): [<ffffffff818b3069>]
local_bh_enable+0x9/0x20
[   23.236298] softirqs last disabled at (2804): [<ffffffff818b3049>]
local_bh_disable+0x9/0x20
[   23.236306] CPU: 3 PID: 1419 Comm: acpid Not tainted
4.3.0-rc3-4-llvmlinux-amd64 #3
[   23.236309] Hardware name: SAMSUNG ELECTRONICS CO., LTD.
530U3BI/530U4BI/530U4BH/530U3BI/530U4BI/530U4BH, BIOS 13XK 03/28/2013
[   23.236313]  ffff8800c760b000 0000000000000096 0000000000000000
ffff8800bce53c88
[   23.236320]  ffffffff8149cabd ffff8800bce53cb8 ffffffff810cd5aa
ffffffffa009780c
[   23.236328]  ffff8800c5fd5740 0000000000000000 0000000000000574
ffff8800bce53cf8
[   23.236334] Call Trace:
[   23.236342]  [<ffffffff8149cabd>] dump_stack+0x7d/0xa0
[   23.236347]  [<ffffffff810cd5aa>] ___might_sleep+0x28a/0x2a0
[   23.236351]  [<ffffffff810cd2af>] __might_sleep+0x4f/0xc0
[   23.236357]  [<ffffffffa008e3d5>] usbhid_close+0x75/0xd0 [usbhid]
[   23.236366]  [<ffffffffa00714d1>] hidinput_close+0x31/0x40 [hid]
[   23.236373]  [<ffffffffa00714a0>] ? hidinput_open+0x40/0x40 [hid]
[   23.236378]  [<ffffffff817440c8>] input_close_device+0x48/0x70
[   23.236382]  [<ffffffff8174c9a6>] evdev_release+0xd6/0xf0
[   23.236387]  [<ffffffff81274367>] __fput+0x107/0x240
[   23.236392]  [<ffffffff812741f6>] ____fput+0x16/0x20
[   23.236397]  [<ffffffff810b97bc>] task_work_run+0x6c/0xe0
[   23.236403]  [<ffffffff81003b8a>] prepare_exit_to_usermode+0x13a/0x140
[   23.236408]  [<ffffffff81003e11>] syscall_return_slowpath+0x281/0x2f0
[   23.236414]  [<ffffffff81270a45>] ? filp_close+0x65/0x90
[   23.236420]  [<ffffffff810f02d9>] ? trace_hardirqs_on_caller+0x19/0x290
[   23.236425]  [<ffffffff81003017>] ? trace_hardirqs_on_thunk+0x17/0x19
[   23.236431]  [<ffffffff8192d9e2>] int_ret_from_sys_call+0x25/0x9f

I will not do a statement :-).

Looking at TEST-1, the spin_unlock_irq() within the if-statement seems
to do cause problems with tracing / irq-flags.

I have added my kernel-config, llvmlinux patchset, diffs with
corresponding dmesg-logs (look into the attached tarball).

Hope this really helps you.

- Sedat -

Download attachment "for-jikos.tar.gz" of type "application/x-gzip" (88271 bytes)

Download attachment "for-jikos.tar.gz.md5sum" of type "application/octet-stream" (51 bytes)

Powered by blists - more mailing lists