All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Johan Hovold <johan@kernel.org>
Cc: "William A. Kennington III" <william@wkennington.com>,
	Oliver Neukum <oneukum@suse.com>,
	Havard Skinnemoen <hskinnemoen@google.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] USB: cdc-acm: refuse writes after disconnect
Date: Fri, 20 Nov 2026 14:45:36 +0100	[thread overview]
Message-ID: <2026112026-dangling-smudge-fd78@gregkh> (raw)
In-Reply-To: <awAtdlEpSLc1ges1@hovoldconsulting.com>

On Fri, Nov 20, 2026 at 12:22:30PM +0100, Johan Hovold wrote:
> On Wed, Nov 18, 2026 at 02:56:36PM +0000, William A. Kennington III wrote:
> > Commit 7fb57a019f94 ("USB: cdc-acm: Fix potential deadlock (lockdep
> > warning)") stopped clearing acm->dev in acm_disconnect() and replaced
> > ACM_READY() with acm->disconnected, but left the write path checking
> > !acm->dev and dropped the disconnect check from acm_tty_write_room().
> > Because acm_disconnect() frees the write buffers with
> > usb_free_coherent() and acm_probe() only pins acm->control, a late
> > acm_tty_write() call dereferences freed memory.
> > 
> > This can happen when a CDC-ACM device disconnects while a file
> > descriptor remains open with a line discipline such as mctp-serial
> > attached. Hangup closes the line discipline, but a subsequent reopen of
> > the hung-up TTY calls tty_reopen() -> tty_ldisc_reinit() from the saved
> > c_line before acm_tty_open() fails with -ENODEV. Because the original
> > descriptor keeps tty->count non-zero, the reinitialized mctp-serial
> > instance stays attached and faults in memcpy() inside acm_tty_write() on
> > the freed wb->buf when transmitting.
> 
> Thanks for reporting this. I assume this is not something you actually
> hit yourself but rather something flagged by an LLM?
> 
> > Pin acm->data alongside acm->control until acm_port_destruct() so the
> > unlocked dev_vdbg() in acm_tty_write() stays valid across disconnect,
> > check acm->disconnected at the start of the write_lock critical section,
> > report zero room in acm_tty_write_room() once disconnected, and set
> > acm->disconnected under write_lock in acm_disconnect() so any concurrent
> > writer finishes before the URBs are poisoned and the buffers are freed.
> 
> This isn't the right fix though as the line disciplines should not be
> calling back into the driver after a hangup (and this isn't cdc-acm
> specific).
> 
> I've prepared a fix that restores the ldisc to N_TTY when a tty is
> reopened after a hangup instead.

Argh, I grabbed this too soon, I'll go revert it...

      reply	other threads:[~2026-11-20 13:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:56 [PATCH] USB: cdc-acm: refuse writes after disconnect William A. Kennington III
2026-11-18 15:09 ` sashiko-bot
2026-11-19  8:24 ` Oliver Neukum
2026-11-20  6:55   ` William A. Kennington III
2026-11-20 11:22 ` Johan Hovold
2026-11-20 13:45   ` Greg Kroah-Hartman [this message]

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=2026112026-dangling-smudge-fd78@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=hskinnemoen@google.com \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=william@wkennington.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.