lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220327082018.13585-1-xiam0nd.tong@gmail.com>
Date:   Sun, 27 Mar 2022 16:20:18 +0800
From:   Xiaomeng Tong <xiam0nd.tong@...il.com>
To:     lgirdwood@...il.com, broonie@...nel.org, perex@...ex.cz,
        tiwai@...e.com
Cc:     kuninori.morimoto.gx@...esas.com, alsa-devel@...a-project.org,
        linux-kernel@...r.kernel.org,
        Xiaomeng Tong <xiam0nd.tong@...il.com>, stable@...r.kernel.org
Subject: [PATCH] soc: soc-core: fix a missing check on list iterator

The bug is here:
	*dai_name = dai->driver->name;

For for_each_component_dais, just like list_for_each_entry,
the list iterator 'dai' will point to a bogus position
containing HEAD if the list is empty or no element is found.
This case must be checked before any use of the iterator,
otherwise it will lead to a invalid memory access.

To fix the bug, use a new variable 'iter' as the list iterator,
while use the original variable 'dai' as a dedicated pointer
to point to the found element.

Cc: stable@...r.kernel.org
Fixes: 58bf4179000a3 ("ASoC: soc-core: remove dai_drv from snd_soc_component")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@...il.com>
---
 sound/soc/soc-core.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 434e61b46983..064fc0347868 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3238,7 +3238,7 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
 
 		ret = snd_soc_component_of_xlate_dai_name(pos, args, dai_name);
 		if (ret == -ENOTSUPP) {
-			struct snd_soc_dai *dai;
+			struct snd_soc_dai *dai = NULL, *iter;
 			int id = -1;
 
 			switch (args->args_count) {
@@ -3261,12 +3261,19 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
 			ret = 0;
 
 			/* find target DAI */
-			for_each_component_dais(pos, dai) {
-				if (id == 0)
+			for_each_component_dais(pos, iter) {
+				if (id == 0) {
+					dai = iter;
 					break;
+				}
 				id--;
 			}
 
+			if (!dai) {
+				ret = -EINVAL;
+				continue;
+			}
+
 			*dai_name = dai->driver->name;
 			if (!*dai_name)
 				*dai_name = pos->name;
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ