alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Dan Rosenberg <drosenberg@vsecurity.com>
Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org,
	security@kernel.org
Subject: Re: [PATCH] sound/oss/midi_synth: prevent underflow, use of uninitialized value, and signedness issue
Date: Wed, 23 Mar 2011 08:39:22 +0100	[thread overview]
Message-ID: <s5h1v1yxp3p.wl%tiwai@suse.de> (raw)
In-Reply-To: <1300818668.2130.27.camel@dan>

At Tue, 22 Mar 2011 14:31:08 -0400,
Dan Rosenberg wrote:
> 
> The offset passed to midi_synth_load_patch() can be essentially
> arbitrary.  If it's greater than the header length, this will result in
> a copy_from_user(dst, src, negative_val).  While this will just return
> -EFAULT on x86, on other architectures this may cause memory corruption.
> Additionally, the length field of the sysex_info structure may not be
> initialized prior to its use.  Finally, a signed comparison may result
> in an unintentionally large loop.
> 
> This patch fixes all these issues, as well as some cleanup to prevent
> checkpatch.pl from complaining.
> 
> Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
> Cc: stable@kernel.org

Well, the whole load_patch mechanism doesn't look working right with
ofs != 0.  The only caller of this callback is sound/oss/sequencer.c,
and it assumes that the whole chunk is passed once without splitting.
Thus the offset calculation in this code is obviously wrong, and
passing offset itself doesn't make any sense.

A similar problem (uninitialized struct fields) is found in another
load_patch callback in sound/oss/opl3.c.

That is, the best fix would be to rip off the offset argument from
this callback.


thanks,

Takashi

> ---
>  sound/oss/midi_synth.c |   27 ++++++++++++++-------------
>  1 files changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/sound/oss/midi_synth.c b/sound/oss/midi_synth.c
> index 3c09374..3500f80 100644
> --- a/sound/oss/midi_synth.c
> +++ b/sound/oss/midi_synth.c
> @@ -491,16 +491,18 @@ midi_synth_load_patch(int dev, int format, const char __user *addr,
>  	if (!prefix_cmd(orig_dev, 0xf0))
>  		return 0;
>  
> +	/* Invalid patch format */
>  	if (format != SYSEX_PATCH)
> -	{
> -/*		  printk("MIDI Error: Invalid patch format (key) 0x%x\n", format);*/
>  		  return -EINVAL;
> -	}
> +
> +	/* Patch header too short */
>  	if (count < hdr_size)
> -	{
> -/*		printk("MIDI Error: Patch header too short\n");*/
>  		return -EINVAL;
> -	}
> +
> +	/* Offset too high */
> +	if (offs > offsetof(struct sysex_info, len) || offs < 0)
> +		return -EINVAL;
> +
>  	count -= hdr_size;
>  
>  	/*
> @@ -510,14 +512,13 @@ midi_synth_load_patch(int dev, int format, const char __user *addr,
>  
>  	if(copy_from_user(&((char *) &sysex)[offs], &(addr)[offs], hdr_size - offs))
>  		return -EFAULT;
> - 
> - 	if (count < sysex.len)
> -	{
> -/*		printk(KERN_WARNING "MIDI Warning: Sysex record too short (%d<%d)\n", count, (int) sysex.len);*/
> +
> +	/* Sysex record too short */
> +	if ((unsigned)count < (unsigned)sysex.len)
>  		sysex.len = count;
> -	}
> -  	left = sysex.len;
> -  	src_offs = 0;
> +
> +	left = sysex.len;
> +	src_offs = 0;
>  
>  	for (i = 0; i < left && !signal_pending(current); i++)
>  	{
> 
> 

  reply	other threads:[~2011-03-23  7:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22 18:31 [PATCH] sound/oss/midi_synth: prevent underflow, use of uninitialized value, and signedness issue Dan Rosenberg
2011-03-23  7:39 ` Takashi Iwai [this message]
2011-03-23 11:23   ` Dan Rosenberg
2011-03-23 11:34     ` Dan Rosenberg

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=s5h1v1yxp3p.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=drosenberg@vsecurity.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=security@kernel.org \
    /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).