From patchwork Wed Apr 10 16:55:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Morton X-Patchwork-Id: 10894425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 072461515 for ; Wed, 10 Apr 2019 16:56:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E267D284C8 for ; Wed, 10 Apr 2019 16:56:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6E5128B5A; Wed, 10 Apr 2019 16:56:02 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI 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 C3BA9284C8 for ; Wed, 10 Apr 2019 16:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733214AbfDJQ4B (ORCPT ); Wed, 10 Apr 2019 12:56:01 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:40833 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733175AbfDJQ4B (ORCPT ); Wed, 10 Apr 2019 12:56:01 -0400 Received: by mail-pl1-f194.google.com with SMTP id b3so1774991plr.7 for ; Wed, 10 Apr 2019 09:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZcnGgMu03T8LTTqVr2mqlTYFf4INWRgM/Q8XomVCOz4=; b=HCb2Y3eQjdD8wwXwkVLkmrgLN/r42Os1rjQoIJRqJro9tiVuhlJj98HJT5+7ulbPlF e/EAZl9CaIiFTJ08dfyv//yWgoqv4rzonPGmYjP+3LloyW54elbOo/wjZSAU7VYZgx/P VjDYK5p3xayWxp9KuoohITIEWFcmuyOjZod+A= 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=ZcnGgMu03T8LTTqVr2mqlTYFf4INWRgM/Q8XomVCOz4=; b=ChiieYlqmW2YCANxfEbRPmVQwVtEBAv9mq/vEP3tKwdqfGWyhHJR1Y8ayCNRg0teLD jhFjfe65W4umBIxr4BCBLmAzjip0F8VYyFP+435u+hKF0nRqLik+kqlBsRHh2Jrzusjj xWpaEzp8lNWDpU7vIeBqD1z/m4wi17i75ydR+Oy4ewaEqN3SQwHrq9yKUQaelHHs/BpI HlDraTeIGdf//fKYIo7AZKx+IXqP2eKSymK4BRqr88bCcI472vtSWL0w3XxOlJ9asPwo +r5bXW/Gwh3N/DTpHr86IdS3AY5tDlEg0y3HGn0isVrXYcRNnBDP8tu+GXIeW6M326cp Ll2g== X-Gm-Message-State: APjAAAWUV8AdOa6CqYSjR26LANr7/AqmBreqz3g21BD4Q1tSg6PLHt0P D3JvdWilF58mFlPzipVNVpGT+A== X-Google-Smtp-Source: APXvYqxCfAF31tcrDxApn6u0UecgXLlWBk0DFpvCDy7igKFfuB12pg96mzlRZMnnn93uhfNvky54+Q== X-Received: by 2002:a17:902:e101:: with SMTP id cc1mr45320044plb.129.1554915360626; Wed, 10 Apr 2019 09:56:00 -0700 (PDT) Received: from localhost ([2620:15c:202:201:9e10:971c:f11c:a814]) by smtp.gmail.com with ESMTPSA id m7sm51300435pgg.62.2019.04.10.09.55.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 09:56:00 -0700 (PDT) From: Micah Morton X-Google-Original-From: Micah Morton To: jmorris@namei.org, keescook@chromium.org, casey@schaufler-ca.com, linux-security-module@vger.kernel.org Cc: Jann Horn , Micah Morton Subject: [PATCH 06/10] LSM: SafeSetID: fix userns handling in securityfs Date: Wed, 10 Apr 2019 09:55:58 -0700 Message-Id: <20190410165558.211483-1-mortonm@chromium.org> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog MIME-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Jann Horn Looking at current_cred() in write handlers is bad form, stop doing that. Also, let's just require that the write is coming from the initial user namespace. Especially SAFESETID_WHITELIST_FLUSH requires privilege over all namespaces, and SAFESETID_WHITELIST_ADD should probably require it as well. Signed-off-by: Jann Horn Signed-off-by: Micah Morton Reviewed-by: Kees Cook --- security/safesetid/securityfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/security/safesetid/securityfs.c b/security/safesetid/securityfs.c index 87e42b7f3e33..76c1e8a6ab93 100644 --- a/security/safesetid/securityfs.c +++ b/security/safesetid/securityfs.c @@ -59,8 +59,8 @@ static int parse_policy_line( if (ret) return ret; - *parent = make_kuid(current_user_ns(), parsed_parent); - *child = make_kuid(current_user_ns(), parsed_child); + *parent = make_kuid(file->f_cred->user_ns, parsed_parent); + *child = make_kuid(file->f_cred->user_ns, parsed_child); if (!uid_valid(*parent) || !uid_valid(*child)) return -EINVAL; @@ -92,7 +92,7 @@ static ssize_t safesetid_file_write(struct file *file, kuid_t child; int ret; - if (!ns_capable(current_user_ns(), CAP_MAC_ADMIN)) + if (!file_ns_capable(file, &init_user_ns, CAP_MAC_ADMIN)) return -EPERM; if (*ppos != 0)