linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Qiushi Wu <wu000273@umn.edu>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Subject: [PATCH 4.14 26/42] firmware: Fix a reference count leak.
Date: Mon,  7 Mar 2022 10:19:00 +0100	[thread overview]
Message-ID: <20220307091636.913759960@linuxfoundation.org> (raw)
In-Reply-To: <20220307091636.146155347@linuxfoundation.org>

From: Qiushi Wu <wu000273@umn.edu>

commit fe3c60684377d5ad9b0569b87ed3e26e12c8173b upstream.

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object.
Callback function fw_cfg_sysfs_release_entry() in kobject_put()
can handle the pointer "entry" properly.

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Link: https://lore.kernel.org/r/20200613190533.15712-1-wu000273@umn.edu
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
[sudip: adjust context]
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/firmware/qemu_fw_cfg.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -461,8 +461,10 @@ static int fw_cfg_register_file(const st
 	/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
 	err = kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype,
 				   fw_cfg_sel_ko, "%d", entry->f.select);
-	if (err)
-		goto err_register;
+	if (err) {
+		kobject_put(&entry->kobj);
+		return err;
+	}
 
 	/* add raw binary content access */
 	err = sysfs_create_bin_file(&entry->kobj, &fw_cfg_sysfs_attr_raw);
@@ -478,7 +480,6 @@ static int fw_cfg_register_file(const st
 
 err_add_raw:
 	kobject_del(&entry->kobj);
-err_register:
 	kfree(entry);
 	return err;
 }



  parent reply	other threads:[~2022-03-07  9:25 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07  9:18 [PATCH 4.14 00/42] 4.14.270-rc1 review Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 01/42] mac80211_hwsim: report NOACK frames in tx_status Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 02/42] mac80211_hwsim: initialize ieee80211_tx_info at hw_scan_work Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 03/42] i2c: bcm2835: Avoid clock stretching timeouts Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 04/42] Input: clear BTN_RIGHT/MIDDLE on buttonpads Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 05/42] cifs: fix double free race when mount fails in cifs_get_root() Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 06/42] dmaengine: shdma: Fix runtime PM imbalance on error Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 07/42] i2c: cadence: allow COMPILE_TEST Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 08/42] i2c: qup: " Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 09/42] net: usb: cdc_mbim: avoid altsetting toggling for Telit FN990 Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 10/42] usb: gadget: dont release an existing dev->buf Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 11/42] usb: gadget: clear related members when goto fail Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 12/42] ata: pata_hpt37x: fix PCI clock detection Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 13/42] ALSA: intel_hdmi: Fix reference to PCM buffer address Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 14/42] ASoC: ops: Shift tested values in snd_soc_put_volsw() by +min Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 15/42] xfrm: fix MTU regression Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 16/42] netfilter: fix use-after-free in __nf_register_net_hook() Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 17/42] xfrm: enforce validity of offload input flags Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 18/42] netfilter: nf_queue: dont assume sk is full socket Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 19/42] netfilter: nf_queue: fix possible use-after-free Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 20/42] batman-adv: Request iflink once in batadv-on-batadv check Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 21/42] batman-adv: Request iflink once in batadv_get_real_netdevice Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 22/42] batman-adv: Dont expect inter-netns unique iflink indices Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 23/42] net: dcb: flush lingering app table entries for unregistered devices Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 24/42] net/smc: fix unexpected SMC_CLC_DECL_ERR_REGRMB error generated by client Greg Kroah-Hartman
2022-03-07  9:18 ` [PATCH 4.14 25/42] net/smc: fix unexpected SMC_CLC_DECL_ERR_REGRMB error cause by server Greg Kroah-Hartman
2022-03-07  9:19 ` Greg Kroah-Hartman [this message]
2022-03-07  9:19 ` [PATCH 4.14 27/42] firmware: qemu_fw_cfg: fix kobject leak in probe error path Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 28/42] mac80211: fix forwarded mesh frames AC & queue selection Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 29/42] net: stmmac: fix return value of __setup handler Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 30/42] net: sxgbe: " Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 31/42] net: arcnet: com20020: Fix null-ptr-deref in com20020pci_probe() Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 32/42] efivars: Respect "block" flag in efivar_entry_set_safe() Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 33/42] can: gs_usb: change active_channelss type from atomic_t to u8 Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 34/42] ARM: 9182/1: mmu: fix returns from early_param() and __setup() functions Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 35/42] soc: fsl: qe: Check of ioremap return value Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 36/42] net: chelsio: cxgb3: check the return value of pci_find_capability() Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 37/42] nl80211: Handle nla_memdup failures in handle_nan_filter Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 38/42] Input: elan_i2c - move regulator_[en|dis]able() out of elan_[en|dis]able_power() Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 39/42] Input: elan_i2c - fix regulator enable count imbalance after suspend/resume Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 40/42] HID: add mapping for KEY_ALL_APPLICATIONS Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 41/42] memfd: fix F_SEAL_WRITE after shmem huge page allocated Greg Kroah-Hartman
2022-03-07  9:19 ` [PATCH 4.14 42/42] net: dcb: disable softirqs in dcbnl_flush_dev() Greg Kroah-Hartman
2022-03-08 17:17 ` [PATCH 4.14 00/42] 4.14.270-rc1 review Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220307091636.913759960@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=sudipm.mukherjee@gmail.com \
    --cc=wu000273@umn.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).