From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 341D01552FD for ; Sat, 21 Feb 2026 14:48:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771685333; cv=none; b=cQMPFBBWVGplNwLlTjXDfBHIYdHiDjvuYViIz/WPvkSUtr9PgrFke5iqVQ0DUPlbZnhQYIU7P9+ZuuhzmDQuuwxJxPc7w0x0mpFnvHwgbMRAW9TdtLOdOxg3ShMqv6c7gcN8pSZ2JwVT3gVECBN1TUYCpXkvs6WEMlcf75HKMtY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771685333; c=relaxed/simple; bh=TIW7di7W9B6L4rzU//z3c0xJPlQEQJg5QsLFlDFJjv0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=H22YdVD5enfBXgGds4JSelV8/k5tqNFHbhGZu9NTEfMwQnoDdO+fUsKAOlebLoa/UZytu4STRI2aw+bGbbad4nZDc5HjYZGivoJ5xT4lZtjBE+WprQpkCvgiZzuWmJ2geuuKSEKHGAfyXKUd/bSUrHO6hQW7LRWUfW0dnM7kjO4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--khtsai.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ci0WmNfF; arc=none smtp.client-ip=209.85.214.202 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--khtsai.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ci0WmNfF" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ab0b2e804cso36334845ad.3 for ; Sat, 21 Feb 2026 06:48:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771685331; x=1772290131; 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=gz+ZDGsHMTEG/Ms65NnPn5UMtTR5l/RI93OOKvh7syQ=; b=Ci0WmNfFG1mnAwc/0RO8a744/gOKqHKaBcrO3kjBwppylof0dDDwOR5lX0xyV6WYUB L1CFFGFq7AEmFD/wDxxeM+lTKfK5ResbnMLJyU6MkWsIK53eKiAeTpfwt6GCgjKKoZkr +c0xdo974BSo3jyP27lDHI87yKpW9JWCLHotkInnPRzvqtchQtxbAVPvriDUHAW8aqQo gJ7+3+ZstJf/87z9xu9zljA13ZH1wnxrmiOdGtTspjfHil9qQK2Exg3nomj+R+KP0Hd8 DdReMvmn/Qbw7TOQERKxYwkcmrdWrcgXOiSygNImfS75haoXG9nBdsy/dYEcsaZIzAS9 w82w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771685331; x=1772290131; 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=gz+ZDGsHMTEG/Ms65NnPn5UMtTR5l/RI93OOKvh7syQ=; b=T5NnGfraCXyaxAz6znLP2r1AhtoTI59NDQcVpxJo8nbNOxfvL6pFuMMbSNh0pOB2vL QI4TKgdnTZ92Zw7kLOmnZaD6KqDQaIxhLVythlMP6cZnnzkKGwGPb0s2r0S8r/F55PET z5n7YcpqXLQgM5V9Qd7NVHB2E2WFWD7mBzSN5t148K9smdJjBqwKy6+MAngFMUffkDfE kVljDCtLoqBKKTqDtJ0M84pdlFgCkh81KDFokru7yvrPo1cp8VT2f4RZZTablP/nWLhd jp6i7NzQ/7vo5urrmvp+SJegVdkPiXzP2Pzc8EyTu0PYA0IXtUT2iavvfgSgAaDwDB8q Dang== X-Forwarded-Encrypted: i=1; AJvYcCUAsixBpkEi9Feys2k9OR3DYJoS8vsMAf//u+PivPlC8GEiGZG0H8tJjlzyKdja/mrikJjwskc/6KxRs40=@vger.kernel.org X-Gm-Message-State: AOJu0YyDbxoa6YTiCn0eNiLrJsuDkQi5hCy04EFBXFyKNS1RW9LtkluS 3zDr3pe4P7KC3JBgVZx9KIC/gcJ+0AverQl3wUvzG3cR9PvbIgDkqU3Jki1w3rmWML5KGXZqry0 IKsL+HA== X-Received: from plv12.prod.google.com ([2002:a17:903:bcc:b0:2ad:5a23:794e]) (user=khtsai job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3bcb:b0:2a9:327f:aa2f with SMTP id d9443c01a7336-2ad7451256amr27135015ad.26.1771685331374; Sat, 21 Feb 2026 06:48:51 -0800 (PST) Date: Sat, 21 Feb 2026 22:48:15 +0800 In-Reply-To: <20260221-legacy-ncm-v2-0-dfb891d76507@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260221-legacy-ncm-v2-0-dfb891d76507@google.com> X-Developer-Key: i=khtsai@google.com; a=ed25519; pk=abA4Pw6dY2ZufSbSXW9mtp7xiv1AVPtgRhCFWJSEqLE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1771685327; l=2555; i=khtsai@google.com; s=20250916; h=from:subject:message-id; bh=TIW7di7W9B6L4rzU//z3c0xJPlQEQJg5QsLFlDFJjv0=; b=tT2ibPRmS7uKKQm5BH41kwejb6ZUF26AK2nvOFDZs6YaDsP8VT92urhA7PFfBNqiuoM62Q7LS A9Usc2eUI0YCx/s9FShl7a4IrvB8+jvW9V+rEpYN9brlUxx9xVd9jnu X-Mailer: b4 0.14.2 Message-ID: <20260221-legacy-ncm-v2-1-dfb891d76507@google.com> Subject: [PATCH v2 1/2] usb: legacy: ncm: Fix NPE in gncm_bind From: Kuen-Han Tsai To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kuen-Han Tsai , stable@kernel.org, kernel test robot Content-Type: text/plain; charset="utf-8" Commit 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with bind/unbind") deferred the allocation of the net_device. This change leads to a NULL pointer dereference in the legacy NCM driver as it attempts to access the net_device before it's fully instantiated. Store the provided qmult, host_addr, and dev_addr into the struct ncm_opts->net_opts during gncm_bind(). These values will be properly applied to the net_device when it is allocated and configured later in the binding process by the NCM function driver. Fixes: 56a512a9b410 ("usb: gadget: f_ncm: align net_device lifecycle with bind/unbind") Cc: stable@kernel.org Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202602181727.fd76c561-lkp@intel.com Signed-off-by: Kuen-Han Tsai --- drivers/usb/gadget/legacy/ncm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/legacy/ncm.c b/drivers/usb/gadget/legacy/ncm.c index 0f1b45e3abd1a1ead7b2776be10a2a5747960136..e8d5655340530aa38fde698f876e785122f0cce8 100644 --- a/drivers/usb/gadget/legacy/ncm.c +++ b/drivers/usb/gadget/legacy/ncm.c @@ -15,8 +15,10 @@ /* #define DEBUG */ /* #define VERBOSE_DEBUG */ +#include #include #include +#include #include #include "u_ether.h" @@ -129,6 +131,7 @@ static int gncm_bind(struct usb_composite_dev *cdev) struct usb_gadget *gadget = cdev->gadget; struct f_ncm_opts *ncm_opts; int status; + u8 mac[ETH_ALEN]; f_ncm_inst = usb_get_function_instance("ncm"); if (IS_ERR(f_ncm_inst)) @@ -136,11 +139,15 @@ static int gncm_bind(struct usb_composite_dev *cdev) ncm_opts = container_of(f_ncm_inst, struct f_ncm_opts, func_inst); - gether_set_qmult(ncm_opts->net, qmult); - if (!gether_set_host_addr(ncm_opts->net, host_addr)) + ncm_opts->net_opts.qmult = qmult; + if (host_addr && mac_pton(host_addr, mac)) { + memcpy(&ncm_opts->net_opts.host_mac, mac, ETH_ALEN); pr_info("using host ethernet address: %s", host_addr); - if (!gether_set_dev_addr(ncm_opts->net, dev_addr)) + } + if (dev_addr && mac_pton(dev_addr, mac)) { + memcpy(&ncm_opts->net_opts.dev_mac, mac, ETH_ALEN); pr_info("using self ethernet address: %s", dev_addr); + } /* Allocate string descriptor numbers ... note that string * contents can be overridden by the composite_dev glue. -- 2.53.0.345.g96ddfc5eaa-goog