From nobody Thu Dec 18 13:02:08 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5721C32772 for ; Tue, 23 Aug 2022 08:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344374AbiHWInQ (ORCPT ); Tue, 23 Aug 2022 04:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348619AbiHWIln (ORCPT ); Tue, 23 Aug 2022 04:41:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05EF67A76F; Tue, 23 Aug 2022 01:20:01 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9F6A861388; Tue, 23 Aug 2022 08:18:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEDC0C433D6; Tue, 23 Aug 2022 08:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242713; bh=P2NEBc2H85qsMBFTU4JMsHFgSL2p2zn/OeqE9orNI9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xAEnkw2UqIFg4BI044cT0DN1y36YCvyNR0/4FnhwC14sH4I3ozT2BQWZRNYTw62SY C8Q6+aO5npw5id+X3uqtdZzWcRt3vumZmPLta4ITOwHpBpZ0GAQYYeyAvM9obdtcIH bWOwFtQS2fHBARRgFiAe6HglWauZKaDFpnm7RZWE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Mark Brown Subject: [PATCH 5.19 177/365] ASoC: SOF: debug: Fix potential buffer overflow by snprintf() Date: Tue, 23 Aug 2022 10:01:18 +0200 Message-Id: <20220823080125.626228574@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Takashi Iwai commit 1eb123ce985e6cf302ac6e3f19862d132d86fa8f upstream. 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: 5b10b6298921 ("ASoC: SOF: Add `memory_info` file to debugfs") Signed-off-by: Takashi Iwai Link: https://lore.kernel.org/r/20220801165420.25978-3-tiwai@suse.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- sound/soc/sof/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/sound/soc/sof/debug.c +++ b/sound/soc/sof/debug.c @@ -252,9 +252,9 @@ static int memory_info_update(struct snd } =20 for (i =3D 0, len =3D 0; i < reply->num_elems; i++) { - ret =3D snprintf(buf + len, buff_size - len, "zone %d.%d used %#8x free = %#8x\n", - reply->elems[i].zone, reply->elems[i].id, - reply->elems[i].used, reply->elems[i].free); + ret =3D scnprintf(buf + len, buff_size - len, "zone %d.%d used %#8x free= %#8x\n", + reply->elems[i].zone, reply->elems[i].id, + reply->elems[i].used, reply->elems[i].free); if (ret < 0) goto error; len +=3D ret;