Skip to content

Commit 3a862ca

Browse files
committed
fs: add anon_inode_getfile_secure() similar to anon_inode_getfd_secure()
Extending the secure anonymous inode support to other subsystems requires that we have a secure anon_inode_getfile() variant in addition to the existing secure anon_inode_getfd() variant. Thankfully we can reuse the existing __anon_inode_getfile() function and just wrap it with the proper arguments. Acked-by: Mickaël Salaün <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 67daf27 commit 3a862ca

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

fs/anon_inodes.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,35 @@ struct file *anon_inode_getfile(const char *name,
148148
}
149149
EXPORT_SYMBOL_GPL(anon_inode_getfile);
150150

151+
/**
152+
* anon_inode_getfile_secure - Like anon_inode_getfile(), but creates a new
153+
* !S_PRIVATE anon inode rather than reuse the
154+
* singleton anon inode and calls the
155+
* inode_init_security_anon() LSM hook. This
156+
* allows for both the inode to have its own
157+
* security context and for the LSM to enforce
158+
* policy on the inode's creation.
159+
*
160+
* @name: [in] name of the "class" of the new file
161+
* @fops: [in] file operations for the new file
162+
* @priv: [in] private data for the new file (will be file's private_data)
163+
* @flags: [in] flags
164+
* @context_inode:
165+
* [in] the logical relationship with the new inode (optional)
166+
*
167+
* The LSM may use @context_inode in inode_init_security_anon(), but a
168+
* reference to it is not held. Returns the newly created file* or an error
169+
* pointer. See the anon_inode_getfile() documentation for more information.
170+
*/
171+
struct file *anon_inode_getfile_secure(const char *name,
172+
const struct file_operations *fops,
173+
void *priv, int flags,
174+
const struct inode *context_inode)
175+
{
176+
return __anon_inode_getfile(name, fops, priv, flags,
177+
context_inode, true);
178+
}
179+
151180
static int __anon_inode_getfd(const char *name,
152181
const struct file_operations *fops,
153182
void *priv, int flags,

include/linux/anon_inodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ struct inode;
1515
struct file *anon_inode_getfile(const char *name,
1616
const struct file_operations *fops,
1717
void *priv, int flags);
18+
struct file *anon_inode_getfile_secure(const char *name,
19+
const struct file_operations *fops,
20+
void *priv, int flags,
21+
const struct inode *context_inode);
1822
int anon_inode_getfd(const char *name, const struct file_operations *fops,
1923
void *priv, int flags);
2024
int anon_inode_getfd_secure(const char *name,

0 commit comments

Comments
 (0)