All of lore.kernel.org
 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,
	Vasant Hegde <hegdevasant@linux.vnet.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.4 076/112] powerpc/powernv/dump: Fix race while processing OPAL dump
Date: Tue, 27 Oct 2020 14:49:46 +0100	[thread overview]
Message-ID: <20201027134904.153332418@linuxfoundation.org> (raw)
In-Reply-To: <20201027134900.532249571@linuxfoundation.org>

From: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>

[ Upstream commit 0a43ae3e2beb77e3481d812834d33abe270768ab ]

Every dump reported by OPAL is exported to userspace through a sysfs
interface and notified using kobject_uevent(). The userspace daemon
(opal_errd) then reads the dump and acknowledges that the dump is
saved safely to disk. Once acknowledged the kernel removes the
respective sysfs file entry causing respective resources to be
released including kobject.

However it's possible the userspace daemon may already be scanning
dump entries when a new sysfs dump entry is created by the kernel.
User daemon may read this new entry and ack it even before kernel can
notify userspace about it through kobject_uevent() call. If that
happens then we have a potential race between
dump_ack_store->kobject_put() and kobject_uevent which can lead to
use-after-free of a kernfs object resulting in a kernel crash.

This patch fixes this race by protecting the sysfs file
creation/notification by holding a reference count on kobject until we
safely send kobject_uevent().

The function create_dump_obj() returns the dump object which if used
by caller function will end up in use-after-free problem again.
However, the return value of create_dump_obj() function isn't being
used today and there is no need as well. Hence change it to return
void to make this fix complete.

Fixes: c7e64b9ce04a ("powerpc/powernv Platform dump interface")
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201017164210.264619-1-hegdevasant@linux.vnet.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/powerpc/platforms/powernv/opal-dump.c | 41 +++++++++++++++-------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-dump.c b/arch/powerpc/platforms/powernv/opal-dump.c
index 4c827826c05eb..e21e2c0af69d2 100644
--- a/arch/powerpc/platforms/powernv/opal-dump.c
+++ b/arch/powerpc/platforms/powernv/opal-dump.c
@@ -319,15 +319,14 @@ static ssize_t dump_attr_read(struct file *filep, struct kobject *kobj,
 	return count;
 }
 
-static struct dump_obj *create_dump_obj(uint32_t id, size_t size,
-					uint32_t type)
+static void create_dump_obj(uint32_t id, size_t size, uint32_t type)
 {
 	struct dump_obj *dump;
 	int rc;
 
 	dump = kzalloc(sizeof(*dump), GFP_KERNEL);
 	if (!dump)
-		return NULL;
+		return;
 
 	dump->kobj.kset = dump_kset;
 
@@ -347,21 +346,39 @@ static struct dump_obj *create_dump_obj(uint32_t id, size_t size,
 	rc = kobject_add(&dump->kobj, NULL, "0x%x-0x%x", type, id);
 	if (rc) {
 		kobject_put(&dump->kobj);
-		return NULL;
+		return;
 	}
 
+	/*
+	 * As soon as the sysfs file for this dump is created/activated there is
+	 * a chance the opal_errd daemon (or any userspace) might read and
+	 * acknowledge the dump before kobject_uevent() is called. If that
+	 * happens then there is a potential race between
+	 * dump_ack_store->kobject_put() and kobject_uevent() which leads to a
+	 * use-after-free of a kernfs object resulting in a kernel crash.
+	 *
+	 * To avoid that, we need to take a reference on behalf of the bin file,
+	 * so that our reference remains valid while we call kobject_uevent().
+	 * We then drop our reference before exiting the function, leaving the
+	 * bin file to drop the last reference (if it hasn't already).
+	 */
+
+	/* Take a reference for the bin file */
+	kobject_get(&dump->kobj);
 	rc = sysfs_create_bin_file(&dump->kobj, &dump->dump_attr);
-	if (rc) {
+	if (rc == 0) {
+		kobject_uevent(&dump->kobj, KOBJ_ADD);
+
+		pr_info("%s: New platform dump. ID = 0x%x Size %u\n",
+			__func__, dump->id, dump->size);
+	} else {
+		/* Drop reference count taken for bin file */
 		kobject_put(&dump->kobj);
-		return NULL;
 	}
 
-	pr_info("%s: New platform dump. ID = 0x%x Size %u\n",
-		__func__, dump->id, dump->size);
-
-	kobject_uevent(&dump->kobj, KOBJ_ADD);
-
-	return dump;
+	/* Drop our reference */
+	kobject_put(&dump->kobj);
+	return;
 }
 
 static irqreturn_t process_dump(int irq, void *data)
-- 
2.25.1




  parent reply	other threads:[~2020-10-27 14:06 UTC|newest]

Thread overview: 119+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27 13:48 [PATCH 4.4 000/112] 4.4.241-rc1 review Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 001/112] ibmveth: Identify ingress large send packets Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 002/112] tipc: fix the skb_unshare() in tipc_buf_append() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 003/112] net/ipv4: always honour route mtu during forwarding Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 004/112] r8169: fix data corruption issue on RTL8402 Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 005/112] ALSA: bebob: potential info leak in hwdep_read() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 006/112] mm/kasan: print name of mem[set,cpy,move]() caller in report Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 007/112] mm/kasan: add API to check memory regions Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 008/112] compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 009/112] compiler.h: Add read_word_at_a_time() function Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 010/112] lib/strscpy: Shut up KASAN false-positives in strscpy() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 011/112] x86/mm/ptdump: Fix soft lockup in page table walker Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 012/112] net: hdlc: In hdlc_rcv, check to make sure dev is an HDLC device Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 013/112] net: hdlc_raw_eth: Clear the IFF_TX_SKB_SHARING flag after calling ether_setup Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 014/112] nfc: Ensure presence of NFC_ATTR_FIRMWARE_NAME attribute in nfc_genl_fw_download() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 015/112] tcp: fix to update snd_wl1 in bulk receiver fast path Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 016/112] icmp: randomize the global rate limiter Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 017/112] cifs: remove bogus debug code Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 018/112] ima: Dont ignore errors from crypto_shash_update() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 019/112] EDAC/i5100: Fix error handling order in i5100_init_one() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 020/112] crypto: ixp4xx - Fix the size used in a dma_free_coherent() call Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 021/112] media: Revert "media: exynos4-is: Add missed check for pinctrl_lookup_state()" Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 022/112] media: m5mols: Check function pointer in m5mols_sensor_power Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 023/112] media: omap3isp: Fix memleak in isp_probe Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 024/112] crypto: omap-sham - fix digcnt register handling with export/import Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 025/112] media: tc358743: initialize variable Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 026/112] media: ti-vpe: Fix a missing check and reference count leak Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 027/112] ath6kl: prevent potential array overflow in ath6kl_add_new_sta() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 028/112] ath9k: Fix potential out of bounds in ath9k_htc_txcompletion_cb() Greg Kroah-Hartman
2020-10-27 13:48 ` [PATCH 4.4 029/112] wcn36xx: Fix reported 802.11n rx_highest rate wcn3660/wcn3680 Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 030/112] mwifiex: Do not use GFP_KERNEL in atomic context Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 031/112] drm/gma500: fix error check Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 032/112] scsi: qla4xxx: Fix an error handling path in qla4xxx_get_host_stats() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 033/112] scsi: csiostor: Fix wrong return value in csio_hw_prep_fw() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 034/112] backlight: sky81452-backlight: Fix refcount imbalance on error Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 035/112] VMCI: check return value of get_user_pages_fast() for errors Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 036/112] tty: serial: earlycon dependency Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 037/112] tty: hvcs: Dont NULL tty->driver_data until hvcs_cleanup() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 038/112] pty: do tty_flip_buffer_push without port->lock in pty_write Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 039/112] drivers/virt/fsl_hypervisor: Fix error handling path Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 040/112] video: fbdev: vga16fb: fix setting of pixclock because a pass-by-value error Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 041/112] video: fbdev: sis: fix null ptr dereference Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 042/112] HID: roccat: add bounds checking in kone_sysfs_write_settings() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 043/112] ath6kl: wmi: prevent a shift wrapping bug in ath6kl_wmi_delete_pstream_cmd() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 044/112] misc: mic: scif: Fix error handling path Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 045/112] ALSA: seq: oss: Avoid mutex lock for a long-time ioctl Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 046/112] quota: clear padding in v2r1_mem2diskdqb() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 047/112] net: enic: Cure the enic api locking trainwreck Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 048/112] mfd: sm501: Fix leaks in probe() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 049/112] usb: gadget: u_ether: enable qmult on SuperSpeed Plus as well Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 050/112] nl80211: fix non-split wiphy information Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 051/112] mwifiex: fix double free Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 052/112] net: korina: fix kfree of rx/tx descriptor array Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 053/112] IB/mlx4: Adjust delayed work when a dup is observed Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 054/112] powerpc/pseries: Fix missing of_node_put() in rng_init() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 055/112] powerpc/icp-hv: Fix missing of_node_put() in success path Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 056/112] mtd: lpddr: fix excessive stack usage with clang Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 057/112] mtd: mtdoops: Dont write panic data twice Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 058/112] ARM: 9007/1: l2c: fix prefetch bits init in L2X0_AUX_CTRL using DT values Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 059/112] powerpc/tau: Use appropriate temperature sample interval Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 060/112] powerpc/tau: Remove duplicated set_thresholds() call Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 061/112] powerpc/tau: Disable TAU between measurements Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 062/112] perf intel-pt: Fix "context_switch event has no tid" error Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 063/112] kdb: Fix pager search for multi-line strings Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 064/112] powerpc/perf/hv-gpci: Fix starting index value Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 065/112] cpufreq: powernv: Fix frame-size-overflow in powernv_cpufreq_reboot_notifier Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 066/112] lib/crc32.c: fix trivial typo in preprocessor condition Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 067/112] vfio/pci: Clear token on bypass registration failure Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 068/112] Input: imx6ul_tsc - clean up some errors in imx6ul_tsc_resume() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 069/112] Input: ep93xx_keypad - fix handling of platform_get_irq() error Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 070/112] Input: omap4-keypad " Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 071/112] Input: sun4i-ps2 " Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 072/112] KVM: x86: emulating RDPID failure shall return #UD rather than #GP Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 073/112] memory: omap-gpmc: Fix a couple off by ones Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 074/112] memory: fsl-corenet-cf: Fix handling of platform_get_irq() error Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 075/112] arm64: dts: zynqmp: Remove additional compatible string for i2c IPs Greg Kroah-Hartman
2020-10-27 13:49 ` Greg Kroah-Hartman [this message]
2020-10-27 13:49 ` [PATCH 4.4 077/112] media: firewire: fix memory leak Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 078/112] media: ati_remote: sanity check for both endpoints Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 079/112] media: exynos4-is: Fix several reference count leaks due to pm_runtime_get_sync Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 080/112] media: exynos4-is: Fix a reference count leak " Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 081/112] media: exynos4-is: Fix a reference count leak Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 082/112] media: bdisp: Fix runtime PM imbalance on error Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 083/112] media: media/pci: prevent memory leak in bttv_probe Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 084/112] media: uvcvideo: Ensure all probed info is returned to v4l2 Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 085/112] mmc: sdio: Check for CISTPL_VERS_1 buffer size Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 086/112] media: saa7134: avoid a shift overflow Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 087/112] ntfs: add check for mft record size in superblock Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 088/112] PM: hibernate: remove the bogus call to get_gendisk() in software_resume() Greg Kroah-Hartman
2020-10-27 13:49 ` [PATCH 4.4 089/112] scsi: mvumi: Fix error return in mvumi_io_attach() Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 090/112] scsi: target: core: Add CONTROL field for trace events Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 091/112] usb: gadget: function: printer: fix use-after-free in __lock_acquire Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 092/112] udf: Limit sparing table size Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 093/112] udf: Avoid accessing uninitialized data on failed inode read Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 094/112] ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs() Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 095/112] misc: rtsx: Fix memory leak in rtsx_pci_probe Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 096/112] reiserfs: only call unlock_new_inode() if I_NEW Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 097/112] xfs: make sure the rt allocator doesnt run off the end Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 098/112] usb: ohci: Default to per-port over-current protection Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 099/112] Bluetooth: Only mark socket zapped after unlocking Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 100/112] scsi: ibmvfc: Fix error return in ibmvfc_probe() Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 101/112] brcmsmac: fix memory leak in wlc_phy_attach_lcnphy Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 102/112] rtl8xxxu: prevent potential memory leak Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 103/112] Fix use after free in get_capset_info callback Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 104/112] tty: ipwireless: fix error handling Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 105/112] ipvs: Fix uninit-value in do_ip_vs_set_ctl() Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 106/112] reiserfs: Fix memory leak in reiserfs_parse_options() Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 107/112] brcm80211: fix possible memleak in brcmf_proto_msgbuf_attach Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 108/112] usb: core: Solve race condition in anchor cleanup functions Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 109/112] ath10k: check idx validity in __ath10k_htt_rx_ring_fill_n() Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 110/112] net: korina: cast KSEG0 address to pointer in kfree Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 111/112] usb: cdc-acm: add quirk to blacklist ETAS ES58X devices Greg Kroah-Hartman
2020-10-27 13:50 ` [PATCH 4.4 112/112] USB: cdc-wdm: Make wdm_flush() interruptible and add wdm_fsync() Greg Kroah-Hartman
2020-10-28 13:50 ` [PATCH 4.4 000/112] 4.4.241-rc1 review Naresh Kamboju
2020-10-28 15:54 ` Pavel Machek
2020-10-28 19:28 ` Jon Hunter
     [not found] ` <20201028170621.GA118534@roeck-us.net>
2020-10-28 19:46   ` Guenter Roeck
2020-10-28 20:33     ` Daniel Díaz
2020-10-28 20:47       ` Guenter Roeck

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=20201027134904.153332418@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=hegdevasant@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.