From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Takashi Iwai" <tiwai@suse.de>,
"Jaroslav Kysela" <perex@perex.cz>,
"Lars-Peter Clausen" <lars@metafoo.de>
Subject: [PATCH 3.2 084/125] ALSA: control: Fix replacing user controls
Date: Tue, 08 Jul 2014 20:01:50 +0100 [thread overview]
Message-ID: <lsq.1404846110.924949232@decadent.org.uk> (raw)
In-Reply-To: <lsq.1404846109.699842714@decadent.org.uk>
3.2.61-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lars-Peter Clausen <lars@metafoo.de>
commit 82262a46627bebb0febcc26664746c25cef08563 upstream.
There are two issues with the current implementation for replacing user
controls. The first is that the code does not check if the control is actually a
user control and neither does it check if the control is owned by the process
that tries to remove it. That allows userspace applications to remove arbitrary
controls, which can cause a user after free if a for example a driver does not
expect a control to be removed from under its feed.
The second issue is that on one hand when a control is replaced the
user_ctl_count limit is not checked and on the other hand the user_ctl_count is
increased (even though the number of user controls does not change). This allows
userspace, once the user_ctl_count limit as been reached, to repeatedly replace
a control until user_ctl_count overflows. Once that happens new controls can be
added effectively bypassing the user_ctl_count limit.
Both issues can be fixed by instead of open-coding the removal of the control
that is to be replaced to use snd_ctl_remove_user_ctl(). This function does
proper permission checks as well as decrements user_ctl_count after the control
has been removed.
Note that by using snd_ctl_remove_user_ctl() the check which returns -EBUSY at
beginning of the function if the control already exists is removed. This is not
a problem though since the check is quite useless, because the lock that is
protecting the control list is released between the check and before adding the
new control to the list, which means that it is possible that a different
control with the same settings is added to the list after the check. Luckily
there is another check that is done while holding the lock in snd_ctl_add(), so
we'll rely on that to make sure that the same control is not added twice.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
sound/core/control.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -1151,8 +1151,6 @@ static int snd_ctl_elem_add(struct snd_c
struct user_element *ue;
int idx, err;
- if (!replace && card->user_ctl_count >= MAX_USER_CONTROLS)
- return -ENOMEM;
if (info->count < 1)
return -EINVAL;
access = info->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
@@ -1161,21 +1159,16 @@ static int snd_ctl_elem_add(struct snd_c
SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE));
info->id.numid = 0;
memset(&kctl, 0, sizeof(kctl));
- down_write(&card->controls_rwsem);
- _kctl = snd_ctl_find_id(card, &info->id);
- err = 0;
- if (_kctl) {
- if (replace)
- err = snd_ctl_remove(card, _kctl);
- else
- err = -EBUSY;
- } else {
- if (replace)
- err = -ENOENT;
+
+ if (replace) {
+ err = snd_ctl_remove_user_ctl(file, &info->id);
+ if (err)
+ return err;
}
- up_write(&card->controls_rwsem);
- if (err < 0)
- return err;
+
+ if (card->user_ctl_count >= MAX_USER_CONTROLS)
+ return -ENOMEM;
+
memcpy(&kctl.id, &info->id, sizeof(info->id));
kctl.count = info->owner ? info->owner : 1;
access |= SNDRV_CTL_ELEM_ACCESS_USER;
next prev parent reply other threads:[~2014-07-08 19:01 UTC|newest]
Thread overview: 137+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-08 19:01 [PATCH 3.2 000/125] 3.2.61-rc1 review Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 066/125] idr: fix overflow bug during maximum ID calculation at maximum height Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 107/125] perf: Fix race in removing an event Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 101/125] recordmcount/MIPS: Fix possible incorrect mcount_loc table entries in modules Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 048/125] xhci: delete endpoints from bandwidth list before freeing whole device Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 093/125] lib/lzo: Rename lzo1x_decompress.c to lzo1x_decompress_safe.c Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 013/125] USB: Avoid runtime suspend loops for HCDs that can't handle suspend/resume Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 060/125] powerpc/serial: Use saner flags when creating legacy ports Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 069/125] Input: synaptics - fix resolution for manually provided min/max Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 080/125] rtmutex: Detect changes in the pi lock chain Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 096/125] x86_32, entry: Do syscall exit work on badsys (CVE-2014-4508) Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 078/125] mm: rmap: fix use-after-free in __put_anon_vma Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 110/125] netlink: rate-limit leftover bytes warning and print process name Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 099/125] mm: fix crashes from mbind() merging vmas Ben Hutchings
2014-07-08 20:45 ` Hugh Dickins
2014-07-08 21:26 ` Hugh Dickins
2014-07-09 1:53 ` Ben Hutchings
2014-07-09 5:58 ` Hugh Dickins
2014-07-08 19:01 ` [PATCH 3.2 103/125] target: Fix left-over se_lun->lun_sep pointer OOPs Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 075/125] powerpc: Don't setup CPUs with bad status Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 068/125] Input: elantech - don't set bit 1 of reg_10 when the no_hw_res quirk is set Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 125/125] skbuff: skb_segment: orphan frags before copying Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 114/125] mlx4_core: Stash PCI ID driver_data in mlx4_priv structure Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 004/125] UBIFS: fix an mmap and fsync race condition Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 025/125] USB: sierra: fix urb and memory leak in resume error path Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 021/125] ext4: fix wrong assert in ext4_mb_normalize_request() Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 083/125] ALSA: control: Protect user controls against concurrent access Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 009/125] reiserfs: drop vmtruncate Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 029/125] USB: usb_wwan: fix urb leak in write error path Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 082/125] USB: EHCI: avoid BIOS handover on the HASEE E200 Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 027/125] USB: sierra: fix remote wakeup Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 105/125] [SCSI] fix our current target reap infrastructure Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 088/125] Bluetooth: Fix check for connection encryption Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 094/125] lib/lzo: Update LZO compression to current upstream version Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 030/125] USB: usb_wwan: fix race between write and resume Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 005/125] Input: synaptics - add min/max quirk for the ThinkPad W540 Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 119/125] iommu/vt-d: Fix missing IOTLB flush in intel_iommu_unmap() Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 023/125] IB/ipath: Translate legacy diagpkt into newer extended diagpkt Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 116/125] target: Explicitly clear ramdisk_mcp backend pages Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 054/125] drm/radeon: fix typo in radeon_connector_is_dp12_capable() Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 032/125] USB: usb_wwan: fix urb leak at shutdown Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 046/125] mac80211: don't check netdev state for debugfs read/write Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 058/125] nfsd4: use recall_lock for delegation hashing Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 091/125] b43: fix frequency reported on G-PHY with /new/ firmware Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 042/125] usb: usbtest: fix unlink write error with pattern 1 Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 050/125] RDMA/cxgb4: Fix four byte info leak in c4iw_create_cq() Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 041/125] USB: serial: option: add support for Novatel E371 PCIe card Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 007/125] HID: core: fix validation of report id 0 Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 074/125] watchdog: ath79_wdt: avoid spurious restarts on AR934x Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 077/125] ALSA: hda - Add quirk for external mic on Lifebook U904 Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 086/125] ALSA: control: Handle numid overflow Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 014/125] ARM: 8051/1: put_user: fix possible data corruption in put_user Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 020/125] ext4: fix zeroing of page during writeback Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 057/125] ahci: Add Device ID for HighPoint RocketRaid 642L Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 062/125] iscsi-target: Reject mutual authentication with reflected CHAP_C Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 047/125] rtmutex: Fix deadlock detector for real Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 120/125] ARM: 8012/1: kdump: Avoid overflow when converting pfn to physaddr Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 118/125] [SCSI] megaraid: Use resource_size_t for PCI resources, not long Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 061/125] ALSA: hda/realtek - Add support of ALC891 codec Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 081/125] rtmutex: Plug slow unlock race Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 033/125] USB: usb_wwan: fix potential blocked I/O after resume Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 006/125] ACPI: Fix conflict between customized DSDT and DSDT local copy Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 056/125] drm/radeon: only apply hdmi bpc pll flags when encoder mode is hdmi Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 067/125] Input: elantech - deal with clickpads reporting right button events Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 100/125] drm: fix NULL pointer access by wrong ioctl Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 034/125] USB: cdc-acm: fix write and suspend race Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 026/125] USB: sierra: fix urb and memory leak on disconnect Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 079/125] rtmutex: Handle deadlock detection smarter Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 022/125] IB/qib: Fix port in pkey change event Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 124/125] skbuff: export skb_copy_ubufs Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 097/125] hugetlb: fix copy_hugetlb_page_range() to handle migration/hwpoisoned entry Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 055/125] drm/radeon/atom: fix dithering on certain panels Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 064/125] rtc: rtc-at91rm9200: fix infinite wait for ACKUPD irq Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 024/125] USB: sierra: fix AA deadlock in open error path Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 051/125] RDMA/cxgb4: Add missing padding at end of struct c4iw_create_cq_resp Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 053/125] UBIFS: Remove incorrect assertion in shrink_tnc() Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 111/125] net: tunnels - enable module autoloading Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 040/125] USB: ftdi_sio: add NovaTech OrionLXm product ID Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 008/125] IB/srp: Fix a sporadic crash triggered by cable pulling Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 092/125] tracing: Fix syscall_*regfunc() vs copy_process() race Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 087/125] ALSA: control: Make sure that id->index does not overflow Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 035/125] USB: cdc-acm: fix write and resume race Ben Hutchings
2014-07-08 19:01 ` Ben Hutchings [this message]
2014-07-08 19:01 ` [PATCH 3.2 071/125] Btrfs: fix double free in find_lock_delalloc_range Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 018/125] drm/i915: Only copy back the modified fields to userspace from execbuffer Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 085/125] ALSA: control: Don't access controls outside of protected regions Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 010/125] reiserfs: call truncate_setsize under tailpack mutex Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 036/125] USB: cdc-acm: fix broken runtime suspend Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 037/125] USB: cdc-acm: fix runtime PM for control messages Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 070/125] nfsd4: fix FREE_STATEID lockowner leak Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 012/125] matroxfb: perform a dummy read of M_STATUS Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 112/125] net: fix inet_getid() and ipv6_select_ident() bugs Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 038/125] USB: cdc-acm: fix potential urb leak and PM imbalance in write Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 106/125] [SCSI] dual scan thread bug fix Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 113/125] sctp: Fix sk_ack_backlog wrap-around problem Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 065/125] ptrace: fix fork event messages across pid namespaces Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 015/125] Input: synaptics - T540p - unify with other LEN0034 models Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 017/125] drm/i915: s/DRM_ERROR/DRM_DEBUG in i915_gem_execbuffer.c Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 115/125] net/mlx4_core: Preserve pci_dev_data after __mlx4_remove_one() Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 043/125] powerpc: Fix 64 bit builds with binutils 2.24 Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 059/125] mm: fix sleeping function warning from __put_anon_vma Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 122/125] ptrace,x86: force IRET path after a ptrace_stop() Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 044/125] md: always set MD_RECOVERY_INTR when aborting a reshape or other "resync" Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 076/125] evm: prohibit userspace writing 'security.evm' HMAC value Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 001/125] mm: highmem: don't treat PKMAP_ADDR(LAST_PKMAP) as a highmem address Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 028/125] USB: option: fix runtime PM handling Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 121/125] Documentation: Update stable address in Chinese and Japanese translations Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 039/125] USB: io_ti: fix firmware download on big-endian machines (part 2) Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 117/125] [SCSI] Fix spurious request sense in error handling Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 108/125] MIPS: Cleanup flags in syscall flags handlers Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 052/125] nfsd: getattr for FATTR4_WORD0_FILES_AVAIL needs the statfs buffer Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 123/125] skbuff: add an api to orphan frags Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 073/125] auditsc: audit_krule mask accesses need bounds checking Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 011/125] ARM: imx: fix error handling in ipu device registration Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 003/125] genirq: Sanitize spurious interrupt detection of threaded irqs Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 045/125] s390/lowcore: reserve 96 bytes for IRB in lowcore Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 031/125] USB: usb_wwan: fix write and suspend race Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 109/125] MIPS: asm: thread_info: Add _TIF_SECCOMP flag Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 089/125] Bluetooth: Fix SSP acceptor just-works confirmation without MITM Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 098/125] mm: revert 0def08e3 ("mm/mempolicy.c: check return code of check_range") Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 104/125] [SCSI] Stop accepting SCSI requests before removing a device Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 095/125] lzo: properly check for overruns Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 090/125] rt2x00: disable TKIP on USB Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 049/125] IB/umad: Fix error handling Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 102/125] MIPS: MSC: Prevent out-of-bounds writes to MIPS SC ioremap'd region Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 019/125] ahci: add PCI ID for Marvell 88SE91A0 SATA Controller Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 072/125] drm/radeon: stop poisoning the GART TLB Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 063/125] mm: vmscan: clear kswapd's special reclaim powers before exiting Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 016/125] mac80211: fix IBSS join by initializing last_scan_completed Ben Hutchings
2014-07-08 19:01 ` [PATCH 3.2 002/125] bluetooth: hci_ldisc: fix deadlock condition Ben Hutchings
2014-07-08 20:12 ` [PATCH 3.2 000/125] 3.2.61-rc1 review Guenter Roeck
2014-07-09 1:27 ` Guenter Roeck
2014-07-09 2:01 ` Ben Hutchings
2014-07-09 11:53 ` Satoru Takeuchi
2014-07-09 21:30 ` Ben Hutchings
2014-07-09 2:40 ` Ben Hutchings
2014-07-09 3:13 ` 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=lsq.1404846110.924949232@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=lars@metafoo.de \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.de \
/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