Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2984894imu; Sun, 9 Dec 2018 14:18:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/V6d3dzjs4kX0Nk7Lybty2NGLkyztAx4B1h90Q3nzmqa3wngN7q2p1ee0e1YujHdwkRIdf6 X-Received: by 2002:a63:bd51:: with SMTP id d17mr8972506pgp.443.1544393909411; Sun, 09 Dec 2018 14:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393909; cv=none; d=google.com; s=arc-20160816; b=OqjdtxNOUVRObrX6efBo7uQQ42tJwov2Kiz8Fe4SoP8y37CJUuO+2GQD1ZOjUdhdtf Xf4Zk00lUbjysbIfsaK7072TjNRzDhjlwiJMv9DWLVNYB9unJfArGpawiiUEIeI5Lhhz d9SR9bi77b1fnyWdCZduC8FVbNts2H+oURgWb4WpJk78/E8elrPRFX9vExyvxzUyAEyQ qjLnkZS4Xq/jj/3y3TEBmJT08zCE74mc29afysmDIV7YfX6iIZt1MRphPCaVGZUtPSxF 6wGfoUu29Vs4HINaLngrpEGSJ/gYwur0mX3dKZINpVVEJbgTzj79jAWljZzItcyABWlN 4USA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=9zueeM0l5qJDslty/EamXubJu2DS3QUws1QfB2gZDjg=; b=OhENMfo1weKderucr2P7Nmwr4WgcPtHjn3av5aTY5nW9ZR3cWaiNwOo1DLwmrvYCus NeMfd1bLmFQg2pC1FaURk9XUdht6IyYYll9fcVMYSmeaiCY8zSLY7MQDT4BsOKYb6Fws 4kbvc41i8q7jlTOXp+fWAkWARSc+gc0Hg2JDf2GIFnZmLxeeBBo3RaxUoeUwPWEROlYq oosnXVmqIHrDAlDfM2mIN6NrhYkQHD2bZhYxfCTkVm+dFwWm/Mm9hNed+YM7geLM4V7G UjVOvUEgpnB/EhMJ82OOYjdKTD1CDmHrdthBfgorEceuitqt8uXA+L+Xfsf1O2BbQpWW BjPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n18si8961037pfj.30.2018.12.09.14.18.14; Sun, 09 Dec 2018 14:18:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727163AbeLIWRB (ORCPT + 99 others); Sun, 9 Dec 2018 17:17:01 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:37204 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727359AbeLIWHT (ORCPT ); Sun, 9 Dec 2018 17:07:19 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW73O-0002iZ-Jp; Sun, 09 Dec 2018 21:55:58 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72Z-0003G7-RF; Sun, 09 Dec 2018 21:55:07 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Greg Kroah-Hartman" , "Bjorn Helgaas" , "Lukas Wunner" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 050/328] PCI: hotplug: Don't leak pci_slot on registration failure In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Lukas Wunner commit 4ce6435820d1f1cc2c2788e232735eb244bcc8a3 upstream. If addition of sysfs files fails on registration of a hotplug slot, the struct pci_slot as well as the entry in the slot_list is leaked. The issue has been present since the hotplug core was introduced in 2002: https://git.kernel.org/tglx/history/c/a8a2069f432c Perhaps the idea was that even though sysfs addition fails, the slot should still be usable. But that's not how drivers use the interface, they abort probe if a non-zero value is returned. Signed-off-by: Lukas Wunner Signed-off-by: Bjorn Helgaas Cc: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/pci/hotplug/pci_hotplug_core.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -457,8 +457,17 @@ int __pci_hp_register(struct hotplug_slo list_add(&slot->slot_list, &pci_hotplug_slot_list); result = fs_add_slot(pci_slot); + if (result) + goto err_list_del; + kobject_uevent(&pci_slot->kobj, KOBJ_ADD); dbg("Added slot %s to the list\n", name); + goto out; + +err_list_del: + list_del(&slot->slot_list); + pci_slot->hotplug = NULL; + pci_destroy_slot(pci_slot); out: mutex_unlock(&pci_hp_mutex); return result;