All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: "Dmitry Vyukov" <dvyukov@google.com>
Cc: <alsa-devel@alsa-project.org>, "Jaroslav Kysela" <perex@perex.cz>,
	"LKML" <linux-kernel@vger.kernel.org>,
	"Alexander Potapenko" <glider@google.com>,
	"Kostya Serebryany" <kcc@google.com>,
	"syzkaller" <syzkaller@googlegroups.com>,
	"Sasha Levin" <sasha.levin@oracle.com>
Subject: Re: sound: out-of-bounds write in snd_rawmidi_kernel_write1
Date: Wed, 03 Feb 2016 10:41:14 +0100	[thread overview]
Message-ID: <s5hlh722ksl.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5hpowe2l2l.wl-tiwai@suse.de>

On Wed, 03 Feb 2016 10:35:14 +0100,
Takashi Iwai wrote:
> 
> On Wed, 03 Feb 2016 09:57:50 +0100,
> Dmitry Vyukov wrote:
> > 
> > Hello,
> > 
> > The following program triggers an out-of-bounds write in
> > snd_rawmidi_kernel_write1 (run in parallel loop). It seems to try to
> > copy -1 bytes (aka 4GB) from user space into kernel smashing all on
> > its way.
> 
> What card is /dev/midi3?  Please check /proc/asound/cards.
> Is it MTPAV?

In anyway the patch below should paper over it.  But it's still
strange that it gets a negative value there.  Could you put

   WARN_ON(count1 < 0)

before the newly added check?

I tried it locally with virmidi but it didn't appear, so far.  Maybe
my setup is too slow and has fewer CPUs than yours.


thanks,

Takashi

---
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 26ca02248885..2fef77d9de50 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -1239,6 +1239,8 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
 	}
 	while (count > 0 && runtime->avail > 0) {
 		count1 = runtime->buffer_size - runtime->appl_ptr;
+		if (count1 <= 0)
+			break;
 		if (count1 > count)
 			count1 = count;
 		if (count1 > (long)runtime->avail)

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: alsa-devel@alsa-project.org, Jaroslav Kysela <perex@perex.cz>,
	LKML <linux-kernel@vger.kernel.org>,
	Alexander Potapenko <glider@google.com>,
	Kostya Serebryany <kcc@google.com>,
	syzkaller <syzkaller@googlegroups.com>,
	Sasha Levin <sasha.levin@oracle.com>
Subject: Re: sound: out-of-bounds write in snd_rawmidi_kernel_write1
Date: Wed, 03 Feb 2016 10:41:14 +0100	[thread overview]
Message-ID: <s5hlh722ksl.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5hpowe2l2l.wl-tiwai@suse.de>

On Wed, 03 Feb 2016 10:35:14 +0100,
Takashi Iwai wrote:
> 
> On Wed, 03 Feb 2016 09:57:50 +0100,
> Dmitry Vyukov wrote:
> > 
> > Hello,
> > 
> > The following program triggers an out-of-bounds write in
> > snd_rawmidi_kernel_write1 (run in parallel loop). It seems to try to
> > copy -1 bytes (aka 4GB) from user space into kernel smashing all on
> > its way.
> 
> What card is /dev/midi3?  Please check /proc/asound/cards.
> Is it MTPAV?

In anyway the patch below should paper over it.  But it's still
strange that it gets a negative value there.  Could you put

   WARN_ON(count1 < 0)

before the newly added check?

I tried it locally with virmidi but it didn't appear, so far.  Maybe
my setup is too slow and has fewer CPUs than yours.


thanks,

Takashi

---
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 26ca02248885..2fef77d9de50 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -1239,6 +1239,8 @@ static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
 	}
 	while (count > 0 && runtime->avail > 0) {
 		count1 = runtime->buffer_size - runtime->appl_ptr;
+		if (count1 <= 0)
+			break;
 		if (count1 > count)
 			count1 = count;
 		if (count1 > (long)runtime->avail)

  reply	other threads:[~2016-02-03  9:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03  8:57 sound: out-of-bounds write in snd_rawmidi_kernel_write1 Dmitry Vyukov
2016-02-03  8:57 ` Dmitry Vyukov
2016-02-03  9:35 ` Takashi Iwai
2016-02-03  9:35   ` Takashi Iwai
2016-02-03  9:41   ` Takashi Iwai [this message]
2016-02-03  9:41     ` Takashi Iwai
2016-02-03 11:39     ` Takashi Iwai
2016-02-03 11:39       ` Takashi Iwai
2016-02-03 12:02       ` Takashi Iwai
2016-02-03 12:02         ` Takashi Iwai
2016-02-03 13:37         ` Dmitry Vyukov
2016-02-03 14:26           ` Takashi Iwai
2016-02-03 13:25   ` Dmitry Vyukov

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=s5hlh722ksl.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kcc@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=sasha.levin@oracle.com \
    --cc=syzkaller@googlegroups.com \
    /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.