Skip to contentSkip to conversation

Fix snd-usb-audio in 32-bit compat environemt

PATCH In review Juergen Kreileder 3 participants 4 messages Feb 18, 2006 – Feb 20, 2006 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix snd-usb-audio in 32-bit compat environemt

Hi,

I'm getting oopses with snd-usb-audio in 32-bit compat environments:
control_compat.c:get_ctl_type() doesn't initialize 'info', so 'itemlist[uinfo->value.enumerated.item]' in usbmixer.c:mixer_ctl_selector_info() might access random memory (The 'if ((int)uinfo->value.enumerated.item >= cval->max)' doesn't fix all problems because of the unsigned -> signed conversion.)

Here's a fix:

sound/core/control_compat.c +11 -5
@@ -167,7 +167,7 @@ static int get_ctl_type(struct snd_card 
 			int *countp)
 {
 	struct snd_kcontrol *kctl;
-	struct snd_ctl_elem_info info;
+	struct snd_ctl_elem_info *info;
 	int err;
 
 	down_read(&card->controls_rwsem);
@@ -176,13 +176,19 @@ static int get_ctl_type(struct snd_card 
 		up_read(&card->controls_rwsem);
 		return -ENXIO;
 	}
-	info.id = *id;
-	err = kctl->info(kctl, &info);
+	info = kzalloc(sizeof(*info), GFP_KERNEL);
+	if (info == NULL) {
+		up_read(&card->controls_rwsem);
+		return -ENOMEM;
+	}
+	info->id = *id;
+	err = kctl->info(kctl, info);
 	up_read(&card->controls_rwsem);
 	if (err >= 0) {
-		err = info.type;
-		*countp = info.count;
+		err = info->type;
+		*countp = info->count;
 	}
+	kfree(info);
 	return err;
 }
 

=

Tested on ppc64.

Juergen

Signature · 9 lines
Juergen Kreileder, Blackdown Java-Linux Team
http://blog.blackdown.de/


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
#1 lore raw
Quoted 6 lines · Juergen Kreileder

I'm getting oopses with snd-usb-audio in 32-bit compat environments:
control_compat.c:get_ctl_type() doesn't initialize 'info', so 'itemlist[uinfo->value.enumerated.item]' in usbmixer.c:mixer_ctl_selector_info() might access random memory (The 'if ((int)uinfo->value.enumerated.item >= cval->max)' doesn't fix all problems because of the unsigned -> signed conversion.)

IMO, what you did is an overkill. Does this patch fixes your problem?

sound/core/control_compat.c +1 -0
@@ -176,6 +176,7 @@ static int get_ctl_type(struct snd_card
 		up_read(&card->controls_rwsem);
 		return -ENXIO;
 	}
+	memset(info, 0, sizeof(struct snd_ctl_elem_info));
 	info.id = *id;
 	err = kctl->info(kctl, &info);
 	up_read(&card->controls_rwsem);
Quoted 24 lines
sound/core/control_compat.c +8 -3
@@ -167,7 +167,7 @@ static int get_ctl_type(struct snd_card
 			int *countp)
 {
 	struct snd_kcontrol *kctl;
-	struct snd_ctl_elem_info info;
+	struct snd_ctl_elem_info *info;
 	int err;
 
 	down_read(&card->controls_rwsem);
@@ -176,13 +176,19 @@ static int get_ctl_type(struct snd_card
 		up_read(&card->controls_rwsem);
 		return -ENXIO;
 	}
-	info.id = *id;
-	err = kctl->info(kctl, &info);
+	info = kzalloc(sizeof(*info), GFP_KERNEL);
+	if (info == NULL) {
+		up_read(&card->controls_rwsem);
+		return -ENOMEM;
+	}
+	info->id = *id;
+	err = kctl->info(kctl, info);

sound/core/control_compat.c static int get_ctl_type(struct snd_card · line 193

Quoted 10 lines
sound/core/control_compat.c +3 -2
 	up_read(&card->controls_rwsem);
 	if (err >= 0) {
-		err = info.type;
-		*countp = info.count;
+		err = info->type;
+		*countp = info->count;
 	}
+	kfree(info);
 	return err;
 }

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642

#2 lore raw
Quoted 10 lines · Alexey Dobriyan
Quoted 7 lines · Juergen Kreileder

I'm getting oopses with snd-usb-audio in 32-bit compat
environments: control_compat.c:get_ctl_type() doesn't initialize 'info', so
'itemlist[uinfo->value.enumerated.item]' in usbmixer.c:mixer_ctl_selector_info() might access random memory (The 'if ((int)uinfo->value.enumerated.item >= cval->max)' doesn't fix all problems because of the unsigned -> signed conversion.)

IMO, what you did is an overkill.

The advantage of the longer fix is reduced stack usage.

Quoted 1 line

Does this patch fixes your problem?

Yes but you can have that even simpler:

sound/core/control_compat.c +1 -1
@@ -167,7 +167,7 @@ static int get_ctl_type(struct snd_card 
 			int *countp)
 {
 	struct snd_kcontrol *kctl;
-	struct snd_ctl_elem_info info;
+	struct snd_ctl_elem_info info = {0};
 	int err;
 
 	down_read(&card->controls_rwsem);

=

Juergen

Signature · 2 lines
Juergen Kreileder, Blackdown Java-Linux Team
http://blog.blackdown.de/
#3 lore raw

At Sun, 19 Feb 2006 20:02:03 +0100,

Quoted 12 lines · Juergen Kreileder
Quoted 9 lines · Alexey Dobriyan
Quoted 7 lines · Juergen Kreileder

I'm getting oopses with snd-usb-audio in 32-bit compat
environments: control_compat.c:get_ctl_type() doesn't initialize 'info', so
'itemlist[uinfo->value.enumerated.item]' in usbmixer.c:mixer_ctl_selector_info() might access random memory (The 'if ((int)uinfo->value.enumerated.item >= cval->max)' doesn't fix all problems because of the unsigned -> signed conversion.)

Quoted 3 lines
Quoted 1 line

IMO, what you did is an overkill.

The advantage of the longer fix is reduced stack usage.

But it also introduces a kmalloc overhead.
Let's fix the problem first with a simpler patch.

Quoted 7 lines
Quoted 1 line

Does this patch fixes your problem?

Yes but you can have that even simpler:

sound/core/control_compat.c static int get_ctl_type(struct snd_card · line 173

Quoted 8 lines
sound/core/control_compat.c +1 -1
@@ -167,7 +167,7 @@ static int get_ctl_type(struct snd_card 
 			int *countp)
 {
 	struct snd_kcontrol *kctl;
-	struct snd_ctl_elem_info info;
+	struct snd_ctl_elem_info info = {0};
 	int err;
 
 	down_read(&card->controls_rwsem);

I prefer Alexey's patch sicne it's clearer that the zero-initialization is done just before the usage.

But = {0} might result in a better code because of compiler optimization...

Thanks!

Takashi