public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
From: Aditya Garg <gargaditya08@live.com>
To: Sangyun Kim <sangyun.kim@snu.ac.kr>,
	jikos@kernel.org, bentiss@kernel.org
Cc: qasdev00@gmail.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] HID: appletb-kbd: fix UAF and mutex-in-atomic in inactivity timer
Date: Mon, 20 Apr 2026 18:17:36 +0530	[thread overview]
Message-ID: <MAUPR01MB115460F44776CC8E5E5EE7DC4B82F2@MAUPR01MB11546.INDPRD01.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20260420051318.1411671-1-sangyun.kim@snu.ac.kr>



On 4/20/26 10:43, Sangyun Kim wrote:
> This series addresses two defects in hid-appletb-kbd's inactivity
> timer subsystem.  The two patches target different bugs and are
> logically independent; they are sent together because they touch the
> same tear-down code and because the same maintainer will review both.
> 
> Patch 1 fixes a slab use-after-free with two related tear-down windows
> introduced by commit 38224c472a03 ("HID: appletb-kbd: fix slab
> use-after-free bug in appletb_kbd_probe"):
> 
>    A) Within "if (kbd->backlight_dev)" the order was
>       put_device() then timer_delete_sync().  A concurrent
>       hid_appletb_bl unbind between those two calls can drop the last
>       devm reference and free the backlight_device; the still-armed
>       inactivity timer softirq then dereferences the freed object
>       through backlight_device_set_brightness() -> mutex_lock(&ops_lock).
> 
>    B) The "if (kbd->backlight_dev)" block ran before
>       hid_hw_close()/hid_hw_stop(), so even after window A is closed a
>       late ".event" callback from the HID core (USB URB completion on
>       real hardware) can arrive between timer_delete_sync() and
>       put_device(), reach reset_inactivity_timer(), re-arm the timer
>       via mod_timer(), and reopen the same UAF.
> 
> Both windows produce the same KASAN slab-use-after-free on the object
> allocated by devm_backlight_device_register().  Patch 1 closes them
> together by moving hid_hw_close()/hid_hw_stop() before the backlight
> cleanup and, inside that cleanup block, calling timer_delete_sync()
> before put_device().  Shipping both as one commit avoids leaving
> stable kernels in a half-fixed state where only window A is closed.
> 
> Patch 2 fixes a separate "sleeping function called from invalid
> context" bug in the same subsystem.  The inactivity timer is a
> struct timer_list, so the callback runs in softirq context and calls
> backlight_device_set_brightness() -> mutex_lock() from atomic
> context; reset_inactivity_timer() has the same issue on the
> brightness-restore path (it is called from appletb_kbd_hid_event()
> and appletb_kbd_inp_event(), which run in softirq/IRQ context on
> real USB hardware).  Convert the inactivity timer to a delayed_work
> and defer the brightness-restore call to a dedicated work_struct so
> both sleeping calls run in process context.
> 
> Sangyun Kim (2):
>    HID: appletb-kbd: fix UAF in inactivity-timer cleanup path
>    HID: appletb-kbd: run inactivity autodim from workqueues
> 
>   drivers/hid/hid-appletb-kbd.c | 56 ++++++++++++++++++++++-------------
>   1 file changed, 36 insertions(+), 20 deletions(-)
> 

I had a very weird bug just once. And that was when I pressed fn key, 
upon releasing, the touchbar mode did not restore to normal.

Although it was just once, and I was never able to reproduce it again.

Have you tested it on your Machine btw?


  parent reply	other threads:[~2026-04-20 12:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  5:13 [PATCH 0/2] HID: appletb-kbd: fix UAF and mutex-in-atomic in inactivity timer Sangyun Kim
2026-04-20  5:13 ` [PATCH 1/2] HID: appletb-kbd: fix UAF in inactivity-timer cleanup path Sangyun Kim
2026-04-20  5:13 ` [PATCH 2/2] HID: appletb-kbd: run inactivity autodim from workqueues Sangyun Kim
2026-04-20 12:47 ` Aditya Garg [this message]
2026-04-22  6:01   ` [PATCH 0/2] HID: appletb-kbd: fix UAF and mutex-in-atomic in inactivity timer Sangyun Kim
2026-04-22  9:15     ` Aditya Garg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MAUPR01MB115460F44776CC8E5E5EE7DC4B82F2@MAUPR01MB11546.INDPRD01.PROD.OUTLOOK.COM \
    --to=gargaditya08@live.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qasdev00@gmail.com \
    --cc=sangyun.kim@snu.ac.kr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox