Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4125844pxb; Mon, 27 Sep 2021 09:54:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwnlNL5S7K7lU24ruhutyO4tkRc7QMZ8gE4jT+DmZIN5RfI0t/yKcZVo3l6Ulk5xFqNLyn X-Received: by 2002:a17:907:2098:: with SMTP id pv24mr1218531ejb.426.1632761687453; Mon, 27 Sep 2021 09:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632761687; cv=none; d=google.com; s=arc-20160816; b=lmVipVnFUqREBKf4zm4wpWEfAcJWXdseCWC4fCtLzRRMo+A+5HrcF6+ISc3tT1GHxi 4LuSn+FmSYWwkiVIy5rbwlEj5YbpS2M6Z/Tug2VOKftOh0A3BRRMoz89Nd21J38mGji1 sEfyj61R0I7P150jzMW+uIXKCbpO6gertXFIAr0WAxhQe71rIU7RrWcKLSHgi2julI9t xjaD+tOwT8iN6+mDNpHPk6fMV/VcAWN39VMWtNUhGC6u5A9b4FVRUxOiwbd4nF5iUYM6 fiu2tsOUdwru/+NEUFq/xmBeaIlwGT/QHG7ZMNBAlEfdR/iUby+AM45LbWHlvv+ucewu nJqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TIYpQ8TRXmbwlv5vcUv+AmTBjQHdc48qvKNzwC1i4rE=; b=ZRBi0cGhjr3lFefE2PXMHfXDtwbV+Bt5azZAypj+dT/DyZFxaNHn2+QVa1jHWHN1Y1 mNggMCmUCL6nX9+Z+dbUGUyKcWVQSArwlCmCIJuvk8xFA+/HnxgIClgysYXE4K4AE0Ke MUzINOM9/6jQQ2A6HMW5MBBfl3hWbRnoXmVWH2KkRv46qQPQ2Ha0f9qlUtU6DyzHQU2O 0aPC8Jn286D/nob3DOTahjoNcL58NvdoFcil8WCvsH3V6k/6KSAVyzgubBgMBgpIoU/n Cv5JSS62LkTs7+0GjAVBM/L3x6+B33L4YqE0E2DXEw2ThEiBeQT5eKJa3Jk8426R3Qfb 9Ovw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nMOEyLSc; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 23si17699208eje.280.2021.09.27.09.54.20; Mon, 27 Sep 2021 09:54:47 -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=@linaro.org header.s=google header.b=nMOEyLSc; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235656AbhI0QwO (ORCPT + 99 others); Mon, 27 Sep 2021 12:52:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235636AbhI0QwN (ORCPT ); Mon, 27 Sep 2021 12:52:13 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4388CC061575 for ; Mon, 27 Sep 2021 09:50:35 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id y13so25402874ybi.6 for ; Mon, 27 Sep 2021 09:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TIYpQ8TRXmbwlv5vcUv+AmTBjQHdc48qvKNzwC1i4rE=; b=nMOEyLScq7miHOdEzy1rJz8s5KNgr/zxqB09KCXh7y+ty5u4EcVMIwkm9H3M0UeDul RWpXGbf8SznnvMocTS+XDD8RdxJX7woW4dvLLtRP3AGQXMK7hxF9TUrG6/hr4BDFxHG0 Krk4pv+7qxXvR1Wl6QIufjiBTMD9Gq9N/B47S/Ms1q27vBPMLnr/BwkAilBVhX2cQ3Tw /ODQTOcL+0a+Su8SNfGPaomoBMqxojKHRVE71xRe1VBlDFtzfhQXBqQgPrmE0kPhJoq+ 0v4KcwK2TAzPzUf+tW2WvXVwAlBcr8bQx2IG9tJEst2pptW/et4UbctnpA+AErjIgH29 YWng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TIYpQ8TRXmbwlv5vcUv+AmTBjQHdc48qvKNzwC1i4rE=; b=BI+vwQvdsgU2NsVFhxMkTpFnuLC86H03/N3kXP9Hkhtcm/4QA9JSPOeQ8IxTnYEBmY bsLuqOl+XJxg/ypICNEyreE10MhoyeuTUHgntfia3XlZqiokNJeW2muHxvP2TDudh9jV THbigbDPY+qIPwC9oPGkzaGgpsISjxUMMXDb3n2QpgSUJ6p+/5WTh8mfBxMotIfwAB3n TM732/HvuNzWHBtY/64jwnUwW9uG6ZIjuQ5vbdkpgrj0dswtTe1bjBHHWMbdJ0TPKX/U xANsPng+4Lzn6L0ejArXC6Yxnwdm+EykexxJIb79iM4mfugjtWOEmwnSeX8SwJvJKO7O 4p6w== X-Gm-Message-State: AOAM530SUmGv0/f6mU0MaPuM4DaTDC/x7BLv+tgc6HkTEqPp09HXORTa Enh1mwoSGlBIkdiJIc14Oflxlm7Rj87A90Z/uI2ZHg== X-Received: by 2002:a25:9011:: with SMTP id s17mr919651ybl.61.1632761433793; Mon, 27 Sep 2021 09:50:33 -0700 (PDT) MIME-Version: 1.0 References: <20210927114635.GH3959@techsingularity.net> In-Reply-To: <20210927114635.GH3959@techsingularity.net> From: Vincent Guittot Date: Mon, 27 Sep 2021 18:50:23 +0200 Message-ID: Subject: Re: [PATCH] sched/fair: Null terminate buffer when updating tunable_scaling To: Mel Gorman Cc: Peter Zijlstra , Mike Galbraith , Ingo Molnar , Valentin Schneider , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 27 Sept 2021 at 13:46, Mel Gorman wrote: > > 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 Acked-by: Vincent Guittot > --- > 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; >