From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423465AbcBQTfu (ORCPT ); Wed, 17 Feb 2016 14:35:50 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:45728 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161022AbcBQTfs (ORCPT ); Wed, 17 Feb 2016 14:35:48 -0500 Date: Wed, 17 Feb 2016 11:35:47 -0800 From: Andrew Morton To: John Stultz Cc: Thomas Gleixner , Arjan van de Ven , lkml , Oren Laadan , Ruchi Kandoi , Rom Lemarchand , Kees Cook , Android Kernel Team Subject: Re: [PATCH 2/2] proc: Add /proc//timerslack_ns interface Message-Id: <20160217113547.6487174b9c6d365927095080@linux-foundation.org> In-Reply-To: <1455671191-32105-3-git-send-email-john.stultz@linaro.org> References: <1455671191-32105-1-git-send-email-john.stultz@linaro.org> <1455671191-32105-3-git-send-email-john.stultz@linaro.org> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 16 Feb 2016 17:06:31 -0800 John Stultz wrote: > This patch provides a proc/PID/timerslack_ns interface which > exposes a task's timerslack value in nanoseconds and allows it > to be changed. > > This allows power/performance management software to set timer > slack for other threads according to its policy for the thread > (such as when the thread is designated foreground vs. background > activity) > > If the value written is non-zero, slack is set to that value. > Otherwise sets it to the default for the thread. > > This interface checks that the calling task has permissions to > to use PTRACE_MODE_ATTACH_FSCREDS on the target task, so that we > can ensure arbitrary apps do not change the timer slack for other > apps. hm. What the heck is PTRACE_MODE_ATTACH_FSCREDS and why was it chosen? The procfs file's permissions are 0644, yes? So a process's timer_slack is world-readable? hm. > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -2257,6 +2257,74 @@ static const struct file_operations proc_timers_operations = { > .release = seq_release_private, > }; > > +static ssize_t timerslack_ns_write(struct file *file, const char __user *buf, > + size_t count, loff_t *offset) > +{ > + struct inode *inode = file_inode(file); > + struct task_struct *p; > + char buffer[PROC_NUMBUF]; > + u64 slack_ns; > + int err; > + > + memset(buffer, 0, sizeof(buffer)); > + if (count > sizeof(buffer) - 1) > + count = sizeof(buffer) - 1; > + > + if (copy_from_user(buffer, buf, count)) > + return -EFAULT; > + > + err = kstrtoull(strstrip(buffer), 10, &slack_ns); > + if (err < 0) > + return err; Use kstrtoull_from_user()? > + p = get_proc_task(inode); > + if (!p) > + return -ESRCH; > + > + if (ptrace_may_access(p, PTRACE_MODE_ATTACH_FSCREDS)) { > + if (slack_ns == 0) > + p->timer_slack_ns = p->default_timer_slack_ns; > + else > + p->timer_slack_ns = slack_ns; > + } else > + count = -EINVAL; > + > + put_task_struct(p); > + > + return count; > +} > +