Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3343394rwa; Tue, 23 Aug 2022 03:13:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ZTP7X4CnSlLPME/S8rpEqfU84e2xPD2zYykvRaSr6C21+s20HzXV6HzMF1FEmsjkDoh3d X-Received: by 2002:a17:90b:4f45:b0:1f5:6554:d555 with SMTP id pj5-20020a17090b4f4500b001f56554d555mr2638263pjb.226.1661249610539; Tue, 23 Aug 2022 03:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661249610; cv=none; d=google.com; s=arc-20160816; b=Nvw2ZkQp+7zDid/yjuXtFsfbqn43m5Ks4rurfRyP2+2LK1KxDjrMv2aWZS9LV1Adp9 +2mSiL9WSUapqvPvRzbCZrI1oGZSlOob27OQ8kHjZdOHk8GueS1dDQGdtRLjFE5bRaI4 0dDl5070dLc4pm8yw6+cjQt3Q0F+3sT3CD/B/JhsxKtKwF6Ens1ixr+DuVlnnIXCmnAV y48nNDSqixD4I2M81feYnKu5HOeM716lYZRMyCWZbNh/lMrdiS4n0HM3UoVwA9hg5DTs 7j7TDWNpy1l1ux1S3+IKqMrowf/kgCocZAWdYKIHAql+GP7REghrrmgPjm184zp8gVQQ r6Gg== 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=o2uh3qe5wAzlHJCkieJFktMPrLvLSOhYCohlYlcz3LY=; b=KhX7g6+vllk2NSxhAs6evLefYq6aPtE20ZXhcmeyxk1nATMguLjXSsWcbjgDL0e77t tyiddmJvF7n8vRU4UKpGdS7augLpcXOV9HMj5zTB6uFYtyACyx6F2512rkaTPv939yJY cmzUClXRYCYY3p+JUYyH7TBrX95Ji66kNCd85q3s2pB9SQ+jU0ZbMClrJt1iUUgWN1Ld xNfxF85mJ+9cCazP9xN5V9AVEc7brQv9+C9SCZrQf/jJIX+iPiSsNWpGvIKh7ZT9Yv6X 1SaJshPYNVURQ9xwGlenBlrJwsoasUQi335qV/gu6CzIiXrz/HMsRLh14VKBSFfWc+0U Qzjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C4xfycDG; 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 y8-20020aa79e08000000b005366672c76csi8500296pfq.205.2022.08.23.03.13.19; Tue, 23 Aug 2022 03:13:30 -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=C4xfycDG; 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 S1353510AbiHWKLf (ORCPT + 99 others); Tue, 23 Aug 2022 06:11:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352171AbiHWKEh (ORCPT ); Tue, 23 Aug 2022 06:04:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C155C7CA8D; Tue, 23 Aug 2022 01:51:36 -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 4E09BB8105C; Tue, 23 Aug 2022 08:51:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD9ADC433B5; Tue, 23 Aug 2022 08:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244694; bh=9nBzl6UABDLghwFHO1nasarlpDPMZDFE+Q6xgbY2Q+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C4xfycDGUCypPdc8uEFQtUBU9anyXuLbMtaWcje6ovlMzEH3ZVmHjDC5M1kib+w5v n2JRYPiyDUOb5FuMrAAMqyLsllvGQCiukKR38n6QkD2+47TCVc0A4aH+grsJSIhX9H bxwxXfOaqWhS2O5mXBnEfEyOUDMgJECwtV2/10Zk= 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.15 117/244] ASoC: SOF: debug: Fix potential buffer overflow by snprintf() Date: Tue, 23 Aug 2022 10:24:36 +0200 Message-Id: <20220823080102.925360091@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 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 @@ -668,9 +668,9 @@ static int memory_info_update(struct snd } for (i = 0, len = 0; i < reply->num_elems; i++) { - ret = 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 = 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 += ret;