Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3292757rwa; Tue, 23 Aug 2022 02:08:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR51qB+o6inoMWY705FaNBQuulq8XCC+BljuHpdJh+NeygLUNzCN40fZvWSr6Ylj3PHxHRP1 X-Received: by 2002:a17:907:2e02:b0:73d:7c00:d795 with SMTP id ig2-20020a1709072e0200b0073d7c00d795mr6603328ejc.562.1661245692414; Tue, 23 Aug 2022 02:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245692; cv=none; d=google.com; s=arc-20160816; b=yHwVYXbe+xKMmLydmCSNQgC5oD1EVSthTFBlCsiihdlso/IkHEjy4kMvVbX85JoxSm XT4orS+m2r8lXpDEnIFR5ZOl+LDguzB58wlNNnnDu0LLmJs5qBAPTfBPX4CBipGZQHeF hWroQgF755xLEy9nWNTX9BDWZMx4R4EaBiEa+7Xn5smuXVnHlNDhE+3IkgdT42wMC0WF tkKsV22I0cVG2NzvEUggm6+ktDdHYYY1j1+9kXghi8R67ReXgNu+OLyX1RcNdK9Q99qE 9+R0k9ubxyWfqSeYGGwLkAlfLD8PE0dbPZXxSMFbcKlBkjmuNVreNjg1cVZL9iHDT+R1 s3jw== 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=vG5ZAH9SCev2OT0b2RHSpnER/GCfyX5ZAMvYpO1pC6M=; b=ipMtmzgAQkxHb3lHcTylm7SnYP81a0UljHpmCxKkWK6vZ/in3elvh0n0Zm7BKjlhvO z6LprgkYTIWXNI97qJMjGWu2HSktxqCoj8RBV8XVVlB2vuVEEEq+9odDhBkdVlOr4uS0 4ZUPj6zAxFxI3o8fpEBDxMpBCk0mHt0+lqIdhkgwvLRF/9t1SSSIhK7NOobztoJ0YA05 L98UzCwquQjFQB0cO/LuHBGZ1kK/XBcd7vUutuH20XvjM12oaNRaFu/CuOJS/rsIZKxf d3DpIF6aprBKaLqf/CluA2NxBC4hzPcX/w+9mEffkFnPgS2yhdUcFmkknfJoDfESCzL9 5ohQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xAEnkw2U; 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 hv13-20020a17090760cd00b0073c194e99f6si13631715ejc.779.2022.08.23.02.07.45; Tue, 23 Aug 2022 02:08: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=xAEnkw2U; 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 S1346996AbiHWInP (ORCPT + 99 others); Tue, 23 Aug 2022 04:43:15 -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-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 @@ -252,9 +252,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;