History

ALSA: rawmidi: Fix missing input substream checks in compat ioctls

Some rawmidi compat ioctls lack of the input substream checks (although they do check only for rfile->output). This many eventually lead to an Oops as NULL substream is passed to the rawmidi core functions. Fix it by adding the proper checks before each function call. The bug was spotted by syzkaller.

Takashi Iwai committed 8 years ago

Commit 8a56ef41 parent a3dafb21 file · +12 −6Browse files

Unified · Split

sound/core/rawmidi_compat.c+12−6
@@ -36,8 +36,6 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile, · 35 unmodified lines
3636 struct snd_rawmidi_params params;
3737 unsigned int val;
3838
39− if (rfile->output == NULL)
40− return -EINVAL;
4139 if (get_user(params.stream, &src->stream) ||
4240 get_user(params.buffer_size, &src->buffer_size) ||
4341 get_user(params.avail_min, &src->avail_min) ||
@@ -46,8 +44,12 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile, · 2 unmodified lines
4644 params.no_active_sensing = val;
4745 switch (params.stream) {
4846 case SNDRV_RAWMIDI_STREAM_OUTPUT:
47+ if (!rfile->output)
48+ return -EINVAL;
4949 return snd_rawmidi_output_params(rfile->output, &params);
5050 case SNDRV_RAWMIDI_STREAM_INPUT:
51+ if (!rfile->input)
52+ return -EINVAL;
5153 return snd_rawmidi_input_params(rfile->input, &params);
5254 }
5355 return -EINVAL;
@@ -67,16 +69,18 @@ static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile, · 13 unmodified lines
6769 int err;
6870 struct snd_rawmidi_status status;
6971
70− if (rfile->output == NULL)
71− return -EINVAL;
7272 if (get_user(status.stream, &src->stream))
7373 return -EFAULT;
7474
7575 switch (status.stream) {
7676 case SNDRV_RAWMIDI_STREAM_OUTPUT:
77+ if (!rfile->output)
78+ return -EINVAL;
7779 err = snd_rawmidi_output_status(rfile->output, &status);
7880 break;
7981 case SNDRV_RAWMIDI_STREAM_INPUT:
82+ if (!rfile->input)
83+ return -EINVAL;
8084 err = snd_rawmidi_input_status(rfile->input, &status);
8185 break;
8286 default:
@@ -112,16 +116,18 @@ static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile, · 29 unmodified lines
112116 int err;
113117 struct snd_rawmidi_status status;
114118
115− if (rfile->output == NULL)
116− return -EINVAL;
117119 if (get_user(status.stream, &src->stream))
118120 return -EFAULT;
119121
120122 switch (status.stream) {
121123 case SNDRV_RAWMIDI_STREAM_OUTPUT:
124+ if (!rfile->output)
125+ return -EINVAL;
122126 err = snd_rawmidi_output_status(rfile->output, &status);
123127 break;
124128 case SNDRV_RAWMIDI_STREAM_INPUT:
129+ if (!rfile->input)
130+ return -EINVAL;
125131 err = snd_rawmidi_input_status(rfile->input, &status);
126132 break;
127133 default: