From patchwork Mon Aug 22 23:01:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 74480 Delivered-To: patches@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1803913qga; Mon, 22 Aug 2016 16:01:15 -0700 (PDT) X-Received: by 10.66.49.137 with SMTP id u9mr47564817pan.72.1471906874984; Mon, 22 Aug 2016 16:01:14 -0700 (PDT) Return-Path: Received: from mail-pf0-x22b.google.com (mail-pf0-x22b.google.com. [2607:f8b0:400e:c00::22b]) by mx.google.com with ESMTPS id sl8si339695pab.264.2016.08.22.16.01.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Aug 2016 16:01:14 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22b as permitted sender) client-ip=2607:f8b0:400e:c00::22b; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22b as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x22b.google.com with SMTP id p64so36690639pfb.1 for ; Mon, 22 Aug 2016 16:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=vzOhmJX+LwqPxQRlT7AICeL8QzFVYIoaf4wJEo0cctI=; b=guJy+854+SyDiqR0FKy8fD2+02t8wOS0Ko58ZRPyLXgubg9qeQmWk7BF3d13BD7SdO 9w2P52T0oFOwSiNQTSdLq4olbaYwJT8p1RmH1unrpQPktyaMDzsF2ya9WvcC18KvD9sV TJclAmKnTabz8edduWsFrNxuNwj5GRdj6+4iw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vzOhmJX+LwqPxQRlT7AICeL8QzFVYIoaf4wJEo0cctI=; b=ZFmHomH/Pw9x+cqt7K/sJywuYgqBs6fY6tBE6BQj57JkCm6ENapDB5eiNa2U0GvnVw Sd1SgWwkh+2dNBJgcPF6BgDO6ucPoJFupcEcGta4Qm7kUkyJFvO+xL/8xeRkcg0BP84C QNAoyxo17mBuCEQHAhiY4/Zf7vXR8TQvArWt2Ft5hOr5RYfDgJhkEM5CUkxWFtAz7/LR ij7+mdjgEY6fRMFaLPvVV52N3rn4P7oO4v7cuspSnqRFNo6sUZcC5AzOSWddA8TqT3lY kTbl0T2CUri9VzCtWqb1A7IK8BSWXipmwbawv/YcdWZqQqt2QvyFKkWarlU+d4PKP2nn KsCQ== X-Gm-Message-State: AEkoouvClPnR5PMShogBLeUIEuXyi/HpbdYZPlos49MLU3hP/DNvJSp3eWpr8ktfJPVhEjNaz6k= X-Received: by 10.98.28.142 with SMTP id c136mr47128190pfc.131.1471906874693; Mon, 22 Aug 2016 16:01:14 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id 72sm220945pfs.51.2016.08.22.16.01.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Aug 2016 16:01:14 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Kees Cook , "Serge E. Hallyn" , Andrew Morton , Thomas Gleixner , Arjan van de Ven , Oren Laadan , Ruchi Kandoi , Rom Lemarchand , Todd Kjos , Colin Cross , Nick Kralevich , Dmitry Shmidt , Elliott Hughes , Android Kernel Team Subject: [RESEND][PATCH] proc: Fix timerslack_ns CAP_SYS_NICE check when adjusting self Date: Mon, 22 Aug 2016 16:01:10 -0700 Message-Id: <1471906870-28624-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In changing from checking ptrace_may_access(p, PTRACE_MODE_ATTACH_FSCREDS) to capable(CAP_SYS_NICE), I missed that ptrace_my_access succeeds when p == current, but the CAP_SYS_NICE doesn't. Thus while the previous commit was intended to loosen the needed privledges to modify a processes timerslack, it needlessly restricted a task modifying its own timerslack via the proc//timerslack_ns (which is permitted also via the PR_SET_TIMERSLACK method). This patch corrects this by checking if p == current before checking the CAP_SYS_NICE value. This patch applies on top of my two previous patches currently in -mm Cc: Kees Cook Cc: "Serge E. Hallyn" Cc: Andrew Morton Cc: Thomas Gleixner CC: Arjan van de Ven Cc: Oren Laadan Cc: Ruchi Kandoi Cc: Rom Lemarchand Cc: Todd Kjos Cc: Colin Cross Cc: Nick Kralevich Cc: Dmitry Shmidt Cc: Elliott Hughes Cc: Android Kernel Team Acked-by: Kees Cook Signed-off-by: John Stultz --- fs/proc/base.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) -- 1.9.1 diff --git a/fs/proc/base.c b/fs/proc/base.c index 02f8389..01c3c2d 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2281,15 +2281,17 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf, if (!p) return -ESRCH; - if (!capable(CAP_SYS_NICE)) { - count = -EPERM; - goto out; - } + if (p != current) { + if (!capable(CAP_SYS_NICE)) { + count = -EPERM; + goto out; + } - err = security_task_setscheduler(p); - if (err) { - count = err; - goto out; + err = security_task_setscheduler(p); + if (err) { + count = err; + goto out; + } } task_lock(p); @@ -2315,14 +2317,16 @@ static int timerslack_ns_show(struct seq_file *m, void *v) if (!p) return -ESRCH; - if (!capable(CAP_SYS_NICE)) { - err = -EPERM; - goto out; - } + if (p != current) { - err = security_task_getscheduler(p); - if (err) - goto out; + if (!capable(CAP_SYS_NICE)) { + err = -EPERM; + goto out; + } + err = security_task_getscheduler(p); + if (err) + goto out; + } task_lock(p); seq_printf(m, "%llu\n", p->timer_slack_ns);