Skip to contentSkip to conversation

mm: create security context for memfd_secret inodes

RFC PATCH In review Christian Göttsche 2 participants 7 messages Jan 25, 2022 – Jun 13, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 mm: create security context for memfd_secret inodes

Create a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable.

---
An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission.

---
 mm/secretmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/secretmem.c +9 -0
index 22b310adb53d..b61cd2f661bc 100644
@@ -164,11 +164,20 @@ static struct file *secretmem_file_create(unsigned long flags)
 {
 	struct file *file = ERR_PTR(-ENOMEM);
 	struct inode *inode;
+	const char *anon_name = "[secretmem]";
+	const struct qstr qname = QSTR_INIT(anon_name, strlen(anon_name));
+	int err;
 
 	inode = alloc_anon_inode(secretmem_mnt->mnt_sb);
 	if (IS_ERR(inode))
 		return ERR_CAST(inode);
 
+	err = security_inode_init_security_anon(inode, &qname, NULL);
+	if (err) {
+		file = ERR_PTR(err);
+		goto err_free_inode;
+	}
+
 	file = alloc_file_pseudo(inode, secretmem_mnt, "secretmem",
 				 O_RDWR, &secretmem_fops);
 	if (IS_ERR(file))
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 6 lines · Christian Göttsche

Create a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable.

Quoted 7 lines

---
An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission.

---
 mm/secretmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

This seems reasonable to me, and I like the idea of labeling the anon inode as opposed to creating a new set of LSM hooks. If we want to apply access control policy to the memfd_secret() fds we are going to need to attach some sort of LSM state to the inode, we might as well use the mechanism we already have instead of inventing another one.

Quoted 27 lines
mm/secretmem.c +9 -1
index 22b310adb53d..b61cd2f661bc 100644
@@ -164,11 +164,20 @@ static struct file *secretmem_file_create(unsigned long flags)
 {
        struct file *file = ERR_PTR(-ENOMEM);
        struct inode *inode;
+       const char *anon_name = "[secretmem]";
+       const struct qstr qname = QSTR_INIT(anon_name, strlen(anon_name));
+       int err;
 
        inode = alloc_anon_inode(secretmem_mnt->mnt_sb);
        if (IS_ERR(inode))
                return ERR_CAST(inode);
 
+       err = security_inode_init_security_anon(inode, &qname, NULL);
+       if (err) {
+               file = ERR_PTR(err);
+               goto err_free_inode;
+       }
+
        file = alloc_file_pseudo(inode, secretmem_mnt, "secretmem",
                                 O_RDWR, &secretmem_fops);
        if (IS_ERR(file))
--

2.34.1

Signature · 1 line
paul-moore.com
#2 lore raw
Quoted 17 lines · Paul Moore
Quoted 6 lines · Christian Göttsche

Create a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable.

Quoted 7 lines

---
An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission.

---
 mm/secretmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)
Quoted 5 lines

This seems reasonable to me, and I like the idea of labeling the anon inode as opposed to creating a new set of LSM hooks. If we want to apply access control policy to the memfd_secret() fds we are going to need to attach some sort of LSM state to the inode, we might as well use the mechanism we already have instead of inventing another one.

Any further comments (on design or implementation)?

Should I resend a non-rfc?

One naming question:
Should the anonymous inode class be named "[secretmem]", like "[userfaultfd]", or "[secret_mem]" similar to "[io_uring]"?

Quoted 30 lines
Quoted 26 lines
mm/secretmem.c +9 -1
index 22b310adb53d..b61cd2f661bc 100644
@@ -164,11 +164,20 @@ static struct file *secretmem_file_create(unsigned long flags)
 {
        struct file *file = ERR_PTR(-ENOMEM);
        struct inode *inode;
+       const char *anon_name = "[secretmem]";
+       const struct qstr qname = QSTR_INIT(anon_name, strlen(anon_name));
+       int err;
 
        inode = alloc_anon_inode(secretmem_mnt->mnt_sb);
        if (IS_ERR(inode))
                return ERR_CAST(inode);
 
+       err = security_inode_init_security_anon(inode, &qname, NULL);
+       if (err) {
+               file = ERR_PTR(err);
+               goto err_free_inode;
+       }
+
        file = alloc_file_pseudo(inode, secretmem_mnt, "secretmem",
                                 O_RDWR, &secretmem_fops);
        if (IS_ERR(file))
--
Quoted 1 line

2.34.1

--
paul-moore.com

maintainer
#3 lore raw
Quoted 23 lines · Christian Göttsche
Quoted 16 lines · Paul Moore
Quoted 6 lines · Christian Göttsche

Create a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable.

Quoted 7 lines

---
An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission.

---
 mm/secretmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)
Quoted 5 lines

This seems reasonable to me, and I like the idea of labeling the anon inode as opposed to creating a new set of LSM hooks. If we want to apply access control policy to the memfd_secret() fds we are going to need to attach some sort of LSM state to the inode, we might as well use the mechanism we already have instead of inventing another one.

Quoted 3 lines

Any further comments (on design or implementation)?

Should I resend a non-rfc?

I personally would really like to see a selinux-testsuite for this so that we can verify it works not just now but in the future too. I think having a test would also help demonstrate the usefulness of the additional LSM controls.

Quoted 3 lines

One naming question:
Should the anonymous inode class be named "[secretmem]", like "[userfaultfd]", or "[secret_mem]" similar to "[io_uring]"?

The pr_fmt() string in mm/secretmem.c uses "secretmem" so I would suggest sticking with "[secretmem]", although that is question best answered by the secretmem maintainer.

Signature · 1 line
paul-moore.com
#4 lore raw
Quoted 26 lines · Paul Moore
Quoted 23 lines · Christian Göttsche
Quoted 21 lines · Paul Moore
Quoted 6 lines · Christian Göttsche

Create a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable.

Quoted 7 lines

---
An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission.

---
 mm/secretmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

This seems reasonable to me, and I like the idea of labeling the anon inode as opposed to creating a new set of LSM hooks. If we want to apply access control policy to the memfd_secret() fds we are going to need to attach some sort of LSM state to the inode, we might as well use the mechanism we already have instead of inventing another one.

Quoted 9 lines
Quoted 3 lines

Any further comments (on design or implementation)?

Should I resend a non-rfc?

I personally would really like to see a selinux-testsuite for this so that we can verify it works not just now but in the future too. I think having a test would also help demonstrate the usefulness of the additional LSM controls.

Any comments (especially from the mm people)?

Draft SELinux testsuite patch:
https://github.com/SELinuxProject/selinux-testsuite/pull/80

Quoted 10 lines
Quoted 3 lines

One naming question:
Should the anonymous inode class be named "[secretmem]", like "[userfaultfd]", or "[secret_mem]" similar to "[io_uring]"?

The pr_fmt() string in mm/secretmem.c uses "secretmem" so I would suggest sticking with "[secretmem]", although that is question best answered by the secretmem maintainer.

--
paul-moore.com

maintainer
#5 lore raw
Quoted 36 lines · Christian Göttsche
Quoted 25 lines · Paul Moore
Quoted 23 lines · Christian Göttsche
Quoted 21 lines · Paul Moore
Quoted 6 lines · Christian Göttsche

Create a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable.

Quoted 7 lines

---
An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission.

---
 mm/secretmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

This seems reasonable to me, and I like the idea of labeling the anon inode as opposed to creating a new set of LSM hooks. If we want to apply access control policy to the memfd_secret() fds we are going to need to attach some sort of LSM state to the inode, we might as well use the mechanism we already have instead of inventing another one.

Quoted 9 lines
Quoted 3 lines

Any further comments (on design or implementation)?

Should I resend a non-rfc?

I personally would really like to see a selinux-testsuite for this so that we can verify it works not just now but in the future too. I think having a test would also help demonstrate the usefulness of the additional LSM controls.

Quoted 12 lines

Any comments (especially from the mm people)?

Draft SELinux testsuite patch:
https://github.com/SELinuxProject/selinux-testsuite/pull/80

Quoted 7 lines
Quoted 3 lines

One naming question:
Should the anonymous inode class be named "[secretmem]", like "[userfaultfd]", or "[secret_mem]" similar to "[io_uring]"?

The pr_fmt() string in mm/secretmem.c uses "secretmem" so I would suggest sticking with "[secretmem]", although that is question best answered by the secretmem maintainer.

I think this patchset has been posted for long enough with no comments, and no objections, that I can pull this into the selinux/next tree. However, I'll give it until the end of this week just to give folks one last chance to comment. If I don't hear any objections by the end of day on Friday, June 10th I'll go ahead and merge this.

Signature · 1 line
paul-moore.com
maintainer
#6 lore raw
Quoted 51 lines · Paul Moore
Quoted 36 lines · Christian Göttsche
Quoted 25 lines · Paul Moore
Quoted 23 lines · Christian Göttsche
Quoted 21 lines · Paul Moore
Quoted 6 lines · Christian Göttsche

Create a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable.

Quoted 7 lines

---
An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission.

---
 mm/secretmem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

This seems reasonable to me, and I like the idea of labeling the anon inode as opposed to creating a new set of LSM hooks. If we want to apply access control policy to the memfd_secret() fds we are going to need to attach some sort of LSM state to the inode, we might as well use the mechanism we already have instead of inventing another one.

Quoted 9 lines
Quoted 3 lines

Any further comments (on design or implementation)?

Should I resend a non-rfc?

I personally would really like to see a selinux-testsuite for this so that we can verify it works not just now but in the future too. I think having a test would also help demonstrate the usefulness of the additional LSM controls.

Quoted 12 lines

Any comments (especially from the mm people)?

Draft SELinux testsuite patch:
https://github.com/SELinuxProject/selinux-testsuite/pull/80

Quoted 7 lines
Quoted 3 lines

One naming question:
Should the anonymous inode class be named "[secretmem]", like "[userfaultfd]", or "[secret_mem]" similar to "[io_uring]"?

The pr_fmt() string in mm/secretmem.c uses "secretmem" so I would suggest sticking with "[secretmem]", although that is question best answered by the secretmem maintainer.

Quoted 6 lines

I think this patchset has been posted for long enough with no comments, and no objections, that I can pull this into the selinux/next tree. However, I'll give it until the end of this week just to give folks one last chance to comment. If I don't hear any objections by the end of day on Friday, June 10th I'll go ahead and merge this.

I didn't see any comments so I just merged this into selinux/next. Thanks for your patience Christian.

Signature · 1 line
paul-moore.com