linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Levin, Alexander (Sasha Levin)" <alexander.levin@one.verizon.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Takashi Iwai <tiwai@suse.de>,
	"Levin,
	Alexander (Sasha Levin)" <alexander.levin@one.verizon.com>
Subject: [PATCH AUTOSEL for-4.4 23/39] ALSA: vx: Fix possible transfer overflow
Date: Wed, 8 Nov 2017 20:50:39 +0000	[thread overview]
Message-ID: <20171108205027.27525-23-alexander.levin@verizon.com> (raw)
In-Reply-To: <20171108205027.27525-1-alexander.levin@verizon.com>

From: Takashi Iwai <tiwai@suse.de>

[ Upstream commit 874e1f6fad9a5184b67f4cee37c1335cd2cc5677 ]

The pseudo DMA transfer codes in VX222 and VX-pocket driver have a
slight bug where they check the buffer boundary wrongly, and may
overflow.  Also, the zero sample count might be handled badly for the
playback (although it shouldn't happen in theory).  This patch
addresses these issues.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=141541
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
 sound/drivers/vx/vx_pcm.c   |  6 ++++--
 sound/pci/vx222/vx222_ops.c | 12 ++++++------
 sound/pcmcia/vx/vxp_ops.c   | 12 ++++++------
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/sound/drivers/vx/vx_pcm.c b/sound/drivers/vx/vx_pcm.c
index 69f252585780..ea7b377f0378 100644
--- a/sound/drivers/vx/vx_pcm.c
+++ b/sound/drivers/vx/vx_pcm.c
@@ -1048,8 +1048,10 @@ static void vx_pcm_capture_update(struct vx_core *chip, struct snd_pcm_substream
 		/* ok, let's accelerate! */
 		int align = pipe->align * 3;
 		space = (count / align) * align;
-		vx_pseudo_dma_read(chip, runtime, pipe, space);
-		count -= space;
+		if (space > 0) {
+			vx_pseudo_dma_read(chip, runtime, pipe, space);
+			count -= space;
+		}
 	}
 	/* read the rest of bytes */
 	while (count > 0) {
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c
index af83b3b38052..8e457ea27f89 100644
--- a/sound/pci/vx222/vx222_ops.c
+++ b/sound/pci/vx222/vx222_ops.c
@@ -269,12 +269,12 @@ static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 
 	/* Transfer using pseudo-dma.
 	 */
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 2; /* in 32bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0) {
+		for (; length > 0; length--) {
 			outl(cpu_to_le32(*addr), port);
 			addr++;
 		}
@@ -284,7 +284,7 @@ static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 	pipe->hw_ptr += count;
 	count >>= 2; /* in 32bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 0) {
+	for (; count > 0; count--) {
 		outl(cpu_to_le32(*addr), port);
 		addr++;
 	}
@@ -307,12 +307,12 @@ static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 	vx2_setup_pseudo_dma(chip, 0);
 	/* Transfer using pseudo-dma.
 	 */
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 2; /* in 32bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0)
+		for (; length > 0; length--)
 			*addr++ = le32_to_cpu(inl(port));
 		addr = (u32 *)runtime->dma_area;
 		pipe->hw_ptr = 0;
@@ -320,7 +320,7 @@ static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 	pipe->hw_ptr += count;
 	count >>= 2; /* in 32bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 0)
+	for (; count > 0; count--)
 		*addr++ = le32_to_cpu(inl(port));
 
 	vx2_release_pseudo_dma(chip);
diff --git a/sound/pcmcia/vx/vxp_ops.c b/sound/pcmcia/vx/vxp_ops.c
index 281972913c32..56aa1ba73ccc 100644
--- a/sound/pcmcia/vx/vxp_ops.c
+++ b/sound/pcmcia/vx/vxp_ops.c
@@ -369,12 +369,12 @@ static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 	unsigned short *addr = (unsigned short *)(runtime->dma_area + offset);
 
 	vx_setup_pseudo_dma(chip, 1);
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 1; /* in 16bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0) {
+		for (; length > 0; length--) {
 			outw(cpu_to_le16(*addr), port);
 			addr++;
 		}
@@ -384,7 +384,7 @@ static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 	pipe->hw_ptr += count;
 	count >>= 1; /* in 16bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 0) {
+	for (; count > 0; count--) {
 		outw(cpu_to_le16(*addr), port);
 		addr++;
 	}
@@ -411,12 +411,12 @@ static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 	if (snd_BUG_ON(count % 2))
 		return;
 	vx_setup_pseudo_dma(chip, 0);
-	if (offset + count > pipe->buffer_bytes) {
+	if (offset + count >= pipe->buffer_bytes) {
 		int length = pipe->buffer_bytes - offset;
 		count -= length;
 		length >>= 1; /* in 16bit words */
 		/* Transfer using pseudo-dma. */
-		while (length-- > 0)
+		for (; length > 0; length--)
 			*addr++ = le16_to_cpu(inw(port));
 		addr = (unsigned short *)runtime->dma_area;
 		pipe->hw_ptr = 0;
@@ -424,7 +424,7 @@ static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
 	pipe->hw_ptr += count;
 	count >>= 1; /* in 16bit words */
 	/* Transfer using pseudo-dma. */
-	while (count-- > 1)
+	for (; count > 1; count--)
 		*addr++ = le16_to_cpu(inw(port));
 	/* Disable DMA */
 	pchip->regDIALOG &= ~VXP_DLG_DMAREAD_SEL_MASK;
-- 
2.11.0

  parent reply	other threads:[~2017-11-08 20:52 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08 20:50 [PATCH AUTOSEL for-4.4 01/39] extcon: palmas: Check the parent instance to prevent the NULL Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 03/39] ARM: dts: Fix compatible for ti81xx uarts for 8250 Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 02/39] fm10k: request reset when mbx->state changes Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 04/39] ARM: dts: Fix am335x and dm814x scm syscon to probe children Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 05/39] ARM: OMAP2+: Fix init for multiple quirks for the same SoC Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 09/39] ata: SATA_MV should depend on HAS_DMA Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 06/39] ARM: dts: Fix omap3 off mode pull defines Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 07/39] ata: ATA_BMDMA should depend on HAS_DMA Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 08/39] ata: SATA_HIGHBANK " Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 13/39] igb: Fix hw_dbg logging in igb_update_flash_i210 Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 10/39] drm/sti: sti_vtg: Handle return NULL error from devm_ioremap_nocache Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 11/39] igb: reset the PHY before reading the PHY ID Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 12/39] igb: close/suspend race in netif_device_detach Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 15/39] scsi: ufs: add capability to keep auto bkops always enabled Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 17/39] scsi: lpfc: Add missing memory barrier Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 16/39] staging: rtl8188eu: fix incorrect ERROR tags from logs Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 14/39] scsi: ufs-qcom: Fix module autoload Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 21/39] scsi: lpfc: Clear the VendorVersion in the PLOGI/PLOGI ACC payload Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 20/39] scsi: lpfc: Correct issue leading to oops during link reset Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 18/39] scsi: lpfc: FCoE VPort enable-disable does not bring up the VPort Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 19/39] scsi: lpfc: Correct host name in symbolic_name field Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 25/39] backlight: adp5520: Fix error handling in adp5520_bl_probe() Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 22/39] ALSA: vx: Don't try to update capture stream before running Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 24/39] backlight: lcd: Fix race condition during register Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` Levin, Alexander (Sasha Levin) [this message]
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 28/39] arm64: dts: NS2: reserve memory for Nitro firmware Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 26/39] gpu: drm: mgag200: mgag200_main:- Handle error from pci_iomap Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 29/39] ixgbe: fix AER error handling Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 27/39] ALSA: hda/realtek - Add new codec ID ALC299 Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 32/39] ixgbe: add mask for 64 RSS queues Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 33/39] ixgbe: do not disable FEC from the driver Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 30/39] ixgbe: handle close/suspend race with netif_device_detach/present Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 31/39] ixgbe: Reduce I2C retry count on X550 devices Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 34/39] staging: rtl8712: fixed little endian problem Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 35/39] MIPS: End asm function prologue macros with .insn Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 36/39] MIPS: init: Ensure bootmem does not corrupt reserved memory Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 37/39] MIPS: init: Ensure reserved memory regions are not added to bootmem Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 39/39] MIPS: Use Makefile.postlink to insert relocations into vmlinux Levin, Alexander (Sasha Levin)
2017-11-09  9:16   ` Matt Redfearn
2017-11-09 16:42     ` Levin, Alexander (Sasha Levin)
2017-11-08 20:50 ` [PATCH AUTOSEL for-4.4 38/39] MIPS: Netlogic: Exclude netlogic,xlp-pic code from XLR builds Levin, Alexander (Sasha Levin)

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=20171108205027.27525-23-alexander.levin@verizon.com \
    --to=alexander.levin@one.verizon.com \
    --cc=linux-kernel@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).