From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF68534D4EA for ; Wed, 10 Jun 2026 18:08:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781114940; cv=none; b=Otj8SJ5AglopuDWjKtooeYJlyM1i0wvscLrS9t/yXSZrkl/OuHjUpUM1Hz3SMVJ7M1P/naE69aFBWiOJ1zEEs+M54XBpBT6dhXMPlqQxNyTiex8N9uzQttY/rzchzOyUvP5TMzaScoWZHM5N5lhZzGN7iMLhlbfufl3TI/s+OA4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781114940; c=relaxed/simple; bh=gdkRLsEYdTfbD6NMnn7No115YeZMwlYuglRnCd5Nnlo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sn1Np3GwIQtDJ8vn5UfltNVyvtG4MdqJAZUS7nUBoPo/bLydGOOnTS++BDzR/TaH1Tg8kDP7dlycUw+jDEkNkDmaTL9BKrSaz176PZjBmN8rzDMv6P43e4L7X2OX2UKl8ac9MNHeY3HPes5AOTiUihGY7CuPOme4nv0gd0eXZZU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vu1mzTCr; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vu1mzTCr" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137eff27f36so347878c88.1 for ; Wed, 10 Jun 2026 11:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781114938; x=1781719738; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1tVvKPjpVOuOIT3ExmpgiKRZJ1awT71IaVj9uNbuWBI=; b=vu1mzTCr/FCEFLlIOTM8uGQXkiuv4YhppwUbiMu52uTd3CIwm35mH0wjGmax9/zM2S cbzNNaacs0U/ZB/fRLtI+6J+wsFzeIQK2S6IQ7dnoZZnpkPjFuKIFLznaRaucW5EK3hr 9fyyFrNpGEIRayCM2ReVU+00Zee4AxcCLA4Wp1ggURPNdEeSTM/2YakAHmET2JzI5SI1 b/g7IpyBKZokKJ1t+UdKEX76jjFsD1ZgQHl4ZXgf+f7NJhWYNO02JYqtiXHWqwTDh/Qx oZIom5dt2/z+WK6s2XWrTEqdYNU6GxD53/ixjcVnW93+pczF/TH2dJZMqQQhiMFDtNkP knQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781114938; x=1781719738; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1tVvKPjpVOuOIT3ExmpgiKRZJ1awT71IaVj9uNbuWBI=; b=sdCAKKufbXhPdVumSpv10q7ufSNm8HIiKhDNDf5973uBv5iAJrr1Ohb1rTbdjycwKU AhBislrkpdJXj3tbEzbai3l9O5R3aL2vuQNizazfLzyTqOptxSBzT8BtNsnfYvPxT3YM ZQRvDq1CO/CTMn39imQ32dSvyerYwa53/x51LQ7S9hfovdY3lY5/1w10YQod6pZpLFqD h00ZmbagWjx/qMs8eqOSrZrVkgjjMp6siEWkEbJG6NJROQlN2unOtdXuJVLqPPjOR494 d+3cANALFvA7uc/tEBGQn0/v+dSSGZQuwKpSIRF28gv3OiBwlfYYHhex2BsCT5YztIEG vy5Q== X-Forwarded-Encrypted: i=1; AFNElJ8WkKTAde/d0DM+dBbUS6/kObwoNGNBfA0g5DuiclGi5GDm+r83rHSFGLijV9/RLXqy6BqvW3qaLTkIyHI=@vger.kernel.org X-Gm-Message-State: AOJu0YxaPGjqgwYWFId7P1gqSJx1/5yBzuChlxa+GLNYbMvaSoHgCu5t 8niBdBzbNG56u3LAlt7/c7Y4XbRuMa9ds+IJC/WTJL1De/59Xx8n2BpYMYzaWwrF2GkoRCOqZq1 fCSOVub56iHk51A== X-Received: from dlbtu17.prod.google.com ([2002:a05:7022:3c11:b0:137:e4cf:f531]) (user=cmllamas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701b:2403:b0:138:3613:db7 with SMTP id a92af1059eb24-13836130f1amr2334449c88.1.1781114937721; Wed, 10 Jun 2026 11:08:57 -0700 (PDT) Date: Wed, 10 Jun 2026 18:08:37 +0000 In-Reply-To: <20260610180841.3091635-1-cmllamas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260610180841.3091635-1-cmllamas@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260610180841.3091635-2-cmllamas@google.com> Subject: [PATCH 6.1.y 2/2] usb: gadget: u_ether: Fix NULL pointer deref in eth_get_drvinfo From: Carlos Llamas To: stable@vger.kernel.org Cc: Jianqiang kang , Neill Kapron , kernel-team@android.com, Kuen-Han Tsai , Val Packett , stable , Greg Kroah-Hartman , Carlos Llamas , Sasha Levin , "open list:USB SUBSYSTEM" , open list Content-Type: text/plain; charset="UTF-8" From: Kuen-Han Tsai [ Upstream commit e002e92e88e12457373ed096b18716d97e7bbb20 ] Commit ec35c1969650 ("usb: gadget: f_ncm: Fix net_device lifecycle with device_move") reparents the gadget device to /sys/devices/virtual during unbind, clearing the gadget pointer. If the userspace tool queries on the surviving interface during this detached window, this leads to a NULL pointer dereference. Unable to handle kernel NULL pointer dereference Call trace: eth_get_drvinfo+0x50/0x90 ethtool_get_drvinfo+0x5c/0x1f0 __dev_ethtool+0xaec/0x1fe0 dev_ethtool+0x134/0x2e0 dev_ioctl+0x338/0x560 Add a NULL check for dev->gadget in eth_get_drvinfo(). When detached, skip copying the fw_version and bus_info strings, which is natively handled by ethtool_get_drvinfo for empty strings. Suggested-by: Val Packett Reported-by: Val Packett Closes: https://lore.kernel.org/linux-usb/10890524-cf83-4a71-b879-93e2b2cc1fcc@packett.cool/ Fixes: ec35c1969650 ("usb: gadget: f_ncm: Fix net_device lifecycle with device_move") Cc: stable Signed-off-by: Kuen-Han Tsai Link: https://patch.msgid.link/20260316-eth-null-deref-v1-1-07005f33be85@google.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Carlos Llamas --- drivers/usb/gadget/function/u_ether.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index e972de236be5..83dfc5008b68 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -147,8 +147,10 @@ static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p) strscpy(p->driver, "g_ether", sizeof(p->driver)); strscpy(p->version, UETH__VERSION, sizeof(p->version)); - strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version)); - strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info)); + if (dev->gadget) { + strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version)); + strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info)); + } } /* REVISIT can also support: -- 2.54.0.1136.gdb2ca164c4-goog