Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755657AbdLUVGg (ORCPT ); Thu, 21 Dec 2017 16:06:36 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:45031 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752884AbdLUVGd (ORCPT ); Thu, 21 Dec 2017 16:06:33 -0500 X-Google-Smtp-Source: ACJfBose8/pMIclEe+v7FficFarDU+dTa70Td52rbe1zHea1lRZcGJWYZ6Bs6hOiAH2f9lmEjalLrQ== From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= To: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Cc: linux-security-module@vger.kernel.org, Linux Kernel Mailing List , "Eric W . Biederman" , Mahesh Bandewar , Willem de Bruijn Subject: [PATCH] userns: honour no_new_privs for cap_bset during user ns creation/switch Date: Thu, 21 Dec 2017 13:06:05 -0800 Message-Id: <20171221210605.181720-1-zenczykowski@gmail.com> X-Mailer: git-send-email 2.15.1.620.gb9897f4670-goog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1158 Lines: 32 From: Maciej Żenczykowski This allows locking down user namespaces tighter, and it could even be considered a security fix. Signed-off-by: Maciej Żenczykowski --- kernel/user_namespace.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 246d4d4ce5c7..2354f7ade78a 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -50,11 +50,12 @@ static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns) * anything as the capabilities are bound to the new user namespace. */ cred->securebits = SECUREBITS_DEFAULT; + cred->cap_bset = task_no_new_privs(current) ? current_cred()->cap_bset + : CAP_FULL_SET; cred->cap_inheritable = CAP_EMPTY_SET; - cred->cap_permitted = CAP_FULL_SET; - cred->cap_effective = CAP_FULL_SET; + cred->cap_permitted = cred->cap_bset; + cred->cap_effective = cred->cap_bset; cred->cap_ambient = CAP_EMPTY_SET; - cred->cap_bset = CAP_FULL_SET; #ifdef CONFIG_KEYS key_put(cred->request_key_auth); cred->request_key_auth = NULL; -- 2.15.1.620.gb9897f4670-goog