Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3636637imu; Mon, 28 Jan 2019 08:12:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN5SWn6qfGfsJPF0aahmAMzjJxs1ax3IajGrCnUyJepwNdM7w3dLwYoSfz6XALz3roZPd0S5 X-Received: by 2002:a63:8d44:: with SMTP id z65mr20429997pgd.57.1548691970671; Mon, 28 Jan 2019 08:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691970; cv=none; d=google.com; s=arc-20160816; b=KKeR41KtPHH8fCV7Wwv7LhhH8gDL9BXIhDj+ggfr6/qOoshi8crZoH7LtwcfgFRmDP YqNrfyZldx8IiDqbq1wyrjCqN9Z/znVR5q8qvFaB6VoubiXw6rH4CiH0CV7EnwjKbx4F nlfmk2l5pgDRY4jn8B9YfB9F778OCBr24Gyv6xp6THjZ80dc64hV4pizG5NXsx93L9MO frLKR1q2ELYamOVQbIcaSJdaBEYh3YTUXuj+y8RXWt0NeTd08c9uSXWUhZ8g6ZaTWVro lhD9LNxFwSTeQOJMiQtuwiFzAl/02nGhPKwnetIqaTroVkH/S87o7sifLmgpoUieUW1b VFQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y8hudx6SKadApn6i+L3+FbjtY3oYdE8w+A53lTBgug0=; b=q5kaodjrv6jGLooyppiryBiXwr/GrcOCqFnl6/5tMYusWfaDy8mzsGb/qpVd4JDgtq N+w2Iaffs4rHLTyp6ooLauXLOYZqX45R2zjLe0Gy5pZUWPAoohqCi9ZsHfGOuwPPo0aJ X/m1j2nTSNReUaOCoNjPCavROMtDjLWaD6ZHbI0OWzbUHlZiwpVlDnkpWnFtAGEp/czc FdABcASm9Dc9OzH8f1RlBM+STl98ipXklAF/vjdNxlvM9CyEMIPfEUw1nc+ZlCLQnb5K v6ow/+2hxBikOCiq4K1DQZYtnsL2dB7I0WJyt8auuKdAUjuPh1hz/FQIneYe6C5ZsTFT UP/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LvCZTBDy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si26790780pgh.560.2019.01.28.08.12.35; Mon, 28 Jan 2019 08:12:50 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=LvCZTBDy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732997AbfA1QLi (ORCPT + 99 others); Mon, 28 Jan 2019 11:11:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:38744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732971AbfA1QLg (ORCPT ); Mon, 28 Jan 2019 11:11:36 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 072082175B; Mon, 28 Jan 2019 16:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691895; bh=LyYWqI/kO+VSj4t6CstNgqygIq9zztZV3LFIAJYf4vo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LvCZTBDybkz9mojIxaYk5iatBy0XYkcZq/CTMwP58Np8lOS7v+kYJJENMJep6uv4+ mPO1DGny5L/GkFPWpGMJFd5ozqr9ZGMqZCxlrWsCWvI7NXBvoeew0THdghsARF7A1M MW8sNfkB7cu/OWrQMpK65ckHdgb2mY9460dyrLR8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Benjamin Gordon , John Stultz , "Eric W. Biederman" , Kees Cook , "Serge E. Hallyn" , Thomas Gleixner , Arjan van de Ven , Oren Laadan , Ruchi Kandoi , Rom Lemarchand , Todd Kjos , Colin Cross , Nick Kralevich , Dmitry Shmidt , Elliott Hughes , Alexey Dobriyan , Andrew Morton , Linus Torvalds , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 251/258] fs/proc/base.c: use ns_capable instead of capable for timerslack_ns Date: Mon, 28 Jan 2019 10:59:17 -0500 Message-Id: <20190128155924.51521-251-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Gordon [ Upstream commit 8da0b4f692c6d90b09c91f271517db746a22ff67 ] Access to timerslack_ns is controlled by a process having CAP_SYS_NICE in its effective capability set, but the current check looks in the root namespace instead of the process' user namespace. Since a process is allowed to do other activities controlled by CAP_SYS_NICE inside a namespace, it should also be able to adjust timerslack_ns. Link: http://lkml.kernel.org/r/20181030180012.232896-1-bmgordon@google.com Signed-off-by: Benjamin Gordon Acked-by: "Eric W. Biederman" Cc: John Stultz Cc: "Eric W. Biederman" Cc: Kees Cook Cc: "Serge E. Hallyn" 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: Alexey Dobriyan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/proc/base.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 7e9f07bf260d..5bdcf2159ff0 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2356,10 +2356,13 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf, return -ESRCH; if (p != current) { - if (!capable(CAP_SYS_NICE)) { + rcu_read_lock(); + if (!ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE)) { + rcu_read_unlock(); count = -EPERM; goto out; } + rcu_read_unlock(); err = security_task_setscheduler(p); if (err) { @@ -2392,11 +2395,14 @@ static int timerslack_ns_show(struct seq_file *m, void *v) return -ESRCH; if (p != current) { - - if (!capable(CAP_SYS_NICE)) { + rcu_read_lock(); + if (!ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE)) { + rcu_read_unlock(); err = -EPERM; goto out; } + rcu_read_unlock(); + err = security_task_getscheduler(p); if (err) goto out; -- 2.19.1