Skip to content

Commit bcdb192

Browse files
rfvirgilmikeNG
authored andcommitted
ALSA: control: Fix memory corruption risk in snd_ctl_elem_read
commit 5a23699a39abc5328921a81b89383d088f6ba9cc upstream. The patch "ALSA: control: code refactoring for ELEM_READ/ELEM_WRITE operations" introduced a potential for kernel memory corruption due to an incorrect if statement allowing non-readable controls to fall through and call the get function. For TLV controls a driver can omit SNDRV_CTL_ELEM_ACCESS_READ to ensure that only the TLV get function can be called. Instead the normal get() can be invoked unexpectedly and as the driver expects that this will only be called for controls <= 512 bytes, potentially try to copy >512 bytes into the 512 byte return array, so corrupting kernel memory. The problem is an attempt to refactor the snd_ctl_elem_read function to invert the logic so that it conditionally aborted if the control is unreadable instead of conditionally executing. But the if statement wasn't inverted correctly. The correct inversion of if (a && !b) is if (!a || b) Fixes: becf9e5d553c2 ("ALSA: control: code refactoring for ELEM_READ/ELEM_WRITE operations") Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Alexander Grund <theflamefire89@gmail.com> [uli: touched up commit message] Signed-off-by: Ulrich Hecht <uli+cip@fpond.eu> Change-Id: I2ba4da0896711eda284cb3c0004229b472aa6720
1 parent c589544 commit bcdb192

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

sound/core/control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ static int snd_ctl_elem_read(struct snd_card *card,
914914

915915
index_offset = snd_ctl_get_ioff(kctl, &control->id);
916916
vd = &kctl->vd[index_offset];
917-
if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) && kctl->get == NULL)
917+
if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || kctl->get == NULL)
918918
return -EPERM;
919919

920920
snd_ctl_build_ioff(&control->id, kctl, index_offset);

0 commit comments

Comments
 (0)