Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3876805pxb; Mon, 27 Sep 2021 04:48:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySj3XfCm/KH2qT3wfUbx/9BOlglP5zfso9JLykyyPIRFKEN3++nkirj8g4cLpIZnCtvPNN X-Received: by 2002:a50:9d4f:: with SMTP id j15mr23238261edk.68.1632743320444; Mon, 27 Sep 2021 04:48:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632743320; cv=none; d=google.com; s=arc-20160816; b=iEex5hjnw4tk/JdsLR/DwFjvcSrfjRLEg88GY1ni8OSnlZfRjiYq3TWn8hCmzwF/Cm 5XRIGNd+wd5INwbcBKGtGZha9/YQty9uORW8toZm05tT7Plbmo/6ogPwMpL6QRrecpR/ /mKkNx9kXtcI0oLb+hCDzveeqoQJ8Y82Cjr40BKiV9TgSWH9Abi8edd/NDcOUbecN/4i gTBoDseZaHvqtH1AF5T/yArOk5TeMhOWjHclZ/oAJvgpkM0XvzvcC7S5G1SxTTvYL0NZ QTYymCEdioOBLGbZZRWvrHsnL2MXBpf03SA2BujB3b1Ore9Y6qWb66KkdEtfhKZZLDzt SHBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date; bh=uJoBiaQKJISI5Jda+ZGxSsyCcQ1lzk2FQ4BHDbcIy70=; b=yeSc/WfooqZach85TLVe3ZxTn2//4cWATPav+r1mLDJZtcOzttd93wOdVM6u612GuS qwz3q3ayTRPQ0kv2PutXdHc7DVgRWo2UJlEzRx3ggGZALItI5VxELbWIiEBNheqB2xgu K6ufJ7OMJLjcD8mhme9FZZu0ECRA7b4wMr/v9BXxgeUdPa5apP/yDVSv6HaZ5uN8VquM qBb/wI8oZbOdXaZUw8p5s/Gwc7YWRasAMQW9P6ytnHEmuNA1ZFIwowvfN5muLv/5500g 13VnH4vI9JTLH0A2nUvg3rE2z8Fn0lK0g9A9aG5a2/A9w2E0ZMU19KHb47u/Dfrt7B/i wAnw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh20si18270332ejb.234.2021.09.27.04.48.16; Mon, 27 Sep 2021 04:48:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234067AbhI0LsS (ORCPT + 99 others); Mon, 27 Sep 2021 07:48:18 -0400 Received: from outbound-smtp37.blacknight.com ([46.22.139.220]:44651 "EHLO outbound-smtp37.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234146AbhI0LsQ (ORCPT ); Mon, 27 Sep 2021 07:48:16 -0400 Received: from mail.blacknight.com (pemlinmail06.blacknight.ie [81.17.255.152]) by outbound-smtp37.blacknight.com (Postfix) with ESMTPS id 3AD871B02 for ; Mon, 27 Sep 2021 12:46:37 +0100 (IST) Received: (qmail 12512 invoked from network); 27 Sep 2021 11:46:36 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.17.29]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 27 Sep 2021 11:46:36 -0000 Date: Mon, 27 Sep 2021 12:46:35 +0100 From: Mel Gorman To: Peter Zijlstra Cc: Mike Galbraith , Ingo Molnar , Valentin Schneider , Vincent Guittot , LKML Subject: [PATCH] sched/fair: Null terminate buffer when updating tunable_scaling Message-ID: <20210927114635.GH3959@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 49716228efb4..17a653b67006 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;