History

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 9a1b64caac82aa02cb74587ffc798e6f42c6170a.)

Clemens Ladisch committed 16 years ago

Commit aa73aec1 parent cd072021 file · +3 −1Browse files

Unified · Split

sound/core/rawmidi.c+3−1
@@ -535,13 +535,15 @@ static int snd_rawmidi_release(struct inode *inode, struct file *file) · 534 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t