From patchwork Thu Jun 13 09:01:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 804185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74F3EC27C4F for ; Thu, 13 Jun 2024 09:01:35 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 3E457EB6; Thu, 13 Jun 2024 11:01:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3E457EB6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1718269293; bh=RmlL49W8XAlC/ECbKBS7UloNBM1NP6YzyoAgBjV3DKY=; h=From:To:Cc:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=KqBlsC8tPLEcuArtsk44lTe/YEpgyzBtl/eA8FxZH+j5y39jok1QxQPLXfWOlu303 o2Vyiti7YDHbGU+us45v/tBsY/vLoYA+nyd3B5RkdLO43ZkboGslLj/QPyu4fwE/+h 2MGFUkl/rPwzdvXfUFO+xFMaKoV26w1oQNXOTEWk= Received: by alsa1.perex.cz (Postfix, from userid 50401) id EFD7CF805C1; Thu, 13 Jun 2024 11:00:59 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 83817F805AE; Thu, 13 Jun 2024 11:00:59 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id EC20EF8057A; Thu, 13 Jun 2024 11:00:53 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B7780F800D0 for ; Thu, 13 Jun 2024 11:00:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B7780F800D0 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Cm8U2Z2H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718269250; x=1749805250; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RmlL49W8XAlC/ECbKBS7UloNBM1NP6YzyoAgBjV3DKY=; b=Cm8U2Z2HcPnjvfnOPC7LNUIM6o/5WBpl4aC9zPR06jO5RRAPMGFuIa2+ kEwjGdK1wiUUiabOMIPXUNnW2KKjvqVkP7MJlfhuje8yiWLuPAUsvciB9 anAXc+PSNAzlHAZ7FcT6viTVSSkHyN35YXODJndzdMBWoWVjCyfge5/AY be0YDr16AFj93Qwr4zZINoN8tJjeKvVYbGuOHhUoMyNLTdIWygcuxbhjj P3Cvyg/ah5ZujgHk4m702RU8v8f8YwtfxsCNXnLjB9EKwGhnCJfYuBo5T PMMedfD9+o8USVIK6EbRA2pPygXz8tjAdJRpSd7FBdoScTxJs1xN/ozWZ w==; X-CSE-ConnectionGUID: Yciah4tZSCeMECWjuJ7IBw== X-CSE-MsgGUID: s9nhvgSOStO8jNlIF/zcpg== X-IronPort-AV: E=McAfee;i="6700,10204,11101"; a="18001760" X-IronPort-AV: E=Sophos;i="6.08,234,1712646000"; d="scan'208";a="18001760" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 02:00:44 -0700 X-CSE-ConnectionGUID: f8Id1/VKT+SSCHXW0MWXMQ== X-CSE-MsgGUID: PgZiupMAR0KSxa8WXr6WdQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,234,1712646000"; d="scan'208";a="44455422" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by fmviesa003.fm.intel.com with ESMTP; 13 Jun 2024 02:00:42 -0700 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Mark Brown , Pierre-Louis Bossart , =?utf-8?q?P?= =?utf-8?q?=C3=A9ter_Ujfalusi?= Cc: Cezary Rojewski , Takashi Iwai , Jaroslav Kysela , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, =?utf-8?q?Amadeus?= =?utf-8?q?z_S=C5=82awi=C5=84ski?= Subject: [PATCH] ASoC: topology: Fix route memory corruption Date: Thu, 13 Jun 2024 11:01:26 +0200 Message-Id: <20240613090126.841189-1-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: N42RFXBHBEX5M22SABLH4EWGW7W75NHZ X-Message-ID-Hash: N42RFXBHBEX5M22SABLH4EWGW7W75NHZ X-MailFrom: amadeuszx.slawinski@linux.intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: It was reported that recent fix for memory corruption during topology load, causes corruption in other cases. Instead of being overeager with checking topology, assume that it is properly formatted and just duplicate strings. Reported-by: Pierre-Louis Bossart Closes: https://lore.kernel.org/linux-sound/171812236450.201359.3019210915105428447.b4-ty@kernel.org/T/#m8c4bd5abf453960fde6f826c4b7f84881da63e9d Suggested-by: Péter Ujfalusi Signed-off-by: Amadeusz Sławiński --- sound/soc/soc-topology.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 0225bc5fc425a..4b166294602fa 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1052,21 +1052,15 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, break; } - route->source = devm_kmemdup(tplg->dev, elem->source, - min(strlen(elem->source), maxlen), - GFP_KERNEL); - route->sink = devm_kmemdup(tplg->dev, elem->sink, - min(strlen(elem->sink), maxlen), - GFP_KERNEL); + route->source = devm_kstrdup(tplg->dev, elem->source, GFP_KERNEL); + route->sink = devm_kstrdup(tplg->dev, elem->sink, GFP_KERNEL); if (!route->source || !route->sink) { ret = -ENOMEM; break; } if (strnlen(elem->control, maxlen) != 0) { - route->control = devm_kmemdup(tplg->dev, elem->control, - min(strlen(elem->control), maxlen), - GFP_KERNEL); + route->control = devm_kstrdup(tplg->dev, elem->control, GFP_KERNEL); if (!route->control) { ret = -ENOMEM; break;