From patchwork Mon Jul 8 14:48:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 811198 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 6765FC3271E for ; Mon, 8 Jul 2024 14:49:47 +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 1BAB884D; Mon, 8 Jul 2024 16:49:35 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1BAB884D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1720450185; bh=z781XFgAu6Gb7mSdPzePCv03ZyJcZhjXm/dGiLnhcXQ=; h=From:To:CC:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=iCBZr57ypm4l4EZKaGDjGVnd4w/O9TiGCwOMZwjtPN5kbjoXt6nRM1IhHKzK9PSp2 0RvDcFliuZvtMzinyriEeb5AvHQFPcBEeE1wz/BMNVDYb5K8nx030xwUJmLzCeZ3jP KA7z2MHAUwTEnMF4frj7FjF9eF/wNYTAX3cG/5zQ= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7A97FF805A9; Mon, 8 Jul 2024 16:49:13 +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 2755AF805A1; Mon, 8 Jul 2024 16:49:13 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 83101F80494; Mon, 8 Jul 2024 16:49:06 +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 0246DF8013D for ; Mon, 8 Jul 2024 16:48:59 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0246DF8013D 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=p3UlSIKo 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 4687RE75025730; Mon, 8 Jul 2024 09:48:57 -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=EI1gyBEUL/L/gMbK lNgm8TuixCJBNXmQ4JPs9SARDuw=; b=p3UlSIKoPCsxGT9w2op8UkULnqNufwjW rrlDC2Eq+ozuxGf5sWK7UCP0ltfXWQCrTmhbjyye8vH1vKkRk3CMGDltnUOEye/g QjYdWsdGxdZcVGn4f1K4+3zD+juLp3TDc03vL/2Clt4QEIy+dSngo5qedz01i5lw iKgN4hXSYNTaeCQGa0GmkiIulz8L90BdNYrhQ2xsLncEFKsfQLmIvxRr6ZV789xD FN1ForJWq6BSmBIv6QZoeyUlEa0p4ae2mglg5Yh4ClAdouiCDrWj6vM7Cfumvd/3 dP1VjJAQum+6mhrCPCkaC8l0jm7NBpS15rJ1MYbBigOnD1EkDLDCyA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 4073axsm0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jul 2024 09:48:57 -0500 (CDT) Received: from ediex02.ad.cirrus.com (198.61.84.81) 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 15:48:55 +0100 Received: from ediswmail9.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1544.9 via Frontend Transport; Mon, 8 Jul 2024 15:48:55 +0100 Received: from ediswws06.ad.cirrus.com (ediswws06.ad.cirrus.com [198.90.208.18]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id 13578820244; Mon, 8 Jul 2024 14:48:55 +0000 (UTC) From: Richard Fitzgerald To: CC: , , , Subject: [PATCH] firmware: cs_dsp: Use strnlen() on name fields in V1 wmfw files Date: Mon, 8 Jul 2024 15:48:55 +0100 Message-ID: <20240708144855.385332-1-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 0EfxtVBMUaeoF8YGw4iXUuD0UUPjf5u2 X-Proofpoint-GUID: 0EfxtVBMUaeoF8YGw4iXUuD0UUPjf5u2 X-Proofpoint-Spam-Reason: safe Message-ID-Hash: YOEZ64BALPDVUG7DDBQL3D7GBBGOJQO2 X-Message-ID-Hash: YOEZ64BALPDVUG7DDBQL3D7GBBGOJQO2 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 d2aa0980ed78..0a504a3c4375 100644 --- a/drivers/firmware/cirrus/cs_dsp.c +++ b/drivers/firmware/cirrus/cs_dsp.c @@ -1166,7 +1166,7 @@ static inline void cs_dsp_coeff_parse_alg(struct cs_dsp *dsp, const u8 **data, 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); break; default: @@ -1199,7 +1199,7 @@ static inline void cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp, const u8 **data, blk->offset = le16_to_cpu(raw->hdr.offset); blk->mem_type = le16_to_cpu(raw->hdr.type); 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); blk->len = le32_to_cpu(raw->len);