public inbox for cip-dev@lists.cip-project.org
 help / color / mirror / Atom feed
From: Alexander Grund <theflamefire89@gmail.com>
To: cip-dev@lists.cip-project.org
Cc: uli+cip@fpond.eu
Subject: [PATCH 4.4 2/3] ALSA: control: Fix memory corruption risk in snd_ctl_elem_read
Date: Fri, 24 Mar 2023 18:18:11 +0100	[thread overview]
Message-ID: <20230324171812.221086-3-theflamefire89@gmail.com> (raw)
In-Reply-To: <20230324171812.221086-1-theflamefire89@gmail.com>

From: Richard Fitzgerald <rf@opensource.cirrus.com>

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>
---
 sound/core/control.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/core/control.c b/sound/core/control.c
index a042a30d6a728..3ca81e85a1492 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -884,7 +884,7 @@ static int snd_ctl_elem_read(struct snd_card *card,
 
 	index_offset = snd_ctl_get_ioff(kctl, &control->id);
 	vd = &kctl->vd[index_offset];
-	if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) && kctl->get == NULL)
+	if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || kctl->get == NULL)
 		return -EPERM;
 
 	snd_ctl_build_ioff(&control->id, kctl, index_offset);
-- 
2.40.0



  parent reply	other threads:[~2023-03-24 17:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 17:18 [PATCH 4.4 0/3] ALSA: control: Fix locking around snd_ctl_elem_read/write Alexander Grund
2023-03-24 17:18 ` [PATCH 4.4 1/3] ALSA: control: code refactoring for ELEM_READ/ELEM_WRITE operations Alexander Grund
2023-03-29 22:29   ` [cip-dev] " nobuhiro1.iwamatsu
2023-03-31 15:45     ` Alexander Grund
2023-03-24 17:18 ` Alexander Grund [this message]
2023-03-29 22:33   ` [cip-dev] [PATCH 4.4 2/3] ALSA: control: Fix memory corruption risk in snd_ctl_elem_read nobuhiro1.iwamatsu
2023-03-31 15:52     ` Alexander Grund
2023-03-24 17:18 ` [PATCH 4.4 3/3] ALSA: control: use counting semaphore as write lock for ELEM_WRITE operation Alexander Grund
2023-03-29 22:39   ` [cip-dev] " nobuhiro1.iwamatsu
2023-03-31 15:51     ` Alexander Grund
2023-04-03  8:56       ` [cip-dev] " Ulrich Hecht
2023-04-03 17:13         ` Alexander Grund
2023-04-02 16:30 ` [cip-dev] [PATCH 4.4 0/3] ALSA: control: Fix locking around snd_ctl_elem_read/write Pavel Machek
2023-04-02 18:34   ` Alexander Grund
2023-04-03  8:56   ` [cip-dev] " Ulrich Hecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230324171812.221086-3-theflamefire89@gmail.com \
    --to=theflamefire89@gmail.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=uli+cip@fpond.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox