From patchwork Thu Dec 21 21:06:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Maciej_=C5=BBenczykowski?= X-Patchwork-Id: 10128403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D43660318 for ; Thu, 21 Dec 2017 21:06:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9036929DE6 for ; Thu, 21 Dec 2017 21:06:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84A0F29E5F; Thu, 21 Dec 2017 21:06:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B55029DE6 for ; Thu, 21 Dec 2017 21:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755384AbdLUVGe (ORCPT ); Thu, 21 Dec 2017 16:06:34 -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 Received: by mail-pf0-f195.google.com with SMTP id m26so14436859pfj.11; Thu, 21 Dec 2017 13:06:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6GAA30yhTb+o4UnvhqSmahWgLJv+8rBra21SEJY68zQ=; b=HhKDupE/B+QJ0xghswFQIMLpQ0ctK7m/mGV62TNdKl/bO07c07ZS9rVLDR6s9eqXA+ 5JeRXI8NDBg7ZEF7DJXCA6g2oWd7FjsYP0EIo8mCQuffF4e2ail/pq/4gZw3ZbnCEiJA JyQcqVecFeyT1xajkYmjtVZiLhEi9Mmnd7HxIL0W+kXGqh32BPSya1RdSS+vDAvFe8PO 47Cz5C/GeVN1vyoNlgM0fzF5322vNgXhy2V8GCdKgkNaPPL6kEpKLKPL4KsEbddhb+jb 1NLAulNjjEi7kHSvxkfMst31ek7z6GAZUKzT62LsRFtbiLrzymQMqkJ/oabMHIOVZYEw b0qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6GAA30yhTb+o4UnvhqSmahWgLJv+8rBra21SEJY68zQ=; b=k8ke9qUleWOxuQbpXTXHFg6JncmnBAiunpUILO/kSb94ZJIiqjC2GsOXDWdEoCuoLa g2jpnYWZpRaOeASWyGkZvSHe0f2WsMW5xksXOJiYus8fIqFxUeQbnYmXon5awuEY0bDP AxH2hzpo4/ojlNMd40UwXg1szPkL9xbSGptauWxN8ThfVk7ExrnrZDvGCHHwDL/GuQW3 31OgLQAc98X5FyyyHbcuP6HbEGPLj7fjqJQO76GBy5Xxi/QvcR5fqCcgF3Kp/U24f32f G9WMzUaawkyF8x+7l+Evh5DX77NIO5316I84kTivDWHXZWfdUJ97WVBLuYZEJcI1UjvA sAmA== X-Gm-Message-State: AKGB3mJcP5a7tYgyFVaDV3rwKFdslFyZZR8u3b+vXprfJ2z3raYV3u+q V1gthRwYFUInS7/ZxHottyg= X-Google-Smtp-Source: ACJfBose8/pMIclEe+v7FficFarDU+dTa70Td52rbe1zHea1lRZcGJWYZ6Bs6hOiAH2f9lmEjalLrQ== X-Received: by 10.99.123.14 with SMTP id w14mr6602896pgc.340.1513890392304; Thu, 21 Dec 2017 13:06:32 -0800 (PST) Received: from pallas.svl.corp.google.com ([2620:15c:2c4:1:aa52:5cc5:468e:5f4e]) by smtp.gmail.com with ESMTPSA id g7sm14132049pfm.76.2017.12.21.13.06.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Dec 2017 13:06:31 -0800 (PST) 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 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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;