From: Ryan Afranji <afranji@google.com>
To: afranji@google.com, ackerleytng@google.com, pbonzini@redhat.com,
seanjc@google.com, tglx@linutronix.de, x86@kernel.org,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, tabba@google.com
Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
hpa@zytor.com, shuah@kernel.org, andrew.jones@linux.dev,
ricarkol@google.com, chao.p.peng@linux.intel.com,
jarkko@kernel.org, yu.c.zhang@linux.intel.com,
vannapurve@google.com, erdemaktas@google.com,
mail@maciej.szmigiero.name, vbabka@suse.cz, david@redhat.com,
qperret@google.com, michael.roth@amd.com, wei.w.wang@intel.com,
liam.merwick@oracle.com, isaku.yamahata@gmail.com,
kirill.shutemov@linux.intel.com, sagis@google.com,
jthoughton@google.com
Subject: [RFC PATCH v2 01/13] fs: Refactor to provide function that allocates a secure anonymous inode
Date: Fri, 16 May 2025 19:19:21 +0000 [thread overview]
Message-ID: <1f42c32fc18d973b8ec97c8be8b7cd921912d42a.1747368092.git.afranji@google.com> (raw)
In-Reply-To: <cover.1747368092.git.afranji@google.com>
From: David Hildenbrand <david@redhat.com>
alloc_anon_secure_inode() returns an inode after running checks in
security_inode_init_security_anon().
Also refactor secretmem's file creation process to use the new
function.
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
Signed-off-by: Ryan Afranji <afranji@google.com>
---
fs/anon_inodes.c | 23 ++++++++++++++++-------
include/linux/fs.h | 13 +++++++------
mm/secretmem.c | 9 +--------
3 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 583ac81669c2..0ce28959c43a 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -55,17 +55,20 @@ static struct file_system_type anon_inode_fs_type = {
.kill_sb = kill_anon_super,
};
-static struct inode *anon_inode_make_secure_inode(
- const char *name,
- const struct inode *context_inode)
+static struct inode *anon_inode_make_secure_inode(struct super_block *s,
+ const char *name, const struct inode *context_inode,
+ bool fs_internal)
{
struct inode *inode;
int error;
- inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
+ inode = alloc_anon_inode(s);
if (IS_ERR(inode))
return inode;
- inode->i_flags &= ~S_PRIVATE;
+
+ if (!fs_internal)
+ inode->i_flags &= ~S_PRIVATE;
+
error = security_inode_init_security_anon(inode, &QSTR(name),
context_inode);
if (error) {
@@ -75,6 +78,12 @@ static struct inode *anon_inode_make_secure_inode(
return inode;
}
+struct inode *alloc_anon_secure_inode(struct super_block *s, const char *name)
+{
+ return anon_inode_make_secure_inode(s, name, NULL, true);
+}
+EXPORT_SYMBOL_GPL(alloc_anon_secure_inode);
+
static struct file *__anon_inode_getfile(const char *name,
const struct file_operations *fops,
void *priv, int flags,
@@ -88,7 +97,8 @@ static struct file *__anon_inode_getfile(const char *name,
return ERR_PTR(-ENOENT);
if (make_inode) {
- inode = anon_inode_make_secure_inode(name, context_inode);
+ inode = anon_inode_make_secure_inode(anon_inode_mnt->mnt_sb,
+ name, context_inode, false);
if (IS_ERR(inode)) {
file = ERR_CAST(inode);
goto err;
@@ -318,4 +328,3 @@ static int __init anon_inode_init(void)
}
fs_initcall(anon_inode_init);
-
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 016b0fe1536e..8eeef9a7fe07 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -309,7 +309,7 @@ struct iattr {
*/
#define FILESYSTEM_MAX_STACK_DEPTH 2
-/**
+/**
* enum positive_aop_returns - aop return codes with specific semantics
*
* @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
@@ -319,7 +319,7 @@ struct iattr {
* be a candidate for writeback again in the near
* future. Other callers must be careful to unlock
* the page if they get this return. Returned by
- * writepage();
+ * writepage();
*
* @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
* unlocked it and the page might have been truncated.
@@ -1141,8 +1141,8 @@ struct file *get_file_active(struct file **f);
#define MAX_NON_LFS ((1UL<<31) - 1)
-/* Page cache limit. The filesystems should put that into their s_maxbytes
- limits, otherwise bad things can happen in VM. */
+/* Page cache limit. The filesystems should put that into their s_maxbytes
+ limits, otherwise bad things can happen in VM. */
#if BITS_PER_LONG==32
#define MAX_LFS_FILESIZE ((loff_t)ULONG_MAX << PAGE_SHIFT)
#elif BITS_PER_LONG==64
@@ -2607,7 +2607,7 @@ int sync_inode_metadata(struct inode *inode, int wait);
struct file_system_type {
const char *name;
int fs_flags;
-#define FS_REQUIRES_DEV 1
+#define FS_REQUIRES_DEV 1
#define FS_BINARY_MOUNTDATA 2
#define FS_HAS_SUBTYPE 4
#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
@@ -3195,7 +3195,7 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos);
extern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *);
extern ssize_t __kernel_write(struct file *, const void *, size_t, loff_t *);
extern struct file * open_exec(const char *);
-
+
/* fs/dcache.c -- generic fs support functions */
extern bool is_subdir(struct dentry *, struct dentry *);
extern bool path_is_under(const struct path *, const struct path *);
@@ -3550,6 +3550,7 @@ extern int simple_write_begin(struct file *file, struct address_space *mapping,
extern const struct address_space_operations ram_aops;
extern int always_delete_dentry(const struct dentry *);
extern struct inode *alloc_anon_inode(struct super_block *);
+extern struct inode *alloc_anon_secure_inode(struct super_block *, const char *);
extern int simple_nosetlease(struct file *, int, struct file_lease **, void **);
extern const struct dentry_operations simple_dentry_operations;
diff --git a/mm/secretmem.c b/mm/secretmem.c
index 1b0a214ee558..c0e459e58cb6 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -195,18 +195,11 @@ static struct file *secretmem_file_create(unsigned long flags)
struct file *file;
struct inode *inode;
const char *anon_name = "[secretmem]";
- int err;
- inode = alloc_anon_inode(secretmem_mnt->mnt_sb);
+ inode = alloc_anon_secure_inode(secretmem_mnt->mnt_sb, anon_name);
if (IS_ERR(inode))
return ERR_CAST(inode);
- err = security_inode_init_security_anon(inode, &QSTR(anon_name), 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.49.0.1101.gccaa498523-goog
next prev parent reply other threads:[~2025-05-16 19:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-16 19:19 [RFC PATCH v2 00/13] New KVM ioctl to link a gmem inode to a new gmem file Ryan Afranji
2025-05-16 19:19 ` Ryan Afranji [this message]
2025-05-16 19:19 ` [RFC PATCH v2 02/13] KVM: guest_memfd: Make guest mem use guest mem inodes instead of anonymous inodes Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 03/13] KVM: guest_mem: Refactor out kvm_gmem_alloc_view() Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 04/13] KVM: guest_mem: Add ioctl KVM_LINK_GUEST_MEMFD Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 05/13] KVM: selftests: Add tests for KVM_LINK_GUEST_MEMFD ioctl Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 06/13] KVM: selftests: Test transferring private memory to another VM Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 07/13] KVM: x86: Refactor sev's flag migration_in_progress to kvm struct Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 08/13] KVM: x86: Refactor common code out of sev.c Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 09/13] KVM: x86: Refactor common migration preparation code out of sev_vm_move_enc_context_from Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 10/13] KVM: x86: Let moving encryption context be configurable Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 11/13] KVM: x86: Handle moving of memory context for intra-host migration Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 12/13] KVM: selftests: Generalize migration functions from sev_migrate_tests.c Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 13/13] KVM: selftests: Add tests for migration of private mem Ryan Afranji
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1f42c32fc18d973b8ec97c8be8b7cd921912d42a.1747368092.git.afranji@google.com \
--to=afranji@google.com \
--cc=ackerleytng@google.com \
--cc=andrew.jones@linux.dev \
--cc=bp@alien8.de \
--cc=chao.p.peng@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=erdemaktas@google.com \
--cc=hpa@zytor.com \
--cc=isaku.yamahata@gmail.com \
--cc=jarkko@kernel.org \
--cc=jthoughton@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mail@maciej.szmigiero.name \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qperret@google.com \
--cc=ricarkol@google.com \
--cc=sagis@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=tabba@google.com \
--cc=tglx@linutronix.de \
--cc=vannapurve@google.com \
--cc=vbabka@suse.cz \
--cc=wei.w.wang@intel.com \
--cc=x86@kernel.org \
--cc=yu.c.zhang@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®