Skip to content

Commit aa73aec

Browse files
cladischtiwai
authored andcommitted
ALSA: rawmidi: fix oops (use after free) when unloading a driver module
When a driver module is unloaded and the last still open file is a raw MIDI device, the card and its devices will be actually freed in the snd_card_file_remove() call when that file is closed. Afterwards, rmidi and rmidi->card point into freed memory, so the module pointer is likely to be garbage. (This was introduced by commit 9a1b64c.) Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Reported-by: Krzysztof Foltman <wdev@foltman.com> Cc: 2.6.30-2.6.35 <stable@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent cd07202 commit aa73aec

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sound/core/rawmidi.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,15 @@ static int snd_rawmidi_release(struct inode *inode, struct file *file)
535535
{
536536
struct snd_rawmidi_file *rfile;
537537
struct snd_rawmidi *rmidi;
538+
struct module *module;
538539

539540
rfile = file->private_data;
540541
rmidi = rfile->rmidi;
541542
rawmidi_release_priv(rfile);
542543
kfree(rfile);
544+
module = rmidi->card->module;
543545
snd_card_file_remove(rmidi->card, file);
544-
module_put(rmidi->card->module);
546+
module_put(module);
545547
return 0;
546548
}
547549

0 commit comments

Comments
 (0)