From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752454AbcBCJlS (ORCPT ); Wed, 3 Feb 2016 04:41:18 -0500 Received: from mx2.suse.de ([195.135.220.15]:46050 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750946AbcBCJlP (ORCPT ); Wed, 3 Feb 2016 04:41:15 -0500 Date: Wed, 03 Feb 2016 10:41:14 +0100 Message-ID: From: Takashi Iwai To: "Dmitry Vyukov" Cc: , "Jaroslav Kysela" , "LKML" , "Alexander Potapenko" , "Kostya Serebryany" , "syzkaller" , "Sasha Levin" Subject: Re: sound: out-of-bounds write in snd_rawmidi_kernel_write1 In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.5 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)