From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sf.net
Subject: [PATCH 3/3] ALSA: control: add dimension validator for kernel driver
Date: Fri, 1 Jul 2016 20:10:13 +0900 [thread overview]
Message-ID: <1467371413-16895-4-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1467371413-16895-1-git-send-email-o-takashi@sakamocchi.jp>
Currently, kernel drivers are allowed to set arbitrary dimension
information to elements. The total number of members calculated by the
dimension information should be within the number of members in the
element, while there's no validator. When userspace applications have quite
simple implementation, this can cause buffer-over-run over
'struct snd_ctl_elem_value' data.
This commit adds the validation. Unfortunately, the dimension information
is set at runtime, thus the validation cannot run in advance.
As of Linux 4.7, there's no drivers to use the dimen information
except for Echo Audio PCI cards.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
sound/core/control.c | 48 ++++++++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/sound/core/control.c b/sound/core/control.c
index 54da910..a0927ae 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -845,28 +845,44 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
down_read(&card->controls_rwsem);
kctl = snd_ctl_find_id(card, &info->id);
if (kctl == NULL) {
- up_read(&card->controls_rwsem);
- return -ENOENT;
+ result = -ENOENT;
+ goto end;
}
#ifdef CONFIG_SND_DEBUG
info->access = 0;
#endif
result = kctl->info(kctl, info);
- if (result >= 0) {
- snd_BUG_ON(info->access);
- index_offset = snd_ctl_get_ioff(kctl, &info->id);
- vd = &kctl->vd[index_offset];
- snd_ctl_build_ioff(&info->id, kctl, index_offset);
- info->access = vd->access;
- if (vd->owner) {
- info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK;
- if (vd->owner == ctl)
- info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER;
- info->owner = pid_vnr(vd->owner->pid);
- } else {
- info->owner = -1;
- }
+ if (result < 0)
+ goto end;
+
+ snd_BUG_ON(info->access);
+
+ /* This is a driver bug. */
+ if (!validate_element_member_dimension(info)) {
+ dev_err(card->dev,
+ "This module has a bug of invalid dimention info.\n");
+ result = -ENODATA;
+ goto end;
}
+
+ index_offset = snd_ctl_get_ioff(kctl, &info->id);
+ vd = &kctl->vd[index_offset];
+ snd_ctl_build_ioff(&info->id, kctl, index_offset);
+ info->access = vd->access;
+
+ /* This element is not locked by any processes. */
+ if (vd->owner == NULL) {
+ info->owner = -1;
+ goto end;
+ }
+
+ info->owner = pid_vnr(vd->owner->pid);
+ info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK;
+
+ /* This element is locked by this process. */
+ if (vd->owner == ctl)
+ info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER;
+end:
up_read(&card->controls_rwsem);
return result;
}
--
2.7.4
next prev parent reply other threads:[~2016-07-01 11:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-01 11:10 [PATCH 0/3 v3] ALSA: ctl: add dimension information validator Takashi Sakamoto
2016-07-01 11:10 ` [PATCH 1/3] ALSA: echoaudio: purge contradictions between dimension matrix members and total number of members Takashi Sakamoto
2016-07-01 11:10 ` [PATCH 2/3] ALSA: control: add dimension validator for userspace element Takashi Sakamoto
2016-07-01 12:29 ` Takashi Sakamoto
2016-07-02 7:56 ` Takashi Iwai
2016-07-06 13:07 ` Takashi Sakamoto
2016-07-06 13:34 ` Takashi Iwai
2016-07-06 14:18 ` Takashi Sakamoto
2016-07-06 14:40 ` Takashi Iwai
2016-07-07 8:52 ` Takashi Sakamoto
2016-07-01 11:10 ` Takashi Sakamoto [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-07-01 4:15 [PATCH 0/3 v2] ALSA: ctl: add dimension information validator Takashi Sakamoto
2016-07-01 4:15 ` [PATCH 3/3] ALSA: control: add dimension validator for kernel driver Takashi Sakamoto
2016-06-30 14:04 [PATCH 0/3] ALSA: add dimension information validator Takashi Sakamoto
2016-06-30 14:04 ` [PATCH 3/3] ALSA: control: add dimension validator for kernel driver Takashi Sakamoto
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=1467371413-16895-4-git-send-email-o-takashi@sakamocchi.jp \
--to=o-takashi@sakamocchi.jp \
--cc=alsa-devel@alsa-project.org \
--cc=clemens@ladisch.de \
--cc=ffado-devel@lists.sf.net \
--cc=tiwai@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.