Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4154591pxb; Mon, 27 Sep 2021 10:30:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsu83yzoWG15bvInqCoNbQIwvxYbXW+Kio3Nj1dEH1Oyav9y519519iV6sulC6ZRI4i1eN X-Received: by 2002:a63:33cb:: with SMTP id z194mr726355pgz.380.1632763803942; Mon, 27 Sep 2021 10:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632763803; cv=none; d=google.com; s=arc-20160816; b=knQf6RRuFdebhxDosaArfk4XmRkQLSFqkMkpJKfFh3iTi9l7Q8U7fzSSpReUJIwxWO UmKTPqAKDCaEcRql9oAiXvTAZ6JGwxfieYhtUM7iDCJ0UvKQRJCgzckKyIiy4Emtc9LH YkOzvT2HKJ/zwHJQj26FCcKqGdDP+YRf6LlplmyzSOrDgxfkaPK7yRNjXWGoZ0gGfXdt RjFhWaHFFiH2lT7dugQf+4VJtdjSW7A6HH6LAU+GWpvwxVwCuOuhEdd9F/GQXZ0IOtrL L3BHlt3CBoswzZy8xIGCAhXVooCKDAHtfsVDpPeFlIqvTxGN8iFD/uVHV9ygre7gkGmB rOyw== 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=5R7ru/ptaO//gPJIPR8miDAhjpvm19jY6EfspWqRIEM=; b=ZTEQHyyULGiOWnqNLvlbw9D9R+uQt4Lvx0AVzlfO4ukZEW4xWDlrTBk4o32lbnpfrN HjEIauCSNZSDddmRk1u6srUVyRKUfgDIrGSWaC1eV6hY3OSgYYMhHoaqHl/DHfxHuVF/ XYvmNDB5cN9vC1/UpmRyNeG6oi76V7ZrlxB18HDDoah+jj3qPQCOVOLDFAYWCly0d/n+ JCHQ0hUlRj3N37wAxg2PDdK9s1SqKNDrC0zIg4eyMcHmLiFysfF1ZICtg/MfP2YlDKYg qNY1G9xRTxVX+KBsWebuAB1DzF92fN3Un0tdEtLzjwBUFaSejEr3mzm+uLN5QbvTjKlD rgMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="xrKhC9/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y67si11204706pfy.284.2021.09.27.10.29.50; Mon, 27 Sep 2021 10:30:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="xrKhC9/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237739AbhI0R2L (ORCPT + 99 others); Mon, 27 Sep 2021 13:28:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:41376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237893AbhI0RYB (ORCPT ); Mon, 27 Sep 2021 13:24:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9193B613C8; Mon, 27 Sep 2021 17:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762917; bh=M5gpKuARtFe9V4AjmZU4muHT5/fSXcGFswy7yPukRvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xrKhC9/K4f7C/jY2e4czrKUutBHcx8T73s/Gh2ioqbUlN8aY2WZknjDzsg55mTs+M hK+NtPJ7Iuh7H+ZeIUhsEhSkh/o2rOqhPYQotArWwcoL6WdL5kcuguaQ3EgicxKCn3 dsR/6RACDMhdMsMa8lPQ+7GSCXLzNmgUTJ8qXSgU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Daniel Lezcano , Sasha Levin Subject: [PATCH 5.14 100/162] thermal/core: Potential buffer overflow in thermal_build_list_of_policies() Date: Mon, 27 Sep 2021 19:02:26 +0200 Message-Id: <20210927170236.910960528@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170233.453060397@linuxfoundation.org> References: <20210927170233.453060397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 1bb30b20b49773369c299d4d6c65227201328663 ] After printing the list of thermal governors, then this function prints a newline character. The problem is that "size" has not been updated after printing the last governor. This means that it can write one character (the NUL terminator) beyond the end of the buffer. Get rid of the "size" variable and just use "PAGE_SIZE - count" directly. Fixes: 1b4f48494eb2 ("thermal: core: group functions related to governor handling") Signed-off-by: Dan Carpenter Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20210916131342.GB25094@kili Signed-off-by: Sasha Levin --- drivers/thermal/thermal_core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 97ef9b040b84..51374f4e1cca 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -222,15 +222,14 @@ int thermal_build_list_of_policies(char *buf) { struct thermal_governor *pos; ssize_t count = 0; - ssize_t size = PAGE_SIZE; mutex_lock(&thermal_governor_lock); list_for_each_entry(pos, &thermal_governor_list, governor_list) { - size = PAGE_SIZE - count; - count += scnprintf(buf + count, size, "%s ", pos->name); + count += scnprintf(buf + count, PAGE_SIZE - count, "%s ", + pos->name); } - count += scnprintf(buf + count, size, "\n"); + count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); mutex_unlock(&thermal_governor_lock); -- 2.33.0