Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4137397pxb; Mon, 27 Sep 2021 10:08:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfnOzdRWrXMUz9tq48T/Uo6Lb6m3zj5Gf/os7GkPwakz4cbIo592TtUxOK46l415GHaNgA X-Received: by 2002:a63:c10b:: with SMTP id w11mr662128pgf.228.1632762524865; Mon, 27 Sep 2021 10:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632762524; cv=none; d=google.com; s=arc-20160816; b=JwwwEBBkaHhVZi9xwwTcDcNdyOOkOAwM+hvFP23wZK9xV/KmuLng/E93cEe5ZDFirl QMYaI/DEhMrjRp0Sog+aLK1CfqQyx3fXxwgkvEPOos9Xx8AZfoo1+hGVNllCNNTg4U0K QoiToOLRVHrVk5YP8l53X+HQmIKmtWG564T+JtzAO284tuHOU/MdUNXlvxS4BO6OPI72 9iYUyXo4rLzVQ1e2pNglf84JDLudWzadX4ciFmVEq0lR29sWQd7KlT2620JE7R4WZkUV Ci3mn1Nm2DYIR5HYB/yNy7zoI2cCweMCJd4+JMLH5piOLPG3fJE2SePynYLvDQ9SW+gU yvVQ== 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=H5qMcb8R5o9feGjv9V2ICnFEBfKJt/bC7soOAN+gFTo=; b=vmBBBgBi0Z2lS9GbA+2mmDHOfbb+XA5/O2EwZ6BKfm2QGM0F0lA+lVLMk9g8oU6q/x fxbed2hxuUz5pI8UYy6gUy9rb7GuGMHw8U6cabXcao9rtpIwJsFOLHzyLhcGNqai+di9 RPHTt0HeKUNgj0PYByCaxES4sPWANNYyhM55JIiu2DGOnum4fLPrXq+okD/AIMpd4Wva 5y5pFtOOgQIGqlX/S316cWj7phZH2SCM2rFpEWmgWEMausihOBJGZwjDTVN6RYBBsHC8 a23EomMVQmFS209Y06MMlYLcUNFFEj4XRVeLTttbWxNQuLMupx6UQPfB/2PrcM2gr1KO PzEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x3fWCjlB; 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 t16si99982pjt.37.2021.09.27.10.08.31; Mon, 27 Sep 2021 10:08:44 -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=x3fWCjlB; 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 S236141AbhI0RJT (ORCPT + 99 others); Mon, 27 Sep 2021 13:09:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:48546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236313AbhI0RIB (ORCPT ); Mon, 27 Sep 2021 13:08:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 19A7C61206; Mon, 27 Sep 2021 17:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762383; bh=nZzdwmBTTzIKwoK0VaxsvIWM7tsM9iZiIYzeTDcxxyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x3fWCjlByysOe08mMxcuylOskPmUfqOr/3IyijdXU5Q7Kz2a+FRaH2qP4M+Xt+cU+ mtke/ygBoINLfBzwQPK3ixMI/duhmJ4j89UXX7Emewm7QIjwI1R9iMAOv7O+RupyWx 2G6Nyl9X6GLpYzqodeAz7QYpM9v2MI8fhgH1nAcY= 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.4 38/68] thermal/core: Potential buffer overflow in thermal_build_list_of_policies() Date: Mon, 27 Sep 2021 19:02:34 +0200 Message-Id: <20210927170221.290193517@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170219.901812470@linuxfoundation.org> References: <20210927170219.901812470@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 f526ce31f5a2..20eab56b02cb 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -228,15 +228,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