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,
	syzbot+d4503ae45b65c5bc1194@syzkaller.appspotmail.com,
	Takashi Iwai <tiwai@suse.de>
Subject: [PATCH 4.9 25/56] ALSA: pcm: Fix possible OOB access in PCM oss plugins
Date: Mon,  1 Apr 2019 19:02:41 +0200	[thread overview]
Message-ID: <20190401170105.339234260@linuxfoundation.org> (raw)
In-Reply-To: <20190401170103.398401360@linuxfoundation.org>

4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <tiwai@suse.de>

commit ca0214ee2802dd47239a4e39fb21c5b00ef61b22 upstream.

The PCM OSS emulation converts and transfers the data on the fly via
"plugins".  The data is converted over the dynamically allocated
buffer for each plugin, and recently syzkaller caught OOB in this
flow.

Although the bisection by syzbot pointed out to the commit
65766ee0bf7f ("ALSA: oss: Use kvzalloc() for local buffer
allocations"), this is merely a commit to replace vmalloc() with
kvmalloc(), hence it can't be the cause.  The further debug action
revealed that this happens in the case where a slave PCM doesn't
support only the stereo channels while the OSS stream is set up for a
mono channel.  Below is a brief explanation:

At each OSS parameter change, the driver sets up the PCM hw_params
again in snd_pcm_oss_change_params_lock().  This is also the place
where plugins are created and local buffers are allocated.  The
problem is that the plugins are created before the final hw_params is
determined.  Namely, two snd_pcm_hw_param_near() calls for setting the
period size and periods may influence on the final result of channels,
rates, etc, too, while the current code has already created plugins
beforehand with the premature values.  So, the plugin believes that
channels=1, while the actual I/O is with channels=2, which makes the
driver reading/writing over the allocated buffer size.

The fix is simply to move the plugin allocation code after the final
hw_params call.

Reported-by: syzbot+d4503ae45b65c5bc1194@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 sound/core/oss/pcm_oss.c |   43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -951,6 +951,28 @@ static int snd_pcm_oss_change_params_loc
 	oss_frame_size = snd_pcm_format_physical_width(params_format(params)) *
 			 params_channels(params) / 8;
 
+	err = snd_pcm_oss_period_size(substream, params, sparams);
+	if (err < 0)
+		goto failure;
+
+	n = snd_pcm_plug_slave_size(substream, runtime->oss.period_bytes / oss_frame_size);
+	err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, n, NULL);
+	if (err < 0)
+		goto failure;
+
+	err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIODS,
+				     runtime->oss.periods, NULL);
+	if (err < 0)
+		goto failure;
+
+	snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
+
+	err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_HW_PARAMS, sparams);
+	if (err < 0) {
+		pcm_dbg(substream->pcm, "HW_PARAMS failed: %i\n", err);
+		goto failure;
+	}
+
 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
 	snd_pcm_oss_plugin_clear(substream);
 	if (!direct) {
@@ -985,27 +1007,6 @@ static int snd_pcm_oss_change_params_loc
 	}
 #endif
 
-	err = snd_pcm_oss_period_size(substream, params, sparams);
-	if (err < 0)
-		goto failure;
-
-	n = snd_pcm_plug_slave_size(substream, runtime->oss.period_bytes / oss_frame_size);
-	err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, n, NULL);
-	if (err < 0)
-		goto failure;
-
-	err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIODS,
-				     runtime->oss.periods, NULL);
-	if (err < 0)
-		goto failure;
-
-	snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
-
-	if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_HW_PARAMS, sparams)) < 0) {
-		pcm_dbg(substream->pcm, "HW_PARAMS failed: %i\n", err);
-		goto failure;
-	}
-
 	if (runtime->oss.trigger) {
 		sw_params->start_threshold = 1;
 	} else {



  parent reply	other threads:[~2019-04-01 17:27 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 17:02 [PATCH 4.9 00/56] 4.9.167-stable review Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 01/56] Bluetooth: Check L2CAP option sizes returned from l2cap_get_conf_opt Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 02/56] Bluetooth: Verify that l2cap_get_conf_opt provides large enough buffer Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 03/56] video: fbdev: Set pixclock = 0 in goldfishfb Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 04/56] cfg80211: size various nl80211 messages correctly Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 05/56] stmmac: copy unicast mac address to MAC registers Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 06/56] dccp: do not use ipv6 header for ipv4 flow Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 07/56] mISDN: hfcpci: Test both vendor & device ID for Digium HFC4S Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 08/56] net/packet: Set __GFP_NOWARN upon allocation in alloc_pg_vec Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 09/56] net: rose: fix a possible stack overflow Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 10/56] packets: Always register packet sk in the same order Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 11/56] tcp: do not use ipv6 header for ipv4 flow Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 12/56] vxlan: Dont call gro_cells_destroy() before device is unregistered Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 13/56] sctp: get sctphdr by offset in sctp_compute_cksum Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 14/56] mac8390: Fix mmio access size probe Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 15/56] tun: properly test for IFF_UP Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 16/56] tun: add a missing rcu_read_unlock() in error path Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 17/56] btrfs: remove WARN_ON in log_dir_items Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 18/56] btrfs: raid56: properly unmap parity page in finish_parity_scrub() Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 19/56] ARM: imx6q: cpuidle: fix bug that CPU might not wake up at expected time Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 20/56] powerpc: bpf: Fix generation of load/store DW instructions Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 21/56] NFSv4.1 dont free interrupted slot on open Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 22/56] net: dsa: qca8k: remove leftover phy accessors Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 23/56] ALSA: rawmidi: Fix potential Spectre v1 vulnerability Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 24/56] ALSA: seq: oss: Fix " Greg Kroah-Hartman
2019-04-01 17:02 ` Greg Kroah-Hartman [this message]
2019-04-01 17:02 ` [PATCH 4.9 26/56] ALSA: pcm: Dont suspend stream in unrecoverable PCM state Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 27/56] fs/open.c: allow opening only regular files during execve() Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 28/56] scsi: sd: Fix a race between closing an sd device and sd I/O Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 29/56] scsi: sd: Quiesce warning if device does not report optimal I/O size Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 30/56] scsi: zfcp: fix rport unblock if deleted SCSI devices on Scsi_Host Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 31/56] scsi: zfcp: fix scsi_eh host reset with port_forced ERP for non-NPIV FCP devices Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 32/56] tty: atmel_serial: fix a potential NULL pointer dereference Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 33/56] staging: comedi: ni_mio_common: Fix divide-by-zero for DIO cmdtest Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 34/56] staging: vt6655: Remove vif check from vnt_interrupt Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 35/56] staging: vt6655: Fix interrupt race condition on device start up Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 36/56] serial: max310x: Fix to avoid potential NULL pointer dereference Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 37/56] serial: sh-sci: Fix setting SCSCR_TIE while transferring data Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 38/56] USB: serial: cp210x: add new device id Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 39/56] USB: serial: ftdi_sio: add additional NovaTech products Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 40/56] USB: serial: mos7720: fix mos_parport refcount imbalance on error path Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 41/56] USB: serial: option: set driver_info for SIM5218 and compatibles Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 42/56] USB: serial: option: add Olicard 600 Greg Kroah-Hartman
2019-04-01 17:02 ` [PATCH 4.9 43/56] Disable kgdboc failed by echo space to /sys/module/kgdboc/parameters/kgdboc Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 44/56] fs/proc/proc_sysctl.c: fix NULL pointer dereference in put_links Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 45/56] gpio: adnp: Fix testing wrong value in adnp_gpio_direction_input Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 46/56] usb: common: Consider only available nodes for dr_mode Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 47/56] usb: host: xhci-rcar: Add XHCI_TRUST_TX_LENGTH quirk Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 48/56] perf intel-pt: Fix TSC slip Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 49/56] cpu/hotplug: Prevent crash when CPU bringup fails on CONFIG_HOTPLUG_CPU=n Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 50/56] x86/smp: Enforce CONFIG_HOTPLUG_CPU when SMP=y Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 51/56] KVM: Reject device ioctls from processes other than the VMs creator Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 52/56] KVM: x86: Emulate MSR_IA32_ARCH_CAPABILITIES on AMD hosts Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 53/56] USB: gadget: f_hid: fix deadlock in f_hidg_write() Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 54/56] xhci: Fix port resume done detection for SS ports with LPM enabled Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 55/56] Revert "USB: core: only clean up what we allocated" Greg Kroah-Hartman
2019-04-01 17:03 ` [PATCH 4.9 56/56] arm64: support keyctl() system call in 32-bit mode Greg Kroah-Hartman
2019-04-01 21:03 ` [PATCH 4.9 00/56] 4.9.167-stable review kernelci.org bot
2019-04-02  3:01 ` Naresh Kamboju
2019-04-02  9:03 ` Jon Hunter
2019-04-02 19:04 ` Guenter Roeck
2019-04-02 23:54 ` shuah

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=20190401170105.339234260@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+d4503ae45b65c5bc1194@syzkaller.appspotmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).