Skip to content

hid: ipts: Fix double list_del race in ipts_mei_search() - #178

Open
joshuaspaulding wants to merge 1 commit into
linux-surface:v6.19-surface-develfrom
joshuaspaulding:ipts-fix-mei-search-race
Open

joshuaspaulding wants to merge 1 commit into
linux-surface:v6.19-surface-develfrom
joshuaspaulding:ipts-fix-mei-search-race

Conversation

@joshuaspaulding

@joshuaspaulding joshuaspaulding commented Sep 3, 2026 •

Copy link
Copy Markdown

Summary

ipts_mei_search() walks the received-message list under the read side of message_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 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 it surfaces as a general protection fault on 0xdead000000000108 in ipts_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.c in this branch is identical to the 6.12 series version, so the patch applies unchanged across the maintained branches.

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>
@joshuaspaulding
joshuaspaulding force-pushed the ipts-fix-mei-search-race branch from 4d5bc29 to f6df3e9 Compare September 3, 2026 02:49
@antoniovazquezblanco

Copy link
Copy Markdown

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!

@loafecho

Copy link
Copy Markdown

@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 0xdead000000000108, RIP: ipts_mei_search, Comm: ipts_poll, two seconds after a resume from sleep. The trigger was a local sleep hook that reloaded the driver on wake, right after the kernel's own re-probe, so two starts raced. The crash store also has the same fault from an earlier date on the stock linux-surface 6.19.8 kernel, so it isn't caused by my other patches.

Same fix here: my local patch also finds and unlinks the reply under one write lock (it keeps a found pointer instead of testing list_entry_is_head(), otherwise the same idea).

Reproducer: reload the driver while four processes send HID feature requests to its hidraw node during start-up.

  • Stock driver: faulted in the first cycle in 4 of 4 runs.
  • My fix plus separate stop-path changes: 200 of 200 cycles, 0 kernel errors. That run included the other changes, so it isn't a test of this PR's exact code.

Not tested: this PR's exact code; any other Surface model.

drivers/hid/ipts/mei.c is identical on v6.19-surface-devel, v7.2-surface-devel and v7.3-surface-devel, so this applies unchanged to the newer branches too.

@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 rmmod hang in ipts_thread_stop(), because the stop waits with no timeout for the poll thread, which is either dead or blocked on the lock the crashed task held. (Suspend takes the same path; I haven't seen it hang.) I have a fix for that, but it needs more work before I post it.

This was referenced Nov 7, 2026
@antoniovazquezblanco

Copy link
Copy Markdown

@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.

Sorry @joshuaspaulding for my last comment pointing to the wrong repo. Thanks @loafecho for this pointer towards the correct place to report!

@antoniovazquezblanco

Copy link
Copy Markdown

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 v6.19-surface-devel, which is two releases behind the current devel branches. I think the correct target branch would be v7.3-surface-devel and your patch would need no change for that.

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 IPTS_CMD_FEEDBACK at the same time.
Only two paths reach that wait: the poll loop via ipts_control_refill_buffer(), and EDS2 userspace via ipts_control_hid2me_feedback() from ipts_eds2_get_feature() and ipts_eds2_set_feature().
ipts_eds1_raw_request() only handles SET_MODE and never sends hid2me feedback, so on EDS1 the poll thread is the only FEEDBACK waiter and there is nothing to race it with.

In summary, this works on SP4 :)

@loafecho

loafecho commented Nov 7, 2026

Copy link
Copy Markdown

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants