From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (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 E1EDD358378 for ; Sat, 25 Jul 2026 10:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784974013; cv=none; b=SAaWmA+8W594cG5iFUKGizHC7FpqtP3C/TzO4Ile/LVup4erOzKElHC64kC9qsQYZ9d0nxV/83LF+NnRzjbmEpN74zbrbLRakZA7UN32CDm40hXSD/9/Q6V+ObKDhvlHQpUDMicLnVfrvMgiYPsx5SiN7eRrGTYNrnNUcvJhiSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784974013; c=relaxed/simple; bh=HqRcAEudUosAiH1k8QJ41Ox33wE0zPmsdCWEXpUVGPs=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=PPpN9+5wNcVZ0Qm59sfNWf0miGhpOw5GOrRbTMOHY1dRuGRqjNFu3o4eKCfrwW7YL7+SgWlE+vhDMVBi5qkwmYM8P1b0YMce8rsfc9Rb1UJS5j4vOQ45hxBpR1+s2QoxtJimEpSI8Ix7twXS70W176ph85z2T9uD85ghr8h8sy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.167.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-4a45b3f0bdfso1697135b6e.1 for ; Sat, 25 Jul 2026 03:06:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784974011; x=1785578811; h=content-type:to:from:subject:message-id:in-reply-to:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=LH+T03euz+B4vKMMv7U7Gq2wXHf1tw9PaNwtoyDkjk0=; b=ddjL71lvXH8UUIVV9Ecwb24NuEGTqcuMgEya7YruqvyiZb3K9cPMzxk4AxWpHyl+OC QEqbxZS5GQb0PY3bvl/vH8FBhZ7hmgQA9PmA5Vzo2Rz25xknN6eazN4+1d5ANGxWiRcq 0mo9oymOnbIHEhInoQt4hmylavfWhY0rd9GGEpYZ+6hyRpbvzAqeFHspz1Ik/X/JZlwq P73BZg8JYzSBeY0xN3zX0vxiv05bsA8L6QUjeqAQ9qIqdWoolZfSZT+Muxdd7bC6e5Zq ysKmam75slzX9kB7oyopvyaU8mBmL9CyE2YQYNTThnAlvQ8dB9grAJP67gtOZi/CVBA6 cI2A== X-Gm-Message-State: AOJu0YxYuz1Lu+dULQRsgta7LVGFTEdkTH6EBwDnmcXBLLUAYpigH68h ZO6uQaS+z1gTLwXZIq2tjU5VnbrIPdCnGQUkrbMQF4ZdXoLe+h7qYV4M6F6nRYdX5nTkGMOpQBE PgUpDKrD+jCiO+vFYn3z0L+T5JXBbL4kbJY+c+0dmQBRdB9Rmit11lOilxM4= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6808:3447:b0:495:db98:cd70 with SMTP id 5614622812f47-4ab6a269c18mr1569987b6e.35.1784974010813; Sat, 25 Jul 2026 03:06:50 -0700 (PDT) Date: Sat, 25 Jul 2026 03:06:50 -0700 In-Reply-To: <697018fc.050a0220.706b.0003.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a648aba.073198cf.94f0f.0013.GAE@google.com> Subject: Forwarded: [PATCH] PCI: Handle dev_set_name() failure in pci_setup_device() From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] PCI: Handle dev_set_name() failure in pci_setup_device() Author: rihyeon8648@gmail.com #syz test pci_setup_device() calls dev_set_name() but ignores its return value. dev_set_name() allocates the name with kvasprintf() and can fail, leaving dev->kobj.name NULL. Enumeration then continues with an unnamed device. device_add() rejects it with -EINVAL because dev_name() returns NULL and pci_bus_type has no ->dev_name callback, but pci_device_add() only WARNs about that failure: pci (null): [8086:2934] type 00 class 0x0c0300 conventional PCI endpoint pci (null): BAR 4 [io 0xc0e0-0xc0ff] ------------[ cut here ]------------ ret < 0 WARNING: drivers/pci/probe.c:2768 at pci_device_add+0x133b/0x1810 Call Trace: pci_scan_single_device+0x1d0/0x240 pci_scan_slot+0x1c9/0x7c0 pci_scan_child_bus_extend+0x6b/0x7b0 pci_rescan_bus+0x18/0x40 rescan_store+0xfb/0x130 The device was already put on bus->devices before device_add() ran and is not removed from it, so pci_bus_add_devices() later in the same pci_rescan_bus() call picks it up and hands it to __device_attach(), which dereferences dev->p. device_add() freed dev->p on its error path, so this is a NULL dereference: Oops: general protection fault, probably for non-canonical address ... KASAN: null-ptr-deref in range [0x0000000000000108-0x000000000000010f] RIP: 0010:__device_attach+0xb0/0x4d0 Call Trace: device_initial_probe+0xaf/0xd0 pci_bus_add_device+0xc5/0x100 pci_bus_add_devices+0x9a/0x1f0 pci_rescan_bus+0x2a/0x40 rescan_store+0xfb/0x130 Kernel panic - not syncing: Fatal exception Propagate the error instead. pci_setup_device() already returns int and both callers, pci_scan_device() and pci_iov_scan_device(), release the device on failure, so no caller changes are needed. Release the OF node first, matching the existing error path for an unknown header type. Reported-by: syzbot+87bb32e345aa80c0554b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=87bb32e345aa80c0554b Fixes: eebfcfb52ce7 ("PCI: handle pci_name() being const") Signed-off-by: Rihyeon Kim --- drivers/pci/probe.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index dd0abbc63e18..474c6cb327be 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2052,9 +2052,13 @@ int pci_setup_device(struct pci_dev *dev) */ dev->msi_addr_mask = DMA_BIT_MASK(64); - dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), - dev->bus->number, PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + err = dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", + pci_domain_nr(dev->bus), dev->bus->number, + PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); + if (err) { + pci_release_of_node(dev); + return err; + } class = pci_class(dev); -- 2.43.0