Skip to contentSkip to conversation

ALSA: seq: a possible sleep-in-atomic-context bug in snd_virmidi_dev_receive_event()

BUG Jia-Ju Bai 3 participants 4 messages Dec 17, 2019

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

The driver may sleep while holding a read lock.
The function call path (from bottom to top) in Linux 4.19 is:

sound/core/seq/seq_memory.c, 96:
    copy_from_user in snd_seq_dump_var_event sound/core/seq/seq_virmidi.c, 97:
    snd_seq_dump_var_event in snd_virmidi_dev_receive_event sound/core/seq/seq_virmidi.c, 88:
    _raw_read_lock in snd_virmidi_dev_receive_event

copy_from_user() can sleep at runtime.

I am not sure how to properly fix this possible bug, so I only report it.

This bug is found by a static analysis tool STCheck written by myself.

Best wishes,
Jia-Ju Bai

#1 lore raw
Quoted 10 lines · Jia-Ju Bai

The driver may sleep while holding a read lock.
The function call path (from bottom to top) in Linux 4.19 is:

sound/core/seq/seq_memory.c, 96:
    copy_from_user in snd_seq_dump_var_event sound/core/seq/seq_virmidi.c, 97:
    snd_seq_dump_var_event in snd_virmidi_dev_receive_event sound/core/seq/seq_virmidi.c, 88:
    _raw_read_lock in snd_virmidi_dev_receive_event

Quoted 5 lines

copy_from_user() can sleep at runtime.

I am not sure how to properly fix this possible bug, so I only report it.

This bug is found by a static analysis tool STCheck written by myself.

Patches for this is usually best :)

#2 lore raw
In reply to Jia-Ju Bai
Quoted 10 lines · Jia-Ju Bai

The driver may sleep while holding a read lock.
The function call path (from bottom to top) in Linux 4.19 is:

sound/core/seq/seq_memory.c, 96:
    copy_from_user in snd_seq_dump_var_event sound/core/seq/seq_virmidi.c, 97:
    snd_seq_dump_var_event in snd_virmidi_dev_receive_event sound/core/seq/seq_virmidi.c, 88:
    _raw_read_lock in snd_virmidi_dev_receive_event

This can't happen. snd_virmidi_dev_receive_event() takes conditionally either read_lock or rw_sem depending on the atomic argument. And the data including user-space pointer is handled always with atomic=1, hence down_read() is used instead of read_lock() here.

thanks,

Takashi

Quoted 10 lines

copy_from_user() can sleep at runtime.

I am not sure how to properly fix this possible bug, so I only report it.

This bug is found by a static analysis tool STCheck written by myself.

Best wishes,
Jia-Ju Bai

author
#3 lore raw
Quoted 11 lines · Takashi Iwai
Quoted 9 lines · Jia-Ju Bai

The driver may sleep while holding a read lock.
The function call path (from bottom to top) in Linux 4.19 is:

sound/core/seq/seq_memory.c, 96:
    copy_from_user in snd_seq_dump_var_event
sound/core/seq/seq_virmidi.c, 97:
    snd_seq_dump_var_event in snd_virmidi_dev_receive_event
sound/core/seq/seq_virmidi.c, 88:
    _raw_read_lock in snd_virmidi_dev_receive_event

Quoted 5 lines

This can't happen. snd_virmidi_dev_receive_event() takes conditionally either read_lock or rw_sem depending on the atomic argument. And the data including user-space pointer is handled always with atomic=1, hence down_read() is used instead of read_lock() here.

Okay, thanks for the explanation.

Best wishes,
Jia-Ju Bai