mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Heidelberg <david@ixit.cz>
To: Kuen-Han Tsai <khtsai@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Felipe Balbi <balbi@ti.com>,
	Prashanth K <prashanth.k@oss.qualcomm.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@kernel.org
Subject: Re: [PATCH 3/3] usb: gadget: f_ncm: align net_device lifecycle with bind/unbind
Date: Sat, 28 Feb 2026 22:44:57 +0100	[thread overview]
Message-ID: <795ea759-7eaf-4f78-81f4-01ffbf2d7961@ixit.cz> (raw)
In-Reply-To: <20251230-ncm-refactor-v1-3-793e347bc7a7@google.com>

On 30/12/2025 11:13, Kuen-Han Tsai wrote:
> Currently, the net_device is allocated in ncm_alloc_inst() and freed in
> ncm_free_inst(). This ties the network interface's lifetime to the
> configuration instance rather than the USB connection (bind/unbind).
> 
> This decoupling causes issues when the USB gadget is disconnected where
> the underlying gadget device is removed. The net_device can outlive its
> parent, leading to dangling sysfs links and NULL pointer dereferences
> when accessing the freed gadget device.
> 
> Problem 1: NULL pointer dereference on disconnect
>   Unable to handle kernel NULL pointer dereference at virtual address
>   0000000000000000
>   Call trace:
>     __pi_strlen+0x14/0x150
>     rtnl_fill_ifinfo+0x6b4/0x708
>     rtmsg_ifinfo_build_skb+0xd8/0x13c
>     rtmsg_ifinfo+0x50/0xa0
>     __dev_notify_flags+0x4c/0x1f0
>     dev_change_flags+0x54/0x70
>     do_setlink+0x390/0xebc
>     rtnl_newlink+0x7d0/0xac8
>     rtnetlink_rcv_msg+0x27c/0x410
>     netlink_rcv_skb+0x134/0x150
>     rtnetlink_rcv+0x18/0x28
>     netlink_unicast+0x254/0x3f0
>     netlink_sendmsg+0x2e0/0x3d4
> 
> Problem 2: Dangling sysfs symlinks
>   console:/ # ls -l /sys/class/net/ncm0
>   lrwxrwxrwx ... /sys/class/net/ncm0 ->
>   /sys/devices/platform/.../gadget.0/net/ncm0
>   console:/ # ls -l /sys/devices/platform/.../gadget.0/net/ncm0
>   ls: .../gadget.0/net/ncm0: No such file or directory
> 
> Move the net_device allocation to ncm_bind() and deallocation to
> ncm_unbind(). This ensures the network interface exists only when the
> gadget function is actually bound to a configuration.
> 
> To support pre-bind configuration (e.g., setting interface name or MAC
> address via configfs), cache user-provided options in f_ncm_opts
> using the gether_opts structure. Apply these cached settings to the
> net_device upon creation in ncm_bind().
> 
> Preserve the use-after-free fix from commit 6334b8e4553c ("usb: gadget:
> f_ncm: Fix UAF ncm object at re-bind after usb ep transport error").
> Check opts->net in ncm_set_alt() and ncm_disable() to ensure
> gether_disconnect() runs only if a connection was established.
> 
> Fixes: 40d133d7f542 ("usb: gadget: f_ncm: convert to new function interface with backward compatibility")
> Cc: stable@kernel.org
> Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
> ---
>   drivers/usb/gadget/function/f_ncm.c | 128 ++++++++++++++++++------------------
>   drivers/usb/gadget/function/u_ncm.h |   4 +-
>   2 files changed, 66 insertions(+), 66 deletions(-)
> 

Just for sure writing here too, this patch (even including fixes from 
next-20260227) breaks Snapdragon 845 USB, and also I seen someone from 
MSM8960, so likely it applies on bigger variety of Qualcomm generations.

Ref:
https://lore.kernel.org/all/70b558ea-a12e-4170-9b8e/c951131249af@ixit.cz/

David

-- 
David Heidelberg


  parent reply	other threads:[~2026-02-28 21:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-30 10:13 [PATCH 0/3] usb: gadget: Refactor NCM net_device lifecycle Kuen-Han Tsai
2025-12-30 10:13 ` [PATCH 1/3] usb: gadget: u_ether: add gether_opts for config caching Kuen-Han Tsai
2025-12-30 10:13 ` [PATCH 2/3] usb: gadget: u_ether: Add auto-cleanup helper for freeing net_device Kuen-Han Tsai
2025-12-30 10:13 ` [PATCH 3/3] usb: gadget: f_ncm: align net_device lifecycle with bind/unbind Kuen-Han Tsai
2026-01-09 10:25   ` Ernest Van Hoecke
2026-01-09 10:47     ` Kuen-Han Tsai
2026-02-28 21:44   ` David Heidelberg [this message]
2026-03-09 10:20   ` Jon Hunter
2026-03-09 10:37     ` Kuen-Han Tsai

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=795ea759-7eaf-4f78-81f4-01ffbf2d7961@ixit.cz \
    --to=david@ixit.cz \
    --cc=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=khtsai@google.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=prashanth.k@oss.qualcomm.com \
    --cc=stable@kernel.org \
    /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

all inboxes | Powered by JetHome®