Repository navigation
hid: ipts: Fix double list_del race in ipts_mei_search() - #178
joshuaspaulding wants to merge 1 commit into
Conversation
ipts_mei_search() looks up a matching response under the read side of message_lock, drops the lock, and then re-acquires it for writing to unlink the entry. Two concurrent callers waiting for the same command code (typically the receiver poll thread and a userspace hidraw raw request, both inside ipts_control_send_feedback()) can each find the same entry during their read-locked walk and then both unlink and free it. The second list_del() hits LIST_POISON and, with CONFIG_DEBUG_LIST, oopses the poll kthread: list_del corruption, ...->next is LIST_POISON1 (dead000000000100) kernel BUG at lib/list_debug.c:56! RIP: __list_del_entry_valid_or_report.cold Call Trace: ipts_mei_search+0x83/0x150 [ipts] ipts_mei_recv+0x61/0x190 [ipts] ipts_cmd_recv_timeout+0x2f/0x90 [ipts] ipts_control_send_feedback+0x81/0xc0 [ipts] ipts_receiver_poll_loop.cold+0x89/0x11c [ipts] ipts_thread_runner+0x21/0x40 [ipts] Without CONFIG_DEBUG_LIST the same race shows up as a general protection fault on 0xdead000000000108 in ipts_mei_search(). The other caller is then left blocked in D state inside the driver, which makes every later suspend fail with "tasks refusing to freeze". Seen on resume from s2idle on a Surface Pro 7 while iptsd was (re)started. Hold the write lock across the search and the unlink so that a message can only be claimed by one caller. Signed-off-by: Josh Spaulding <git@spaulding.app>
4d5bc29 to
f6df3e9
Compare
|
I am not very much up to date on the development procedures here so don't trust me blindly but, should this be posted at https://github.com/linux-surface/intel-precise-touch? Thanks! |
|
@joshuaspaulding, a second Surface Pro 7 report on this one, with numbers. Disclosure: this work was done with help from an AI coding assistant, which also ran the tests on my own Surface Pro 7. Setup: Surface Pro 7 (EDS2, poll mode), Ubuntu 24.04, linux-surface kernel 6.19.8. Same crash here: general protection fault on Same fix here: my local patch also finds and unlinks the reply under one write lock (it keeps a Reproducer: reload the driver while four processes send HID feature requests to its hidraw node during start-up.
Not tested: this PR's exact code; any other Surface model.
@antoniovazquezblanco, on where this belongs: intel-precise-touch's last commit is from April 2024, and the most recent ipts fix ("hid: ipts: Fix size of synthesized HID data report") went straight into the v7.2 and v7.3 kernel branches here. So this repo looks like the right place now. Separately, after this fault reboot, power-off and |
Sorry @joshuaspaulding for my last comment pointing to the wrong repo. Thanks @loafecho for this pointer towards the correct place to report! |
|
I am still trying to learn how to contribute here so please, do not take the following feedback without a second questioning but here are some things that may help this get merged possibly. @joshuaspaulding, I think it is worth changing the target branch of this PR. This targets As for my side, I ran this on a Surface Pro 4 to add a second hardware generation to the two SP7 reports. The race is structurally unreachable on EDS1, so this is a no-regression result, not a second reproduction. The double claim needs two tasks waiting on In summary, this works on SP4 :) |
|
@joshuaspaulding I ran this PR's exact change on my Surface Pro 7 now, to fill the gap I left in my earlier comment. Build was stock v7.3-surface-devel drivers/hid/ipts plus this PR's diff and nothing else. mei.c is identical on 6.19 and 7.3, so it's the same code you have here, and it's also byte for byte the first commit of #187. Same reproducer as before, reload the driver while four processes send HID feature requests to its hidraw node during start-up. 200 of 200 cycles in one boot, no oops, no general protection fault, no BUG or WARNING lines, the hidraw node came back every cycle and the touch check passed at the end. This kernel doesn't have CONFIG_DEBUG_LIST, so a double list_del here would show up as the general protection fault on 0xdead000000000108 from my earlier comment. For comparison, stock 6.19.8 faulted in the first cycle in 4 of 4 runs with this reproducer. I didn't rerun stock on 7.3. The log still has a lot of the driver's normal error lines during the reloads, mostly "Failed to process buffer: -16" and -11 timeouts on QUIESCE_IO and FEEDBACK. I haven't compared those against another build, but none of them led to a crash. Tested-by: Tony Garcia 180770769+loafecho@users.noreply.github.com |
Summary
ipts_mei_search()walks the received-message list under the read side ofmessage_lock, drops the lock, then re-takes it for writing to unlink the entry it found. Two waiters for the same command code (typically the receiver poll thread and a userspace hidraw raw request, both insideipts_control_send_feedback()) can each find the same entry during their read-locked walk and then both unlink and free it. The secondlist_del()hitsLIST_POISONand, withCONFIG_DEBUG_LIST, oopses the poll kthread:Without
CONFIG_DEBUG_LISTit surfaces as a general protection fault on0xdead000000000108inipts_mei_search(). The other caller is then stuck in D state inside the driver, so every later suspend fails with "tasks refusing to freeze" until reboot.This is the same trace as linux-surface/linux-surface#2122 and linux-surface/intel-precise-touch#33.
The fix holds the write lock across the search and the unlink, so a message can only be claimed by one caller.
Testing
Surface Pro 7 (IPTS 045E:099F, EDS v2, poll mode). Reproduced on 6.12.107 with the stock patch series: oops on resume from s2idle while iptsd was being restarted, followed by an unfreezable iptsd for the rest of the boot. Rebuilt 6.12.107 with this change and ran repeated s2idle suspend/resume cycles with iptsd stopped before sleep and restarted on wake, which exercises the poll thread and the hidraw path concurrently. No oops, poll thread and iptsd healthy after every cycle.
The
drivers/hid/ipts/mei.cin this branch is identical to the 6.12 series version, so the patch applies unchanged across the maintained branches.