forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
ima: Add IMA namespace support
Implement an IMA namespace data structure that gets created alongside a user namespace with CLONE_NEWUSER. This lays down the foundation for namespacing the different aspects of IMA (eg. IMA-audit, IMA-measurement, IMA-appraisal). Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Suggested-by: James Bottomley <James.Bottomley@HansenPartnership.com>
- Loading branch information
1 parent
32ba540
commit 0e5d16c2da02e9c61692836edf0b6f7f227e1867
Showing
10 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Copyright (C) 2016-2021 IBM Corporation | ||
| * Author: | ||
| * Yuqiong Sun <suny@us.ibm.com> | ||
| * Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, version 2 of the License. | ||
| */ | ||
|
|
||
| #include <linux/export.h> | ||
| #include <linux/user_namespace.h> | ||
| #include <linux/ima.h> | ||
| #include <linux/proc_ns.h> | ||
|
|
||
| int ima_init_namespace(struct ima_namespace *ns) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| int __init ima_ns_init(void) | ||
| { | ||
| return ima_init_namespace(&init_ima_ns); | ||
| } | ||
|
|
||
| struct ima_namespace init_ima_ns = { | ||
| .kref = KREF_INIT(1), | ||
| .user_ns = &init_user_ns, | ||
| }; | ||
| EXPORT_SYMBOL(init_ima_ns); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * Copyright (C) 2016-2021 IBM Corporation | ||
| * Author: | ||
| * Yuqiong Sun <suny@us.ibm.com> | ||
| * Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, version 2 of the License. | ||
| */ | ||
|
|
||
| #include <linux/kref.h> | ||
| #include <linux/slab.h> | ||
| #include <linux/ima.h> | ||
| #include <linux/mount.h> | ||
| #include <linux/proc_ns.h> | ||
| #include <linux/lsm_hooks.h> | ||
|
|
||
| #include "ima.h" | ||
|
|
||
| static struct kmem_cache *imans_cachep; | ||
|
|
||
| int create_ima_ns(struct user_namespace *user_ns) | ||
| { | ||
| struct ima_namespace *ns; | ||
| int err; | ||
|
|
||
| ns = kmem_cache_zalloc(imans_cachep, GFP_KERNEL); | ||
| if (!ns) | ||
| return -ENOMEM; | ||
| pr_debug("NEW ima_ns: 0x%p\n", ns); | ||
|
|
||
| kref_init(&ns->kref); | ||
| ns->user_ns = user_ns; | ||
|
|
||
| err = ima_init_namespace(ns); | ||
| if (err) | ||
| goto fail_free; | ||
|
|
||
| user_ns->ima_ns = ns; | ||
|
|
||
| return 0; | ||
|
|
||
| fail_free: | ||
| kmem_cache_free(imans_cachep, ns); | ||
|
|
||
| return err; | ||
| } | ||
|
|
||
| static void destroy_ima_ns(struct ima_namespace *ns) | ||
| { | ||
| pr_debug("DESTROY ima_ns: 0x%p\n", ns); | ||
| kmem_cache_free(imans_cachep, ns); | ||
| } | ||
|
|
||
| void free_ima_ns(struct kref *kref) | ||
| { | ||
| struct ima_namespace *ns; | ||
|
|
||
| ns = container_of(kref, struct ima_namespace, kref); | ||
| if (WARN_ON(ns == &init_ima_ns)) | ||
| return; | ||
|
|
||
| destroy_ima_ns(ns); | ||
| } | ||
|
|
||
| static int __init imans_cache_init(void) | ||
| { | ||
| imans_cachep = KMEM_CACHE(ima_namespace, SLAB_PANIC); | ||
| return 0; | ||
| } | ||
| subsys_initcall(imans_cache_init) |