Create io_uring fd with ephemeral inode
cover Create io_uring fd with ephemeral inode
This set converts io_uring to use secure anon_inodes (with a newly allocated non-S_PRIVATE inode) for each individual instance. In addition to allowing LSM modules to enforce policy using the inode context, it also enables checkpoint/restore usecases by allowing mapping the VMA to the open fd in a task. Offset is already available to determine rings mapped per region, so this was the only missing piece in establishing region <-> io_uring instance mapping.
LSM tie up has been left out of this set for now.
Kumar Kartikeya Dwivedi (2):
fs: anon_inodes: export anon_inode_getfile_secure helper
fs: io_uring: convert to use anon_inode_getfile_secure
fs/anon_inodes.c | 9 +++++++++ fs/io_uring.c | 4 ++-- include/linux/anon_inodes.h | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 fs: anon_inodes: export anon_inode_getfile_secure helper
This is the non-fd installing analogue of anon_inode_getfd_secure. In addition to allowing LSMs to attach policy to the distinct inode, this is also needed for checkpoint restore of an io_uring instance where a mapped region needs to mapped back to the io_uring fd by CRIU. This is currently not possible as all anon_inodes share a single inode.
--- fs/anon_inodes.c | 9 +++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 13 insertions(+)
fs/anon_inodes.c +9 -0
@@ -148,6 +148,15 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile); +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode) +{ +return __anon_inode_getfile (name, fops, priv, flags, context_inode, true); +} +EXPORT_SYMBOL_GPL (anon_inode_getfile_secure); + static int __anon_inode_getfd(const char *name, const struct file_operations *fops, void *priv, int flags,
include/linux/anon_inodes.h +4 -0
@@ -15,6 +15,10 @@ struct inode;struct file *anon_inode_getfile (const char *name,const struct file_operations *fops,void *priv,int flags); +struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode);int anon_inode_getfd (const char *name,const struct file_operations *fops,void *priv,int flags); int anon_inode_getfd_secure(const char *name,
Signature · 1 line
2.31.1
Re: [PATCH 1/2] fs: anon_inodes: export anon_inode_getfile_secure helper
Quoted 7 lines · Kumar Kartikeya Dwivedi
This is the non-fd installing analogue of
anon_inode_getfd_secure. In addition to allowing LSMs to attach policy to the distinct inode, this is also needed for checkpoint restore of anio_uringinstance where a mapped region needs to mapped back to theio_uringfd by CRIU. This is currently not possible as allanon_inodesshare a single inode.
Quoted 5 lines
Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>--- fs/anon_inodes.c | 9 +++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 13 insertions(+)
[NOTE: dropping dancol@google as that email is bouncy]
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 149
Quoted 7 lines
fs/anon_inodes.c +0
-0@@ -148,6 +148,15 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile);
This function should have a comment block at the top similar to anon_inode_getfile(); in fact you can likely copy-n-paste the bulk of it to use as a start.
If you don't want to bother respinning, I've got this exact patch (+comments) in my patchset that I'll post later and I'm happy to give/share credit if that is important to you.
Quoted 8 lines
fs/anon_inodes.c +8
-0+struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode) +{ +return __anon_inode_getfile (name, fops, priv, flags, context_inode, true); +} +EXPORT_SYMBOL_GPL (anon_inode_getfile_secure);
Signature · 2 lines
paul moore www.paul-moore.com
Re: [PATCH 1/2] fs: anon_inodes: export anon_inode_getfile_secure helper
Quoted 29 lines · Paul Moore
Quoted 7 lines · Kumar Kartikeya Dwivedi
This is the non-fd installing analogue of
anon_inode_getfd_secure. In addition to allowing LSMs to attach policy to the distinct inode, this is also needed for checkpoint restore of anio_uringinstance where a mapped region needs to mapped back to theio_uringfd by CRIU. This is currently not possible as allanon_inodesshare a single inode.Quoted 5 lines
Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>--- fs/anon_inodes.c | 9 +++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 13 insertions(+)[NOTE: dropping dancol@google as that email is bouncy]
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 149
Quoted 7 lines
fs/anon_inodes.c +0
-0@@ -148,6 +148,15 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile);This function should have a comment block at the top similar to
anon_inode_getfile(); in fact you can likely copy-n-paste the bulk of it to use as a start.
Quoted 4 lines
If you don't want to bother respinning, I've got this exact patch (+comments) in my patchset that I'll post later and I'm happy to give/share credit if that is important to you.
That'd be great; no credit is fine :). Please CC me when you post it.
Quoted 4 lines
Quoted 4 lines
fs/anon_inodes.c +4
-0+struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode)
Quoted 8 lines
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 158
Quoted 4 lines
fs/anon_inodes.c +4
-0+{ +return __anon_inode_getfile (name, fops, priv, flags, context_inode, true); +} +EXPORT_SYMBOL_GPL (anon_inode_getfile_secure);--
paul moore
www.paul-moore.com
--
Kartikeya
Re: [PATCH 1/2] fs: anon_inodes: export anon_inode_getfile_secure helper
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 29 lines · Paul Moore
Quoted 7 lines · Kumar Kartikeya Dwivedi
This is the non-fd installing analogue of
anon_inode_getfd_secure. In addition to allowing LSMs to attach policy to the distinct inode, this is also needed for checkpoint restore of anio_uringinstance where a mapped region needs to mapped back to theio_uringfd by CRIU. This is currently not possible as allanon_inodesshare a single inode.Quoted 5 lines
Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>--- fs/anon_inodes.c | 9 +++++++++ include/linux/anon_inodes.h | 4 ++++ 2 files changed, 13 insertions(+)[NOTE: dropping dancol@google as that email is bouncy]
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 149
Quoted 7 lines
fs/anon_inodes.c +0
-0@@ -148,6 +148,15 @@ struct file *anon_inode_getfile(const char *name, }EXPORT_SYMBOL_GPL (anon_inode_getfile);This function should have a comment block at the top similar to
anon_inode_getfile(); in fact you can likely copy-n-paste the bulk of it to use as a start.
Quoted 6 lines
Quoted 4 lines
If you don't want to bother respinning, I've got this exact patch (+comments) in my patchset that I'll post later and I'm happy to give/share credit if that is important to you.
That'd be great; no credit is fine :). Please CC me when you post it.
Will do. I dug out my system which had the patches and I'm working on forward porting them to v5.13-rc2; if I don't have them cleaned up enough for posting by Thursday, I'll make sure they are at least RFC ready by Friday.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [PATCH 1/2] fs: anon_inodes: export anon_inode_getfile_secure helper
In reply to Kumar Kartikeya DwivediQuoted 5 lines · Kumar Kartikeya Dwivedi
This is the non-fd installing analogue of
anon_inode_getfd_secure. In addition to allowing LSMs to attach policy to the distinct inode, this is also needed for checkpoint restore of anio_uringinstance where a mapped region needs to mapped back to theio_uringfd by CRIU. This is currently not possible as allanon_inodesshare a single inode.
No need to export it, as io_uring can't be built modular.
fs/anon_inodes.c struct file *anon_inode_getfile(const char *name, · line 158
Quoted 8 lines
fs/anon_inodes.c +8
-0+struct file *anon_inode_getfile_secure (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct inode *context_inode) +{ +return __anon_inode_getfile (name, fops, priv, flags, context_inode, true); +} +EXPORT_SYMBOL_GPL (anon_inode_getfile_secure);
Please avoid the overly long line here.
PATCH 2/2 fs: io_uring: convert to use anon_inode_getfile_secure
In reply to Kumar Kartikeya DwivediMake io_uring use anon_inode_getfile_secure helper exposed in previous commit. This gives each io_uring instance a distinct inode.
--- fs/io_uring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/io_uring.c +2 -2
@@ -9454,8 +9454,8 @@ static struct file *io_uring_get_file(struct io_ring_ctx *ctx)return ERR_PTR (ret);#endif - file =anon_inode_getfile ("[io_uring]" , &io_uring_fops, ctx, -O_RDWR |O_CLOEXEC ); + file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +O_RDWR |O_CLOEXEC ,NULL );#if defined(CONFIG_UNIX )if (IS_ERR (file)) {sock_release (ctx->ring_sock);
Signature · 1 line
2.31.1
Quoted 9 lines · Kumar Kartikeya Dwivedi
This set converts
io_uringto use secureanon_inodes(with a newly allocated non-S_PRIVATE inode) for each individual instance. In addition to allowing LSM modules to enforce policy using the inode context, it also enables checkpoint/restore usecases by allowing mapping the VMA to the open fd in a task. Offset is already available to determine rings mapped per region, so this was the only missing piece in establishing region <->io_uringinstance mapping.LSM tie up has been left out of this set for now.
This brings to light something I have been trying to resolve for a little while now, but I have been finding it difficult to find the necessary time due to competing priorities at work and in my personal time. While the patches in this patchset are a necessary dependency, there are other issues which remain unresolved but which are now public (although the problems were not buried very far in the first place). Further complicating things on my end is that the system with my current work-in-progress patchset was taken offline two days ago and my office is under renovations :/
Give me a day or two to get the patches off that system and I'll post them here and we can start the process of kicking around solutions that work for everyone.
Signature · 2 lines
paul moore www.paul-moore.com