Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3347554rwa; Tue, 23 Aug 2022 03:18:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR5t5JT+WCMPPJK8YxkWuYXyRUYM5LunAmwgCRV4sFLhQIXamaNAH9UcKn5NdDXC/wAdUjVt X-Received: by 2002:a63:9142:0:b0:422:eb76:1965 with SMTP id l63-20020a639142000000b00422eb761965mr19766394pge.160.1661249892740; Tue, 23 Aug 2022 03:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661249892; cv=none; d=google.com; s=arc-20160816; b=pBkvgO22ZK7UfmeOaU4EYJsN0fMZ2tVh4ViQoAWx94m2L6zdEPD8by/3Wb0fNgthyk V81BMwr36ST4WAkVnzMQqa4djQuxhtR/TNOlr/FMWE2lqrx/DQAT5hFz3e7XMD4ColxK Aij0wtUtHPlIKUg1BPY7DU9sMVxTu8/OlAadaC/5YNUGcJADivPasDDTFAbMD7mWpY8X 8PmFTza2x4IUnZ+OWuhDIa+srhUl1yhokBmAKWfjKGXc2ZXDpIfgJkE8G+p8/MA4dRui KOB5Iz6AQBqu9csFAI32U8LckAVD1VhAj7A4i7ERoYZqcbGTcdJyjfJr5bBtFjt5n3IE 7d+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f5IO0V37nsCuFpHqfUQeLToBTs99U+/XTCkzurWooWk=; b=TJ7sLXOe8ln0FeEsib4zVyzcoonnmZZ5CCRa7ZvOzXsG7+OWVDUmAoahE4Ma7AIFVK KUP7ed8BU1IvRNTPbQRoKwj33mbRLCSFGHceoYuaPa5gorToRlaqTkwRvgOK90x1GuXv y+5EmdBF0GBlPgvd9so0sHGjN2jwWcdA/vpPp06wovEG4JD0KsWluUr8XIdPyJqPToLg aZ9DI9hGCWiBvN1aPoiVjebOOGPxCJyBxij2vg9dcoVaU+hmw1CofZlFgwfn0rhRCc9Q nBoRBeKxNmGJVKd5dwkKUnOEbaFxUGMEkPEPUpgzbKTgirO1Bdnb//ucsquSeOs9nW0V mYaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WEhtXVTA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a63d907000000b003fd31d844f7si15337193pgg.538.2022.08.23.03.18.00; Tue, 23 Aug 2022 03:18:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WEhtXVTA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353798AbiHWKP4 (ORCPT + 99 others); Tue, 23 Aug 2022 06:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352910AbiHWKG1 (ORCPT ); Tue, 23 Aug 2022 06:06:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7765411172; Tue, 23 Aug 2022 01:53:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 221B7B81C1C; Tue, 23 Aug 2022 08:53:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 845CBC433D6; Tue, 23 Aug 2022 08:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244811; bh=y2Uk6kUiCZrxv1Byz5ipE9DsC/gbpMLsnOK3xfZGDSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WEhtXVTATTJWd9gyKaVnlNiDWnb4wxNn9OCd0AEqFAoVbyfyfqc48PCtG/Pc+6IN9 oRTbfszIua9BRRpAMsjcrbthvXZsLPxekzG1emiAUMJWRduOroHIkv6fKGKGl4HOvK uROl5Hc1faL8EaEqYAmqXRl2fx1W+IwMqVDHCE4E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Mark Brown , Sasha Levin Subject: [PATCH 5.15 156/244] ASoC: SOF: Intel: hda: Fix potential buffer overflow by snprintf() Date: Tue, 23 Aug 2022 10:25:15 +0200 Message-Id: <20220823080104.402123475@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit 94c1ceb043c1a002de9649bb630c8e8347645982 ] snprintf() returns the would-be-filled size when the string overflows the given buffer size, hence using this value may result in the buffer overflow (although it's unrealistic). This patch replaces with a safer version, scnprintf() for papering over such a potential issue. Fixes: 29c8e4398f02 ("ASoC: SOF: Intel: hda: add extended rom status dump to error log") Signed-off-by: Takashi Iwai Link: https://lore.kernel.org/r/20220801165420.25978-4-tiwai@suse.de Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/intel/hda.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index e733c401562f..35cbef171f4a 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -413,7 +413,7 @@ static void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, u32 flags) chip = get_chip_info(sdev->pdata); for (i = 0; i < HDA_EXT_ROM_STATUS_SIZE; i++) { value = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->rom_status_reg + i * 0x4); - len += snprintf(msg + len, sizeof(msg) - len, " 0x%x", value); + len += scnprintf(msg + len, sizeof(msg) - len, " 0x%x", value); } sof_dev_dbg_or_err(sdev->dev, flags & SOF_DBG_DUMP_FORCE_ERR_LEVEL, -- 2.35.1