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, Guenter Roeck <linux@roeck-us.net>,
	Jens Axboe <axboe@kernel.dk>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 3.18 029/104] cdrom: Fix race condition in cdrom_sysctl_register
Date: Wed, 24 Apr 2019 19:08:46 +0200	[thread overview]
Message-ID: <20190424170856.369343305@linuxfoundation.org> (raw)
In-Reply-To: <20190424170839.996641496@linuxfoundation.org>

[ Upstream commit f25191bb322dec8fa2979ecb8235643aa42470e1 ]

The following traceback is sometimes seen when booting an image in qemu:

[   54.608293] cdrom: Uniform CD-ROM driver Revision: 3.20
[   54.611085] Fusion MPT base driver 3.04.20
[   54.611877] Copyright (c) 1999-2008 LSI Corporation
[   54.616234] Fusion MPT SAS Host driver 3.04.20
[   54.635139] sysctl duplicate entry: /dev/cdrom//info
[   54.639578] CPU: 0 PID: 266 Comm: kworker/u4:5 Not tainted 5.0.0-rc5 #1
[   54.639578] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
[   54.641273] Workqueue: events_unbound async_run_entry_fn
[   54.641273] Call Trace:
[   54.641273]  dump_stack+0x67/0x90
[   54.641273]  __register_sysctl_table+0x50b/0x570
[   54.641273]  ? rcu_read_lock_sched_held+0x6f/0x80
[   54.641273]  ? kmem_cache_alloc_trace+0x1c7/0x1f0
[   54.646814]  __register_sysctl_paths+0x1c8/0x1f0
[   54.646814]  cdrom_sysctl_register.part.7+0xc/0x5f
[   54.646814]  register_cdrom.cold.24+0x2a/0x33
[   54.646814]  sr_probe+0x4bd/0x580
[   54.646814]  ? __driver_attach+0xd0/0xd0
[   54.646814]  really_probe+0xd6/0x260
[   54.646814]  ? __driver_attach+0xd0/0xd0
[   54.646814]  driver_probe_device+0x4a/0xb0
[   54.646814]  ? __driver_attach+0xd0/0xd0
[   54.646814]  bus_for_each_drv+0x73/0xc0
[   54.646814]  __device_attach+0xd6/0x130
[   54.646814]  bus_probe_device+0x9a/0xb0
[   54.646814]  device_add+0x40c/0x670
[   54.646814]  ? __pm_runtime_resume+0x4f/0x80
[   54.646814]  scsi_sysfs_add_sdev+0x81/0x290
[   54.646814]  scsi_probe_and_add_lun+0x888/0xc00
[   54.646814]  ? scsi_autopm_get_host+0x21/0x40
[   54.646814]  __scsi_add_device+0x116/0x130
[   54.646814]  ata_scsi_scan_host+0x93/0x1c0
[   54.646814]  async_run_entry_fn+0x34/0x100
[   54.646814]  process_one_work+0x237/0x5e0
[   54.646814]  worker_thread+0x37/0x380
[   54.646814]  ? rescuer_thread+0x360/0x360
[   54.646814]  kthread+0x118/0x130
[   54.646814]  ? kthread_create_on_node+0x60/0x60
[   54.646814]  ret_from_fork+0x3a/0x50

The only sensible explanation is that cdrom_sysctl_register() is called
twice, once from the module init function and once from register_cdrom().
cdrom_sysctl_register() is not mutex protected and may happily execute
twice if the second call is made before the first call is complete.

Use a static atomic to ensure that the function is executed exactly once.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/cdrom/cdrom.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 2bd91d4943e1..f4f93ca4bdad 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -265,6 +265,7 @@
 /* #define ERRLOGMASK (CD_WARNING|CD_OPEN|CD_COUNT_TRACKS|CD_CLOSE) */
 /* #define ERRLOGMASK (CD_WARNING|CD_REG_UNREG|CD_DO_IOCTL|CD_OPEN|CD_CLOSE|CD_COUNT_TRACKS) */
 
+#include <linux/atomic.h>
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/major.h>
@@ -3676,9 +3677,9 @@ static struct ctl_table_header *cdrom_sysctl_header;
 
 static void cdrom_sysctl_register(void)
 {
-	static int initialized;
+	static atomic_t initialized = ATOMIC_INIT(0);
 
-	if (initialized == 1)
+	if (!atomic_add_unless(&initialized, 1, 1))
 		return;
 
 	cdrom_sysctl_header = register_sysctl_table(cdrom_root_table);
@@ -3689,8 +3690,6 @@ static void cdrom_sysctl_register(void)
 	cdrom_sysctl_settings.debug = debug;
 	cdrom_sysctl_settings.lock = lockdoor;
 	cdrom_sysctl_settings.check = check_media_type;
-
-	initialized = 1;
 }
 
 static void cdrom_sysctl_unregister(void)
-- 
2.19.1




  parent reply	other threads:[~2019-04-24 18:10 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 17:08 [PATCH 3.18 000/104] 3.18.139-stable review Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 001/104] ext4: cleanup bh release code in ext4_ind_remove_space() Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 002/104] i2c: core-smbus: prevent stack corruption on read I2C_BLOCK_DATA Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 003/104] tracing: kdb: Fix ftdump to not sleep Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 004/104] sysctl: handle overflow for file-max Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 005/104] mm/cma.c: cma_declare_contiguous: correct err handling Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 006/104] mm/vmalloc.c: fix kernel BUG at mm/vmalloc.c:512! Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 007/104] mm/slab.c: kmemleak no scan alien caches Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 008/104] ocfs2: fix a panic problem caused by o2cb_ctl Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 009/104] cifs: use correct format characters Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 010/104] dm thin: add sanity checks to thin-pool and external snapshot creation Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 011/104] cifs: Fix NULL pointer dereference of devname Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 012/104] fs: fix guard_bio_eod to check for real EOD errors Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 013/104] tools lib traceevent: Fix buffer overflow in arg_eval Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 014/104] scsi: core: replace GFP_ATOMIC with GFP_KERNEL in scsi_scan.c Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 015/104] ARM: 8840/1: use a raw_spinlock_t in unwind Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 016/104] mmc: omap: fix the maximum timeout setting Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 017/104] e1000e: Fix -Wformat-truncation warnings Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 018/104] IB/mlx4: Increase the timeout for CM cache Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 019/104] scsi: megaraid_sas: return error when create DMA pool failed Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 020/104] SoC: imx-sgtl5000: add missing put_device() Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 021/104] leds: lp55xx: fix null deref on firmware load failure Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 022/104] kprobes: Prohibit probing on bsearch() Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 023/104] ARM: 8833/1: Ensure that NEON code always compiles with Clang Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 024/104] ALSA: PCM: check if ops are defined before suspending PCM Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 025/104] bcache: fix input overflow to cache set sysfs file io_error_halflife Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 026/104] bcache: fix input overflow to sequential_cutoff Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 027/104] bcache: improve sysfs_strtoul_clamp() Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 028/104] fbdev: fbmem: fix memory access if logo is bigger than the screen Greg Kroah-Hartman
2019-04-24 17:08 ` Greg Kroah-Hartman [this message]
2019-04-24 17:08 ` [PATCH 3.18 030/104] e1000e: fix cyclic resets at link up with active tx Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 031/104] locking/lockdep: Add debug_locks check in __lock_downgrade() Greg Kroah-Hartman
2019-04-24 17:30   ` Tetsuo Handa
2019-04-25  7:56     ` Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 032/104] tty: increase the default flip buffer limit to 2*640K Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 033/104] media: mt9m111: set initial frame size other than 0x0 Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 034/104] hwrng: virtio - Avoid repeated init of completion Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 035/104] hpet: Fix missing = character in the __setup() code of hpet_mmap_enable Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 036/104] dmaengine: imx-dma: fix warning comparison of distinct pointer types Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 037/104] media: s5p-jpeg: Check for fmt_ver_flag when doing fmt enumeration Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 038/104] wlcore: Fix memory leak in case wl12xx_fetch_firmware failure Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 039/104] x86/build: Mark per-CPU symbols as absolute explicitly for LLD Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 040/104] dmaengine: tegra: avoid overflow of byte tracking Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 041/104] drm/dp/mst: Configure no_stop_bit correctly for remote i2c xfers Greg Kroah-Hartman
2019-04-24 17:08 ` [PATCH 3.18 042/104] binfmt_elf: switch to new creds when switching to new mm Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 043/104] lib/string.c: implement a basic bcmp Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 044/104] tty: mark Siemens R3964 line discipline as BROKEN Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 045/104] tty: ldisc: add sysctl to prevent autoloading of ldiscs Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 046/104] openvswitch: fix flow actions reallocation Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 047/104] qmi_wwan: add Olicard 600 Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 048/104] sctp: initialize _pad of sockaddr_in before copying to user memory Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 049/104] netns: provide pure entropy for net_hash_mix() Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 050/104] net: ethtool: not call vzalloc for zero sized memory request Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 051/104] ip6_tunnel: Match to ARPHRD_TUNNEL6 for dev type Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 052/104] ALSA: seq: Fix OOB-reads from strlcpy Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 053/104] ASoC: fsl_esai: fix channel swap issue when stream starts Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 054/104] block: do not leak memory in bio_copy_user_iov() Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 055/104] arm64: futex: Fix FUTEX_WAKE_OP atomic ops with non-zero result value Greg Kroah-Hartman
2019-04-24 17:35   ` Nathan Chancellor
2019-04-25  7:51     ` Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 056/104] xen: Prevent buffer overflow in privcmd ioctl Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 057/104] sched/fair: Do not re-read ->h_load_next during hierarchical load calculation Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 058/104] xtensa: fix return_address Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 059/104] PCI: Add function 1 DMA alias quirk for Marvell 9170 SATA controller Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 060/104] string: drop __must_check from strscpy() and restore strscpy() usages in cgroup Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 061/104] perf/core: Restore mmap record type correctly Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 062/104] ext4: report real fs size after failed resize Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 063/104] ALSA: echoaudio: add a check for ioremap_nocache Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 064/104] ALSA: sb8: add a check for request_region Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 065/104] IB/mlx4: Fix race condition between catas error reset and aliasguid flows Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 066/104] mmc: davinci: remove extraneous __init annotation Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 067/104] ALSA: opl3: fix mismatch between snd_opl3_drum_switch definition and declaration Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 068/104] thermal/int340x_thermal: fix mode setting Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 069/104] tools/power turbostat: return the exit status of a command Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 070/104] perf top: Fix error handling in cmd_top() Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 071/104] perf tests: Fix a memory leak in test__perf_evsel__tp_sched_test() Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 072/104] x86/hpet: Prevent potential NULL pointer dereference Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 073/104] x86/cpu/cyrix: Use correct macros for Cyrix calls on Geode processors Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 074/104] iommu/vt-d: Check capability before disabling protected memory Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 075/104] fix incorrect error code mapping for OBJECTID_NOT_FOUND Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 076/104] rsi: improve kernel thread handling to fix kernel panic Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 077/104] 9p: do not trust pdu content for stat item size Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 078/104] 9p locks: add mount option for lock retry interval Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 079/104] serial: uartps: console_setup() cant be placed to init section Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 080/104] ARM: samsung: Limit SAMSUNG_PM_CHECK config option to non-Exynos platforms Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 081/104] ACPI / SBS: Fix GPE storm on recent MacBookPros Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 082/104] iommu/dmar: Fix buffer overflow during PCI bus notification Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 083/104] appletalk: Fix use-after-free in atalk_proc_exit Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 084/104] lib/div64.c: off by one in shift Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 085/104] include/linux/swap.h: use offsetof() instead of custom __swapoffset macro Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 086/104] inet: update the IP ID generation algorithm to higher standards Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 087/104] appletalk: Fix compile regression Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 088/104] crypto: crypto4xx - properly set IV after de- and encrypt Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 089/104] tpm/tpm_i2c_atmel: Return -E2BIG when the transfer is incomplete Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 090/104] bonding: fix event handling for stacked bonds Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 091/104] net: bridge: multicast: use rcu to access port list from br_multicast_start_querier Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 092/104] ipv4: recompile ip options in ipv4_link_failure Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 093/104] ipv4: ensure rcu_read_lock() in ipv4_link_failure() Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 094/104] tcp: tcp_grow_window() needs to respect tcp_space() Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 095/104] iio: ad_sigma_delta: select channel when reading register Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 096/104] iio: adc: at91: disable adc channel interrupt in timeout case Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 097/104] staging: comedi: vmk80xx: Fix use of uninitialized semaphore Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 098/104] staging: comedi: vmk80xx: Fix possible double-free of ->usb_rx_buf Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 099/104] staging: comedi: ni_usb6501: " Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 100/104] ALSA: core: Fix card races between register and disconnect Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 101/104] x86/kprobes: Verify stack frame on kretprobe Greg Kroah-Hartman
2019-04-24 17:09 ` [PATCH 3.18 102/104] kprobes: Fix error check when reusing optimized probes Greg Kroah-Hartman
2019-04-24 17:10 ` [PATCH 3.18 103/104] sched/fair: Limit sched_cfs_period_timer() loop to avoid hard lockup Greg Kroah-Hartman
2019-04-24 17:10 ` [PATCH 3.18 104/104] device_cgroup: fix RCU imbalance in error case Greg Kroah-Hartman
2019-04-24 21:45 ` [PATCH 3.18 000/104] 3.18.139-stable review kernelci.org bot
2019-04-25 16:23 ` shuah
2019-04-25 19:36 ` 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=20190424170856.369343305@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --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 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).