From patchwork Mon Jul 8 15:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 812653 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 B747CC3271E for ; Mon, 8 Jul 2024 15:21:40 +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 5C60B86F; Mon, 8 Jul 2024 17:21:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5C60B86F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1720452098; bh=BQsr0QooV/d3TxNeQGRSzfpz7axyeeF7mtNZAvlbAow=; h=From:To:CC:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=bEHwf8jQtktKT5hy3EO/qsHlGpAY1XqT9MEfoL/y40E6bZGCvCv4uMVo4M/gP26Rn WsGpxO83UmxQvCQROiKszE8/e03+xs7VOmK6FJI+Y24nxz5m/t5zgHQ3R8ogahcQZB 85CUt2dHgDh153F2zfzUx7OZPkFxLJaLnC7OugP4= Received: by alsa1.perex.cz (Postfix, from userid 50401) id B040BF805B4; Mon, 8 Jul 2024 17:21:06 +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 1F89DF805AB; Mon, 8 Jul 2024 17:21:06 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 87402F801F5; Mon, 8 Jul 2024 17:21:00 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (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 0C3DEF800FA for ; Mon, 8 Jul 2024 17:20:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0C3DEF800FA Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=cirrus.com header.i=@cirrus.com header.a=rsa-sha256 header.s=PODMain02222019 header.b=HlQuxlFQ Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46870Jll022463; Mon, 8 Jul 2024 10:20:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=PODMain02222019; bh=VTOCAsJ2DgwNIHbx lWGqUzgfjvlXFbBnCmhOojAy2co=; b=HlQuxlFQRwqxRBxlvheArRTSQJK7x5M6 sdtW1UOjzaP284RvHM9DydKmRqLxzpXBe8PThwO7nxJ/W3sNwFZ40ODOS4B5AwSc UnAzNm+2mu/lWZ14Nv7SrBZj3QwPT7AgkSPQ6BNpUkQ/D6OI3Lz9HQTNpyut6o7n 3VD2FUM96cR6HyLjN1lyJRDU06KdZUNh3kliBL6yt/ioo/plf07cyupihShDpw/1 tlaW4YjY2ko6cV9c9b9Bc3zwSDSdcZx1tfO53Dp336GW2OV0Y/8MByi5qGLdSRY8 /a0jLzvdjTaDESmZwFAH4wrFtOu64gjWGY49bDoRy5Fkn2U1G91sBA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 4073axsnbu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jul 2024 10:20:55 -0500 (CDT) Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 8 Jul 2024 16:20:52 +0100 Received: from ediswmail9.ad.cirrus.com (198.61.86.93) by anon-ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1544.9 via Frontend Transport; Mon, 8 Jul 2024 16:20:52 +0100 Received: from ediswws06.ad.cirrus.com (ediswws06.ad.cirrus.com [198.90.208.18]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id 4B96882024D; Mon, 8 Jul 2024 15:20:52 +0000 (UTC) From: Richard Fitzgerald To: CC: , , , Subject: [PATCH v2] firmware: cs_dsp: Use strnlen() on name fields in V1 wmfw files Date: Mon, 8 Jul 2024 16:20:52 +0100 Message-ID: <20240708152052.390594-1-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 80UGiJTZpRXp0rd6aaAHA3UiHuVIHDZM X-Proofpoint-GUID: 80UGiJTZpRXp0rd6aaAHA3UiHuVIHDZM X-Proofpoint-Spam-Reason: safe Message-ID-Hash: CNRI7EPF3KBF6OULPLSRMV7SEBAXVL4L X-Message-ID-Hash: CNRI7EPF3KBF6OULPLSRMV7SEBAXVL4L X-MailFrom: prvs=4919130c1b=rf@opensource.cirrus.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: Use strnlen() instead of strlen() on the algorithm and coefficient name string arrays in V1 wmfw files. In V1 wmfw files the name is a NUL-terminated string in a fixed-size array. cs_dsp should protect against overrunning the array if the NUL terminator is missing. Signed-off-by: Richard Fitzgerald Fixes: f6bc909e7673 ("firmware: cs_dsp: add driver to support firmware loading on Cirrus Logic DSPs") --- drivers/firmware/cirrus/cs_dsp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/cirrus/cs_dsp.c b/drivers/firmware/cirrus/cs_dsp.c index 16484ab9b09d..8a347b938406 100644 --- a/drivers/firmware/cirrus/cs_dsp.c +++ b/drivers/firmware/cirrus/cs_dsp.c @@ -1183,4 +1183,4 @@ static int cs_dsp_coeff_parse_alg(struct cs_dsp *dsp, blk->id = le32_to_cpu(raw->id); blk->name = raw->name; - blk->name_len = strlen(raw->name); + blk->name_len = strnlen(raw->name, ARRAY_SIZE(raw->name)); blk->ncoeff = le32_to_cpu(raw->ncoeff); @@ -1260,4 +1260,4 @@ static int cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp, blk->name = raw->name; - blk->name_len = strlen(raw->name); + blk->name_len = strnlen(raw->name, ARRAY_SIZE(raw->name)); blk->ctl_type = le16_to_cpu(raw->ctl_type); blk->flags = le16_to_cpu(raw->flags);