Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4145083pxb; Mon, 27 Sep 2021 10:17:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp6pwTFtgIv+OKys2U6k3DppWmbYu9dqERohD50m2cRpWvP6ptKwuNtT3NUR2RQG53xO8z X-Received: by 2002:a17:90b:4d07:: with SMTP id mw7mr239012pjb.66.1632763078419; Mon, 27 Sep 2021 10:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632763078; cv=none; d=google.com; s=arc-20160816; b=wa865/zmZmXTZhtXp3xwGzQrh+lsGIsPQtzHcvjqsnhh5tRGMrY2ea/aJxvyBqWSlz huweMLlBvKz9GvI4KyXfjTKeA6FIF2ySM/64hdG/l1Zu1SRJJWgXeTWRus1CiAPoI/TN Pimrd6b/ukOgbcp6EgrES0WQ0/DgCVnetr4rTa8C/AVH34f2goBBBniOsASi5uNiM3xN +yoV8va/Oij+YkUrYuGmaxP1AUGPE4aE//z270oEZ7oh8oFnOnq1q/5Cx8krTqBCnnvw PUX4VgSpkHYN3G1PSvnYMOieV/UF8o7po4Tq6imy6ALOxucLS2gWKN5R19ApNPTTcC/G l23w== 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=ezmKN0OJShep4JgRtjFeI8e4rbnl4dWDTz6IUKoAg3M=; b=hTmJpcYKuTYVAarMPXCYBf+XvaqtLDkFVjm49p5W9ysX4dPNPzLdxeB9aPD71eyZO8 yKlQt0wCXMybqjHaFAtQZPLKwQIiBHa8qdG/q4JbP6chdf5Rb3E25VtwXxXDJ3iRAkAI sfhEVAt61kk3/BwK/2VZ+IICMTbHOY+pDDPnx+BpkRsL5FuSww20TJFGRXbrd3mxiIWw rNiMl0QOC5fzUEQT1O925QffvTJf7KowwIUpjlLkNIpyzX1IHNPFfaTqOVsocS7i9v0N 8HJGLrWXBwfMeTpPkpqp7MUC3F4Xg9EAxpy6zPlq9hbnTZ0QOlZDZays8xva+7XtIV8t BDtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2k2QIe96; 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 h193si20995794pgc.497.2021.09.27.10.17.45; Mon, 27 Sep 2021 10:17:58 -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=2k2QIe96; 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 S235660AbhI0RR5 (ORCPT + 99 others); Mon, 27 Sep 2021 13:17:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:56358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235871AbhI0ROg (ORCPT ); Mon, 27 Sep 2021 13:14:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4447D61362; Mon, 27 Sep 2021 17:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762625; bh=DBHRgJEr/2D6Bw5rELvKRtFWdt7jdM6yQlWdM3okMJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2k2QIe96Br/u72rJlg8MpXcqxPDW4VWRplZtzd+g8BOzkmnH0aQK0SpmcNco8Qu0S JItRMLwafvwMclQltyw+nccSmSJENUpznaD2GNz7J9Vqbw/SiJUGkyDD8SU8uhX4Th /dUz4s3WYJ9B41DqxO69zCxn+b0p8fQey6nbjD4Q= 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.10 062/103] thermal/core: Potential buffer overflow in thermal_build_list_of_policies() Date: Mon, 27 Sep 2021 19:02:34 +0200 Message-Id: <20210927170227.922523104@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170225.702078779@linuxfoundation.org> References: <20210927170225.702078779@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 e669f83faa3c..17de8a9b991e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -224,15 +224,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