Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3963734pxb; Mon, 4 Oct 2021 13:50:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz38TQLIrpgvi4y5p2vOQV4Q1dXEZe2UebjaB+LszOJCj439x7rcGgctClrrmp2oJ5PxS26 X-Received: by 2002:aa7:db85:: with SMTP id u5mr20310777edt.234.1633380643147; Mon, 04 Oct 2021 13:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633380643; cv=none; d=google.com; s=arc-20160816; b=eolLi2tZ/kzKRAReHVh+cbXzD0OiIPslfpS7C8J40nm/xdLCqe076iC5Z+cFFoS9Az 40xTk9lb9nvOgiP/flxkXoJoO6xkIWnS9YsgPwA/349diwxCCA22Z2fgTMUBAbn+2gv4 LyRWaVcp03esKcCa3STFf8pPklBNmBAMrvQxVMcvW+iWeuMszHjgutJYBgZTO1UpJJU5 P9oMO5uayriCn/BXvRLM9wJrbm7pavhj60gC4uyDNxqbo0NT4N1P3JjNqK8Ii+QagW61 YxY/w3g98s4uVQdbpZgMps0siTHvuAdZU7YFd3vOHqBcmbN+zsOz8yVSq/26X0D/yUY6 LK9g== 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=FIxjO79OYFTsKJU+p87WRiPvw1FCXXEfqXU0RsyPXO4=; b=O3xKaaRGOOZsrbEvWXv9EpVfQAS6NKqBKLnfbc/EUndM7Y+1SexHe6GG3M5LZ6C6bm 8Af390YwRAfxsCyJV4WMOEVXmGedr3PARkTPTkqn5smTMpA46+zzilUMeqGYw6oBSZbw 57uOgMeoD2P4osdUoVj92WTjcY7iDJFvUMCwE+La+MX4LLLH+Z6JuWM5qND0g+EDwGTY HZptlgElaFKiOVrjQWTG3jGlABNoff42Lo42zpHa0z3hSqicmX5QmL+j6i3uQMDKbW1z RHqSnuGVNXJqIrqXJ6VVo6Kz3UhrEMk8mt7p2+qDyA1x4cRlwg/yncWcyysNTYwnMXED VS+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GM28vPJi; 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 nc28si234796ejc.499.2021.10.04.13.50.19; Mon, 04 Oct 2021 13:50:43 -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=GM28vPJi; 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 S238560AbhJDNkn (ORCPT + 99 others); Mon, 4 Oct 2021 09:40:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:52272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238546AbhJDNin (ORCPT ); Mon, 4 Oct 2021 09:38:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2E42063244; Mon, 4 Oct 2021 13:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353466; bh=QP6nuaR1+mibQHUtOSz7uF/n+aPPer/THWb1NdvRCiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GM28vPJidOfX97HBD3ina9Z+ClR39tWGoQJrbA7w0wP03O7T5QZ5UwvruPnoN7opw nv93O0OORWh5PsW2k7g+Ki6JiI0yL3kM9h2Rvg16P6B9UEE/x62fLo43S//RMXOsy/ 4uLpQFKwMAvhZAzA66DadHhJJ/OCDfQIlYKssFD8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mel Gorman , "Peter Zijlstra (Intel)" , Vincent Guittot , Sasha Levin Subject: [PATCH 5.14 140/172] sched/fair: Null terminate buffer when updating tunable_scaling Date: Mon, 4 Oct 2021 14:53:10 +0200 Message-Id: <20211004125049.493620907@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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: Mel Gorman [ Upstream commit 703066188f63d66cc6b9d678e5b5ef1213c5938e ] This patch null-terminates the temporary buffer in sched_scaling_write() so kstrtouint() does not return failure and checks the value is valid. Before: $ cat /sys/kernel/debug/sched/tunable_scaling 1 $ echo 0 > /sys/kernel/debug/sched/tunable_scaling -bash: echo: write error: Invalid argument $ cat /sys/kernel/debug/sched/tunable_scaling 1 After: $ cat /sys/kernel/debug/sched/tunable_scaling 1 $ echo 0 > /sys/kernel/debug/sched/tunable_scaling $ cat /sys/kernel/debug/sched/tunable_scaling 0 $ echo 3 > /sys/kernel/debug/sched/tunable_scaling -bash: echo: write error: Invalid argument Fixes: 8a99b6833c88 ("sched: Move SCHED_DEBUG sysctl to debugfs") Signed-off-by: Mel Gorman Signed-off-by: Peter Zijlstra (Intel) Acked-by: Vincent Guittot Link: https://lore.kernel.org/r/20210927114635.GH3959@techsingularity.net Signed-off-by: Sasha Levin --- kernel/sched/debug.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 7e08e3d947c2..2c879cd02a5f 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -173,16 +173,22 @@ static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos) { char buf[16]; + unsigned int scaling; if (cnt > 15) cnt = 15; if (copy_from_user(&buf, ubuf, cnt)) return -EFAULT; + buf[cnt] = '\0'; - if (kstrtouint(buf, 10, &sysctl_sched_tunable_scaling)) + if (kstrtouint(buf, 10, &scaling)) return -EINVAL; + if (scaling >= SCHED_TUNABLESCALING_END) + return -EINVAL; + + sysctl_sched_tunable_scaling = scaling; if (sched_update_scaling()) return -EINVAL; -- 2.33.0