From patchwork Fri Jul 28 20:21:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Adamson X-Patchwork-Id: 9869393 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 DBCD060382 for ; Fri, 28 Jul 2017 20:22:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D00AB28901 for ; Fri, 28 Jul 2017 20:22:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C489928908; Fri, 28 Jul 2017 20:22: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.9 required=2.0 tests=BAYES_00,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 D8FF328901 for ; Fri, 28 Jul 2017 20:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752680AbdG1UWe (ORCPT ); Fri, 28 Jul 2017 16:22:34 -0400 Received: from mx142.netapp.com ([216.240.21.19]:52446 "EHLO mx142.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752647AbdG1UWd (ORCPT ); Fri, 28 Jul 2017 16:22:33 -0400 X-IronPort-AV: E=Sophos;i="5.40,427,1496127600"; d="scan'208";a="203129309" Received: from vmwexchts01-prd.hq.netapp.com ([10.122.105.12]) by mx142-out.netapp.com with ESMTP; 28 Jul 2017 13:00:29 -0700 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCHTS01-PRD.hq.netapp.com (10.122.105.12) with Microsoft SMTP Server id 15.0.1210.3; Fri, 28 Jul 2017 13:22:12 -0700 Received: from localhost.localdomain.localdomain (dros-16.vpn.netapp.com [10.55.79.21]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id v6SKM1lk007987; Fri, 28 Jul 2017 13:22:12 -0700 (PDT) From: To: CC: , , , , Andy Adamson Subject: [PATCH Version 6 11/12] SUNRPC SVCAUTH_GSS set gss3 label on nfsd thread Date: Fri, 28 Jul 2017 16:21:57 -0400 Message-ID: <1501273318-14200-12-git-send-email-andros@netapp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1501273318-14200-1-git-send-email-andros@netapp.com> References: <1501273318-14200-1-git-send-email-andros@netapp.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andy Adamson Note: may need to give nfsd selinux authority to change thread label. Signed-off-by: Andy Adamson --- fs/nfsd/auth.c | 11 ++++++++++- include/linux/sunrpc/svcauth.h | 1 + net/sunrpc/auth_gss/svcauth_gss.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/auth.c b/fs/nfsd/auth.c index 62469c6..0330fe9 100644 --- a/fs/nfsd/auth.c +++ b/fs/nfsd/auth.c @@ -1,6 +1,7 @@ /* Copyright (C) 1995, 1996 Olaf Kirch */ #include +#include #include "nfsd.h" #include "auth.h" @@ -22,7 +23,7 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp) struct group_info *rqgi; struct group_info *gi; struct cred *new; - int i; + int i, ret; int flags = nfsexp_flags(rqstp, exp); validate_process_creds(); @@ -77,6 +78,14 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp) else new->cap_effective = cap_raise_nfsd_set(new->cap_effective, new->cap_permitted); + + if (selinux_is_enabled() && rqstp->rq_authop->set_label && + (exp->ex_flags & NFSEXP_SECURITY_LABEL)) { + ret = rqstp->rq_authop->set_label(rqstp, new); + if (ret < 0) + /* Should nfsd fail this request? */ + pr_warn("%s set_label FAILED ret %d\n", __func__, ret); + } validate_process_creds(); put_cred(override_creds(new)); put_cred(new); diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h index d039320..eed6880 100644 --- a/include/linux/sunrpc/svcauth.h +++ b/include/linux/sunrpc/svcauth.h @@ -128,6 +128,7 @@ struct auth_ops { int (*release)(struct svc_rqst *rq); void (*domain_release)(struct auth_domain *); int (*set_client)(struct svc_rqst *rq); + int (*set_label)(struct svc_rqst *rq, struct cred *new); }; #define SVC_GARBAGE 1 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 1b6e47f..2a48aa0 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1072,6 +1072,37 @@ struct gss_svc_data { return SVC_OK; } +/** + * the svcdata->rsci_ch pointer is the child context. + * assume one GSS3_LABEL per child context. + */ +static int +svcauth_gss_set_label(struct svc_rqst *rqstp, struct cred *new) +{ + struct gss_svc_data *svcdata = rqstp->rq_auth_data; + struct rsc *rsci_ch = svcdata->rsci_ch; + struct gss3_svc_assert *g3a; + struct gss3_label *g3l; + int ret = -1; + + if (!rsci_ch || !rsci_ch->assertions) + goto out; + + g3a = rsci_ch->assertions; + if (g3a->sa_num != 1 || g3a->sa_assert.au_type != GSS3_LABEL) + goto out; + + g3l = &g3a->sa_assert.u.au_label; + if (g3l->la_label.len == 0) + goto out; + + /* Assume SeLinux - need to validate la_lfs and la_pi ? */ + ret = set_security_override_from_ctx(new, (char *)g3l->la_label.data); + +out: + return ret; +} + static inline int gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, struct rpc_gss_wire_cred *gc, @@ -2126,6 +2157,7 @@ static void gss3_free_svc_assert(struct gss3_svc_assert *g3a) .release = svcauth_gss_release, .domain_release = svcauth_gss_domain_release, .set_client = svcauth_gss_set_client, + .set_label = svcauth_gss_set_label, }; static int rsi_cache_create_net(struct net *net)