Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7130071imm; Tue, 28 Aug 2018 06:57:23 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbKzkcZ/uNTIU8KuFRBDoMZj2PM3e1LHPxSHoZe5iP2W4Ieyad63porK222xoN9B6aVnSZy X-Received: by 2002:a17:902:ac1:: with SMTP id 59-v6mr1737852plp.18.1535464643337; Tue, 28 Aug 2018 06:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535464643; cv=none; d=google.com; s=arc-20160816; b=blFru6pee8oO/n+I1ZNZJW3X0QSXG789afTAT/2dUWMFAjc2d85Uznow0n1hVfXET8 9o4doXSKJ6awOYTzhfCGWutKJ7Zcw1vh0DJw+RySScCjmaEOmS9FMFiqwrTuqEfe7OUs Agl1S8bQMwseQd0wJX6qg+oz1lGxIb/Ea8tBzi9YBhfP7gIFHs85lVR857pIwM2cDxW0 +vEFs00kf63vth/p8qN/HFvt3Uy6+iQ2+Tf8kWCSksKuAiJrgDSh7rbz6aFTCRSbRcXS Gp4YDa17UciOqbeJ3WoonQdtAP7Udad4u4SghmEzq9TAzcOwvVmzcdD73P68DtNE+BPl FqMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=ab0s3zvejnmJfyeKzJvgSIoA8iMErkTqVmd01+ovXLI=; b=ChH2T72udVG1gHMSzXLasU0YmGRc+d/Ki73VDa6x0IIJtresUFxmBbVL6ws9DW0zYl I9rAYzGMS8TCI72iyhAEtXv4i/YWFQI9BxEpNnM2zqTC7rUdMgktVUXJfX9cgz0R18kI cFtsPT96GahEQ2eKH6CJEafJU7UePuMRCzvlh+rNioqW/MBEzp0wDWzl3DUUZpFS6/IA DIdUFt5wT2hEO0VYnavo/ozCfsU6OM+HgBkzhbhhPRXn7W2mJRJOPCDNa5FwxZvIKpyl RNiSnyj+IE7bHIKF54gaodaUK4JerBE2UYpCsFilJEzpm5e00lLjYrrTazVAPNREP0t2 d6pw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13-v6si1087412pfd.319.2018.08.28.06.57.08; Tue, 28 Aug 2018 06:57:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728350AbeH1Rr0 (ORCPT + 99 others); Tue, 28 Aug 2018 13:47:26 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:38676 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727706AbeH1Rq7 (ORCPT ); Tue, 28 Aug 2018 13:46:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6AF421AED; Tue, 28 Aug 2018 06:54:43 -0700 (PDT) Received: from e110439-lin.Cambridge.arm.com (e110439-lin.emea.arm.com [10.4.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 796633F5BD; Tue, 28 Aug 2018 06:54:40 -0700 (PDT) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Tejun Heo , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: [PATCH v4 14/16] sched/core: uclamp: request CAP_SYS_ADMIN by default Date: Tue, 28 Aug 2018 14:53:22 +0100 Message-Id: <20180828135324.21976-15-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180828135324.21976-1-patrick.bellasi@arm.com> References: <20180828135324.21976-1-patrick.bellasi@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The number of clamp groups supported is limited and defined at compile time. However, a malicious user can currently ask for many different clamp values thus consuming all the available clamp groups. Since on properly configured systems we expect only a limited set of different clamp values, the previous problem can be mitigated by allowing access to clamp groups configuration only to privileged tasks. This should still allow a System Management Software to properly pre-configure the system. Let's restrict the tuning of utilization clamp values, by default, to tasks with CAP_SYS_ADMIN capabilities. Whenever this should be considered too restrictive and/or not required for a specific platforms, a kernel boot option is provided to change this default behavior thus allowing non privileged tasks to change their utilization clamp values. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Paul Turner Cc: Suren Baghdasaryan Cc: Todd Kjos Cc: Joel Fernandes Cc: Steve Muckle Cc: Juri Lelli Cc: Quentin Perret Cc: Dietmar Eggemann Cc: Morten Rasmussen Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- Changes in v4: Others: - new patch added in this version - rebased on v4.19-rc1 --- .../admin-guide/kernel-parameters.txt | 3 +++ kernel/sched/core.c | 22 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9871e649ffef..481f8214ea9a 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4561,6 +4561,9 @@ ,,,,,,, See also Documentation/input/devices/joystick-parport.rst + uclamp_user [KNL] Enable task-specific utilization clamping tuning + also from tasks without CAP_SYS_ADMIN capability. + udbg-immortal [PPC] When debugging early kernel crashes that happen after console_init() and before a proper console driver takes over, this boot options might diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 222397edb8a7..8341ce580a9a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1510,14 +1510,29 @@ static inline int alloc_uclamp_sched_group(struct task_group *tg, static inline void free_uclamp_sched_group(struct task_group *tg) { } #endif /* CONFIG_UCLAMP_TASK_GROUP */ +static bool uclamp_user_allowed __read_mostly; +static int __init uclamp_user_allow(char *str) +{ + uclamp_user_allowed = true; + + return 0; +} +early_param("uclamp_user", uclamp_user_allow); + static inline int __setscheduler_uclamp(struct task_struct *p, - const struct sched_attr *attr) + const struct sched_attr *attr, + bool user) { int group_id[UCLAMP_CNT] = { UCLAMP_NOT_VALID }; int lower_bound, upper_bound; struct uclamp_se *uc_se; int result = 0; + if (!capable(CAP_SYS_ADMIN) && + user && !uclamp_user_allowed) { + return -EPERM; + } + mutex_lock(&uclamp_mutex); /* Find a valid group_id for each required clamp value */ @@ -1702,7 +1717,8 @@ static inline int alloc_uclamp_sched_group(struct task_group *tg, return 1; } static inline int __setscheduler_uclamp(struct task_struct *p, - const struct sched_attr *attr) + const struct sched_attr *attr, + bool user) { return -EINVAL; } @@ -5217,7 +5233,7 @@ static int __sched_setscheduler(struct task_struct *p, /* Configure utilization clamps for the task */ if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) { - retval = __setscheduler_uclamp(p, attr); + retval = __setscheduler_uclamp(p, attr, user); if (retval) return retval; } -- 2.18.0