Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1336781imm; Thu, 23 Aug 2018 01:03:20 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwsVI5OFW4GX4i7FUfBZyUAiwsYuvy5M279IPYPkHislh8hEXxj1B8tJyvvnQt2Af54dZH+ X-Received: by 2002:a63:1d64:: with SMTP id d36-v6mr18490141pgm.92.1535011400894; Thu, 23 Aug 2018 01:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535011400; cv=none; d=google.com; s=arc-20160816; b=ROEv9UGFi8FvFWexHqbVNDa2v4A0wMrse7BdUPYPUZmo3keXzpXN0PSiooM1v5akDY 4cNBvO217etxgK0LdU47x6vlRx4oXpf3UC819uwEkx0tC0Dv8Xo8WcZOmXJr1MKQzebD 5xR5qGhVns9soL7NxIySXlBurG8/2DuainBR1S9BWw3ZkaSSH2GPbcu8BUx0sbyE8LAy d2RtK6LW1gU+KUIEICZGp1dwGNbrIVg8FX1+IpvpzG/pVYw333fFgOmhPiddZLO48p73 MIVjyKDPjqgFPCfRVDKUDGmnQRgX4DxUA++dAZnOz4zK6X/3Bmh4k3lBIAmBW5Z92mSo e3BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=6IONFUPfJHJWeyONcUjpe+lKzzFFKh8PK7znPg9McVM=; b=MQHHjUM9wHZ5xXO6uC5+8RbNgqp0RKFIHgHrDSu8/bmNKvguyHySZ2P3fJZkfLg5oZ OKT2ec8QPrdEqOaWG/rOhgESaJoY7+jGdF2zDjKlW+8p2jfUngRTd0myPmzY9IR+yaau Efj/IP+QD3AApYCS9SBTkl45J72drNNBRZyhWhrmdZTb/w04hbByFVYUjUik+DnhhO+w Q84nfuOuajsDu9G7arFe1MpUabQt2pLSNxCozbgIne+GKF3Rz/7lD+B/8E6O10AZa+wa AhczY8x818unwRBpTBacUyWSk0/SGlMX4JSegt7QJpLcyWG75xqs/21tjz6hdWDdS3f1 ULvg== 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 s195-v6si3926756pgs.492.2018.08.23.01.03.05; Thu, 23 Aug 2018 01:03:20 -0700 (PDT) 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 S1728742AbeHWL3D (ORCPT + 99 others); Thu, 23 Aug 2018 07:29:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43810 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727285AbeHWL3C (ORCPT ); Thu, 23 Aug 2018 07:29:02 -0400 Received: from localhost (5355525A.cm-6-6b.dynamic.ziggo.nl [83.85.82.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6C077CAD; Thu, 23 Aug 2018 08:00:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Bjorn Helgaas , Greg Kroah-Hartman Subject: [PATCH 4.4 75/79] PCI: hotplug: Dont leak pci_slot on registration failure Date: Thu, 23 Aug 2018 09:53:51 +0200 Message-Id: <20180823074924.095094304@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180823074918.641878835@linuxfoundation.org> References: <20180823074918.641878835@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable 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: stable@vger.kernel.org # v2.4.15+ Cc: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- 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;