From patchwork Tue Jun 26 08:43:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 10488287 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 182FF602B3 for ; Tue, 26 Jun 2018 08:43:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07D1A287E5 for ; Tue, 26 Jun 2018 08:43:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0957287E7; Tue, 26 Jun 2018 08:43:18 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 8D3E4287E1 for ; Tue, 26 Jun 2018 08:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752810AbeFZInQ (ORCPT ); Tue, 26 Jun 2018 04:43:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37508 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752481AbeFZInN (ORCPT ); Tue, 26 Jun 2018 04:43:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3550A402312B; Tue, 26 Jun 2018 08:43:13 +0000 (UTC) Received: from ovpn-12-60.pek2.redhat.com (ovpn-12-60.pek2.redhat.com [10.72.12.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 366C6111CA1C; Tue, 26 Jun 2018 08:43:09 +0000 (UTC) From: "Yan, Zheng" To: linux-security-module@vger.kernel.org Cc: jmorris@namei.org, paul@paul-moore.com, ceph-devel@vger.kernel.org, "Yan, Zheng" Subject: [PATCH 1/3] selinux: make dentry_init_security() return security module name Date: Tue, 26 Jun 2018 16:43:04 +0800 Message-Id: <20180626084306.27511-1-zyan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 26 Jun 2018 08:43:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 26 Jun 2018 08:43:13 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'zyan@redhat.com' RCPT:'' Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is preparation for CephFS security label. CephFS's implementation uses dentry_init_security() to get security context before inode is created, then sends open/mkdir/mknod request to MDS, together with security xattr "security." Signed-off-by: "Yan, Zheng" Acked-by: Jeff Layton --- fs/nfs/nfs4proc.c | 3 ++- include/linux/lsm_hooks.h | 4 ++-- include/linux/security.h | 9 +++++---- security/security.c | 7 ++++--- security/selinux/hooks.c | 8 ++++++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 6dd146885da9..d18a5fb7aec3 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -122,7 +122,8 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry, return NULL; err = security_dentry_init_security(dentry, sattr->ia_mode, - &dentry->d_name, (void **)&label->label, &label->len); + &dentry->d_name, NULL, + (void **)&label->label, &label->len); if (err == 0) return label; diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 8f1131c8dd54..e176c2032bdc 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1476,8 +1476,8 @@ union security_list_options { unsigned long *set_kern_flags); int (*sb_parse_opts_str)(char *options, struct security_mnt_opts *opts); int (*dentry_init_security)(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen); + const struct qstr *name, const char **label, + void **ctx, u32 *ctxlen); int (*dentry_create_files_as)(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old, diff --git a/include/linux/security.h b/include/linux/security.h index 63030c85ee19..df2d73998c64 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -246,8 +246,9 @@ int security_sb_clone_mnt_opts(const struct super_block *oldsb, unsigned long *set_kern_flags); int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts); int security_dentry_init_security(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen); + const struct qstr *name, + const char **label, + void **ctx, u32 *ctxlen); int security_dentry_create_files_as(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old, @@ -609,8 +610,8 @@ static inline void security_inode_free(struct inode *inode) static inline int security_dentry_init_security(struct dentry *dentry, int mode, const struct qstr *name, - void **ctx, - u32 *ctxlen) + const char **label, + void **ctx, u32 *ctxlen) { return -EOPNOTSUPP; } diff --git a/security/security.c b/security/security.c index 68f46d849abe..69818d46aa28 100644 --- a/security/security.c +++ b/security/security.c @@ -450,11 +450,12 @@ void security_inode_free(struct inode *inode) } int security_dentry_init_security(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen) + const struct qstr *name, + const char **label, + void **ctx, u32 *ctxlen) { return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode, - name, ctx, ctxlen); + name, label, ctx, ctxlen); } EXPORT_SYMBOL(security_dentry_init_security); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 2b5ee5fbd652..eca3879d9357 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2985,8 +2985,9 @@ static void selinux_inode_free_security(struct inode *inode) } static int selinux_dentry_init_security(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen) + const struct qstr *name, + const char **label, + void **ctx, u32 *ctxlen) { u32 newsid; int rc; @@ -2998,6 +2999,9 @@ static int selinux_dentry_init_security(struct dentry *dentry, int mode, if (rc) return rc; + if (label) + *label = XATTR_SELINUX_SUFFIX; + return security_sid_to_context(&selinux_state, newsid, (char **)ctx, ctxlen); }