The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Pei Xiao <xiaopei01@kylinos.cn>
To: vaibhavgupta40@gmail.com, jens.taprogge@taprogge.org,
	gregkh@linuxfoundation.org, kees@kernel.org,
	industrypack-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: Pei Xiao <xiaopei01@kylinos.cn>,
	Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Subject: [PATCH 0/2] ipack: ipoctal: fix races and UAFs during module removal
Date: Wed,  1 Jul 2026 10:01:08 +0800	[thread overview]
Message-ID: <cover.1782870760.git.xiaopei01@kylinos.cn> (raw)

When the ipoctal device is removed while a userspace process still
holds a tty fd open, several races and use-after-free bugs can be
triggered.  This series addresses the following issues:

1. UAF of struct ipoctal: the remove callback freed ipoctal via
   kfree() while in-flight tty ops could still be accessing it.

2. NULL dereference in ipoctal_write_tty(): __ipoctal_remove() freed
   xmit_buf while a concurrent write() could still dereference it.

3. UAF in ipoctal_cleanup(): ipack_put_carrier(ipoctal->dev) walked
   through ipoctal->dev to reach the carrier module, but the
   ipack_device could have already been freed by then.

4. Page faults due to devm_ioremap() regions being unmapped while
   tty ops still access hardware registers.

5. TOCTOU race between the removed-flag check and the subsequent
   hardware access in each tty op.

Patch 1 introduces kref-based lifetime management, caches the
carrier owner module pointer to avoid chasing a dangling dev->bus
pointer, adds a "removed" flag with checks in all tty ops that
touch hardware, and adds a NULL guard on xmit_buf in the write path.

Patch 2 adds a read-write semaphore (remove_sem) to close the
TOCTOU window: the tty ops hold the read lock for the duration of
the hardware access, while __ipoctal_remove() acquires the write
lock when setting the removed flag, ensuring that once removed is
true no in-flight tty op is still inside a critical section.

Reported-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Link: https://lore.kernel.org/lkml/178144969601.60470.1257088106279546587@gmail.com/

Pei Xiao (2):
  ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup
    on remove
  ipack: ipoctal: add rwsem to guard against TOCTOU in remove path

 drivers/ipack/devices/ipoctal.c | 60 ++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 4 deletions(-)

--
2.25.1


             reply	other threads:[~2026-07-01  2:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  2:01 Pei Xiao [this message]
2026-07-01  2:01 ` [PATCH 1/2] ipack: ipoctal: fix UAF, null-ptr-deref, and use-after-free in cleanup on remove Pei Xiao
2026-07-01  2:01 ` [PATCH 2/2] ipack: ipoctal: add rwsem to guard against TOCTOU in remove path Pei Xiao
2026-07-01  5:41 ` [PATCH 0/2] ipack: ipoctal: fix races and UAFs during module removal Greg KH
2026-07-01  6:16   ` Pei Xiao
2026-07-01 10:37     ` Greg KH
2026-07-01 11:08       ` Pei Xiao

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=cover.1782870760.git.xiaopei01@kylinos.cn \
    --to=xiaopei01@kylinos.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=industrypack-devel@lists.sourceforge.net \
    --cc=jens.taprogge@taprogge.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shuangpeng.kernel@gmail.com \
    --cc=vaibhavgupta40@gmail.com \
    /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