[PATCH 0/2] use-after-free issues in configfs

From: Sascha Hauer
Date: Fri Nov 04 2022 - 09:10:50 EST


This series addresses a few problems with the users of the gether code.
The problem arises when a UDC is disconnected from a gadget created with
configfs doing a "echo '' > UDC". It seems the existing code is tested
up to the point where the gadget from configfs is up, tearing it down
still seems to make problems. I for myself am also not interested in tearing
it down, but I see use-after-free issues when doing a reboot -f.

The underlying problem is that the eth_dev returned by the gether code is used
for multiple bind/unbind cycles, but only initialized properly once.

The usb_gadget * is only valid between bind and unbind, so it is not a suitable
parent for the net_device whose lifetime spans multiple bind/unbind cycles.

I solved the issues for the f_ecm driver, similar problems exist in the other users
like f_eem or f_ncm as well. I can prepare patches for these once it's clear
that this is really the way to go.

Sascha Hauer (2):
usb: gadget: u_ether: Do not make UDC parent of the net device
usb: gadget: f_ecm: Always set current gadget in ecm_bind()

drivers/usb/gadget/function/f_ecm.c | 22 +++++++++-------------
drivers/usb/gadget/function/u_ether.c | 4 ----
2 files changed, 9 insertions(+), 17 deletions(-)

--
2.30.2