samsung-goyawifi: add memfd syscall support (MR 3823)
[ci:skip-build] already built successfully in CI
This commit is contained in:
parent
51d8d6e20f
commit
512e7d3e4c
6 changed files with 601 additions and 0 deletions
|
@ -0,0 +1,71 @@
|
|||
From fcbd68fd6556b2f05c47a0399c2e6fd7689bfdab Mon Sep 17 00:00:00 2001
|
||||
From: Adrian Chelaru <che.adrian@yahoo.com>
|
||||
Date: Wed, 8 Feb 2023 16:14:24 +0000
|
||||
Subject: [PATCH 1/5] cache the value of file_inode() in struct file
|
||||
|
||||
---
|
||||
fs/file_table.c | 2 ++
|
||||
fs/open.c | 2 ++
|
||||
include/linux/fs.h | 6 ++++++
|
||||
3 files changed, 10 insertions(+)
|
||||
|
||||
diff --git a/fs/file_table.c b/fs/file_table.c
|
||||
index 70f2a0fd..768cf946 100644
|
||||
--- a/fs/file_table.c
|
||||
+++ b/fs/file_table.c
|
||||
@@ -176,6 +176,7 @@ struct file *alloc_file(struct path *path, fmode_t mode,
|
||||
return NULL;
|
||||
|
||||
file->f_path = *path;
|
||||
+ file->f_inode = path->dentry->d_inode;
|
||||
file->f_mapping = path->dentry->d_inode->i_mapping;
|
||||
file->f_mode = mode;
|
||||
file->f_op = fop;
|
||||
@@ -259,6 +260,7 @@ static void __fput(struct file *file)
|
||||
drop_file_write_access(file);
|
||||
file->f_path.dentry = NULL;
|
||||
file->f_path.mnt = NULL;
|
||||
+ file->f_inode = NULL;
|
||||
file_free(file);
|
||||
dput(dentry);
|
||||
mntput(mnt);
|
||||
diff --git a/fs/open.c b/fs/open.c
|
||||
index 3f1108b1..2c60e49b 100644
|
||||
--- a/fs/open.c
|
||||
+++ b/fs/open.c
|
||||
@@ -660,6 +660,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
|
||||
f->f_mode = FMODE_PATH;
|
||||
|
||||
inode = dentry->d_inode;
|
||||
+ f->f_inode = dentry->d_inode;
|
||||
if (f->f_mode & FMODE_WRITE) {
|
||||
error = __get_file_write_access(inode, mnt);
|
||||
if (error)
|
||||
@@ -733,6 +734,7 @@ cleanup_all:
|
||||
file_sb_list_del(f);
|
||||
f->f_path.dentry = NULL;
|
||||
f->f_path.mnt = NULL;
|
||||
+ f->f_inode = NULL;
|
||||
cleanup_file:
|
||||
put_filp(f);
|
||||
dput(dentry);
|
||||
diff --git a/include/linux/fs.h b/include/linux/fs.h
|
||||
index b827a8fd..a609ade3 100644
|
||||
--- a/include/linux/fs.h
|
||||
+++ b/include/linux/fs.h
|
||||
@@ -2221,6 +2221,12 @@ static inline bool execute_ok(struct inode *inode)
|
||||
return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode);
|
||||
}
|
||||
|
||||
+static inline struct inode *file_inode(struct file *f)
|
||||
+{
|
||||
+ /* return f->f_path.dentry->d_inode; / can also use this */
|
||||
+ return f->f_inode;
|
||||
+}
|
||||
+
|
||||
/*
|
||||
* get_write_access() gets write permission for a file.
|
||||
* put_write_access() releases this write permission.
|
||||
--
|
||||
2.38.3
|
||||
|
|
@ -0,0 +1,275 @@
|
|||
From f1aa94def8e22f23cf79619de558e4a4224c88ca Mon Sep 17 00:00:00 2001
|
||||
From: Adrian Chelaru <che.adrian@yahoo.com>
|
||||
Date: Wed, 8 Feb 2023 16:26:46 +0000
|
||||
Subject: [PATCH 2/5] Backport shm add sealing API
|
||||
|
||||
---
|
||||
fs/fcntl.c | 5 ++
|
||||
include/linux/fcntl.h | 16 +++++
|
||||
include/linux/shmem_fs.h | 18 ++++++
|
||||
mm/shmem.c | 122 +++++++++++++++++++++++++++++++++++++++
|
||||
4 files changed, 161 insertions(+)
|
||||
|
||||
diff --git a/fs/fcntl.c b/fs/fcntl.c
|
||||
index 75e7c1f3..e69774ee 100644
|
||||
--- a/fs/fcntl.c
|
||||
+++ b/fs/fcntl.c
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <linux/signal.h>
|
||||
#include <linux/rcupdate.h>
|
||||
#include <linux/pid_namespace.h>
|
||||
+#include <linux/shmem_fs.h>
|
||||
|
||||
#include <asm/poll.h>
|
||||
#include <asm/siginfo.h>
|
||||
@@ -420,6 +421,10 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
|
||||
case F_GETPIPE_SZ:
|
||||
err = pipe_fcntl(filp, cmd, arg);
|
||||
break;
|
||||
+ case F_ADD_SEALS:
|
||||
+ case F_GET_SEALS:
|
||||
+ err = shmem_fcntl(filp, cmd, arg);
|
||||
+ break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h
|
||||
index f550f894..2c39b178 100644
|
||||
--- a/include/linux/fcntl.h
|
||||
+++ b/include/linux/fcntl.h
|
||||
@@ -27,6 +27,22 @@
|
||||
#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
|
||||
#define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
|
||||
|
||||
+/*
|
||||
+ * Set/Get seals
|
||||
+ */
|
||||
+#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
|
||||
+#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
|
||||
+
|
||||
+/*
|
||||
+ * Types of seals
|
||||
+ */
|
||||
+#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
|
||||
+#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
|
||||
+#define F_SEAL_GROW 0x0004 /* prevent file from growing */
|
||||
+#define F_SEAL_WRITE 0x0008 /* prevent writes */
|
||||
+/* (1U << 31) is reserved for signed error codes */
|
||||
+
|
||||
+
|
||||
/*
|
||||
* Types of directory notifications that may be requested.
|
||||
*/
|
||||
diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
|
||||
index 79ab2555..c08c0907 100644
|
||||
--- a/include/linux/shmem_fs.h
|
||||
+++ b/include/linux/shmem_fs.h
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __SHMEM_FS_H
|
||||
#define __SHMEM_FS_H
|
||||
|
||||
+#include <linux/file.h>
|
||||
#include <linux/swap.h>
|
||||
#include <linux/mempolicy.h>
|
||||
#include <linux/pagemap.h>
|
||||
@@ -11,6 +12,7 @@
|
||||
struct shmem_inode_info {
|
||||
spinlock_t lock;
|
||||
unsigned long flags;
|
||||
+ unsigned int seals; /* shmem seals */
|
||||
unsigned long alloced; /* data pages alloced to file */
|
||||
union {
|
||||
unsigned long swapped; /* subtotal assigned to swap */
|
||||
@@ -61,4 +63,20 @@ static inline struct page *shmem_read_mapping_page(
|
||||
mapping_gfp_mask(mapping));
|
||||
}
|
||||
|
||||
+#ifdef CONFIG_TMPFS
|
||||
+
|
||||
+extern int shmem_add_seals(struct file *file, unsigned int seals);
|
||||
+extern int shmem_get_seals(struct file *file);
|
||||
+extern long shmem_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
|
||||
+
|
||||
+#else
|
||||
+
|
||||
+static inline long shmem_fcntl(struct file *f, unsigned int c, unsigned long a)
|
||||
+{
|
||||
+ return -EINVAL;
|
||||
+}
|
||||
+
|
||||
+#endif
|
||||
+
|
||||
+
|
||||
#endif
|
||||
diff --git a/mm/shmem.c b/mm/shmem.c
|
||||
index deb9d406..fbb6b2fc 100644
|
||||
--- a/mm/shmem.c
|
||||
+++ b/mm/shmem.c
|
||||
@@ -63,6 +63,7 @@ static struct vfsmount *shm_mnt;
|
||||
#include <linux/highmem.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/magic.h>
|
||||
+#include <linux/fcntl.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/pgtable.h>
|
||||
@@ -543,6 +544,7 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
|
||||
static int shmem_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
+ struct shmem_inode_info *info = SHMEM_I(inode);
|
||||
int error;
|
||||
|
||||
error = inode_change_ok(inode, attr);
|
||||
@@ -553,6 +555,11 @@ static int shmem_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
loff_t oldsize = inode->i_size;
|
||||
loff_t newsize = attr->ia_size;
|
||||
|
||||
+ /* protected by i_mutex */
|
||||
+ if ((newsize < oldsize && (info->seals & F_SEAL_SHRINK)) ||
|
||||
+ (newsize > oldsize && (info->seals & F_SEAL_GROW)))
|
||||
+ return -EPERM;
|
||||
+
|
||||
if (newsize != oldsize) {
|
||||
i_size_write(inode, newsize);
|
||||
inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
@@ -1146,6 +1153,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
|
||||
info = SHMEM_I(inode);
|
||||
memset(info, 0, (char *)inode - (char *)info);
|
||||
spin_lock_init(&info->lock);
|
||||
+ info->seals = F_SEAL_SEAL;
|
||||
info->flags = flags & VM_NORESERVE;
|
||||
INIT_LIST_HEAD(&info->swaplist);
|
||||
INIT_LIST_HEAD(&info->xattr_list);
|
||||
@@ -1199,7 +1207,17 @@ shmem_write_begin(struct file *file, struct address_space *mapping,
|
||||
struct page **pagep, void **fsdata)
|
||||
{
|
||||
struct inode *inode = mapping->host;
|
||||
+ struct shmem_inode_info *info = SHMEM_I(inode);
|
||||
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
|
||||
+
|
||||
+ /* i_mutex is held by caller */
|
||||
+ if (unlikely(info->seals)) {
|
||||
+ if (info->seals & F_SEAL_WRITE)
|
||||
+ return -EPERM;
|
||||
+ if ((info->seals & F_SEAL_GROW) && pos + len > inode->i_size)
|
||||
+ return -EPERM;
|
||||
+ }
|
||||
+
|
||||
return shmem_getpage(inode, index, pagep, SGP_WRITE, NULL);
|
||||
}
|
||||
|
||||
@@ -1472,6 +1490,110 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
|
||||
return error;
|
||||
}
|
||||
|
||||
+static int shmem_wait_for_pins(struct address_space *mapping)
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+#define F_ALL_SEALS (F_SEAL_SEAL | \
|
||||
+ F_SEAL_SHRINK | \
|
||||
+ F_SEAL_GROW | \
|
||||
+ F_SEAL_WRITE)
|
||||
+
|
||||
+int shmem_add_seals(struct file *file, unsigned int seals)
|
||||
+{
|
||||
+ struct inode *inode = file_inode(file);
|
||||
+ struct shmem_inode_info *info = SHMEM_I(inode);
|
||||
+ int error;
|
||||
+
|
||||
+ /*
|
||||
+ * SEALING
|
||||
+ * Sealing allows multiple parties to share a shmem-file but restrict
|
||||
+ * access to a specific subset of file operations. Seals can only be
|
||||
+ * added, but never removed. This way, mutually untrusted parties can
|
||||
+ * share common memory regions with a well-defined policy. A malicious
|
||||
+ * peer can thus never perform unwanted operations on a shared object.
|
||||
+ *
|
||||
+ * Seals are only supported on special shmem-files and always affect
|
||||
+ * the whole underlying inode. Once a seal is set, it may prevent some
|
||||
+ * kinds of access to the file. Currently, the following seals are
|
||||
+ * defined:
|
||||
+ * SEAL_SEAL: Prevent further seals from being set on this file
|
||||
+ * SEAL_SHRINK: Prevent the file from shrinking
|
||||
+ * SEAL_GROW: Prevent the file from growing
|
||||
+ * SEAL_WRITE: Prevent write access to the file
|
||||
+ *
|
||||
+ * As we don't require any trust relationship between two parties, we
|
||||
+ * must prevent seals from being removed. Therefore, sealing a file
|
||||
+ * only adds a given set of seals to the file, it never touches
|
||||
+ * existing seals. Furthermore, the "setting seals"-operation can be
|
||||
+ * sealed itself, which basically prevents any further seal from being
|
||||
+ * added.
|
||||
+ *
|
||||
+ * Semantics of sealing are only defined on volatile files. Only
|
||||
+ * anonymous shmem files support sealing. More importantly, seals are
|
||||
+ * never written to disk. Therefore, there's no plan to support it on
|
||||
+ * other file types.
|
||||
+ */
|
||||
+
|
||||
+ if (file->f_op != &shmem_file_operations)
|
||||
+ return -EINVAL;
|
||||
+ if (!(file->f_mode & FMODE_WRITE))
|
||||
+ return -EPERM;
|
||||
+ if (seals & ~(unsigned int)F_ALL_SEALS)
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ mutex_lock(&inode->i_mutex);
|
||||
+
|
||||
+ if (info->seals & F_SEAL_SEAL) {
|
||||
+ error = -EPERM;
|
||||
+ goto unlock;
|
||||
+ }
|
||||
+
|
||||
+ /* TODO: this is the place to actually apply seals to
|
||||
+ * file->f_mapping, but this was not backported yet */
|
||||
+
|
||||
+ info->seals |= seals;
|
||||
+ error = 0;
|
||||
+
|
||||
+unlock:
|
||||
+ mutex_unlock(&inode->i_mutex);
|
||||
+ return error;
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(shmem_add_seals);
|
||||
+
|
||||
+int shmem_get_seals(struct file *file)
|
||||
+{
|
||||
+ if (file->f_op != &shmem_file_operations)
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ return SHMEM_I(file_inode(file))->seals;
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(shmem_get_seals);
|
||||
+
|
||||
+long shmem_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||
+{
|
||||
+ long error;
|
||||
+
|
||||
+ switch (cmd) {
|
||||
+ case F_ADD_SEALS:
|
||||
+ /* disallow upper 32bit */
|
||||
+ if (arg > UINT_MAX)
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ error = shmem_add_seals(file, arg);
|
||||
+ break;
|
||||
+ case F_GET_SEALS:
|
||||
+ error = shmem_get_seals(file);
|
||||
+ break;
|
||||
+ default:
|
||||
+ error = -EINVAL;
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return error;
|
||||
+}
|
||||
+
|
||||
static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
|
||||
{
|
||||
struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
|
||||
--
|
||||
2.38.3
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
From e6525eb45b8c8eafc18fb08cfa13df29435f984a Mon Sep 17 00:00:00 2001
|
||||
From: Adrian Chelaru <che.adrian@yahoo.com>
|
||||
Date: Wed, 8 Feb 2023 16:33:36 +0000
|
||||
Subject: [PATCH 3/5] Backport shm add memfd create syscall
|
||||
|
||||
---
|
||||
arch/x86/syscalls/syscall_32.tbl | 1 +
|
||||
arch/x86/syscalls/syscall_64.tbl | 1 +
|
||||
include/linux/syscalls.h | 1 +
|
||||
include/uapi/linux/memfd.h | 8 ++++
|
||||
kernel/sys_ni.c | 1 +
|
||||
mm/shmem.c | 74 ++++++++++++++++++++++++++++++++
|
||||
6 files changed, 86 insertions(+)
|
||||
create mode 100644 include/uapi/linux/memfd.h
|
||||
|
||||
diff --git a/arch/x86/syscalls/syscall_32.tbl b/arch/x86/syscalls/syscall_32.tbl
|
||||
index 29f9f055..199c47e8 100644
|
||||
--- a/arch/x86/syscalls/syscall_32.tbl
|
||||
+++ b/arch/x86/syscalls/syscall_32.tbl
|
||||
@@ -355,3 +355,4 @@
|
||||
346 i386 setns sys_setns
|
||||
347 i386 process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv
|
||||
348 i386 process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev
|
||||
+356 i386 memfd_create sys_memfd_create
|
||||
diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl
|
||||
index dd29a9ea..6b52cf60 100644
|
||||
--- a/arch/x86/syscalls/syscall_64.tbl
|
||||
+++ b/arch/x86/syscalls/syscall_64.tbl
|
||||
@@ -318,6 +318,7 @@
|
||||
309 common getcpu sys_getcpu
|
||||
310 64 process_vm_readv sys_process_vm_readv
|
||||
311 64 process_vm_writev sys_process_vm_writev
|
||||
+319 common memfd_create sys_memfd_create
|
||||
#
|
||||
# x32-specific system call numbers start at 512 to avoid cache impact
|
||||
# for native 64-bit operation.
|
||||
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
|
||||
index 3de3acb8..d97575d9 100644
|
||||
--- a/include/linux/syscalls.h
|
||||
+++ b/include/linux/syscalls.h
|
||||
@@ -813,6 +813,7 @@ asmlinkage long sys_timerfd_settime(int ufd, int flags,
|
||||
asmlinkage long sys_timerfd_gettime(int ufd, struct itimerspec __user *otmr);
|
||||
asmlinkage long sys_eventfd(unsigned int count);
|
||||
asmlinkage long sys_eventfd2(unsigned int count, int flags);
|
||||
+asmlinkage long sys_memfd_create(const char __user *uname_ptr, unsigned int flags);
|
||||
asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
|
||||
asmlinkage long sys_old_readdir(unsigned int, struct old_linux_dirent __user *, unsigned int);
|
||||
asmlinkage long sys_pselect6(int, fd_set __user *, fd_set __user *,
|
||||
diff --git a/include/uapi/linux/memfd.h b/include/uapi/linux/memfd.h
|
||||
new file mode 100644
|
||||
index 00000000..9a772654
|
||||
--- /dev/null
|
||||
+++ b/include/uapi/linux/memfd.h
|
||||
@@ -0,0 +1,8 @@
|
||||
+#ifndef _UAPI_LINUX_MEMFD_H
|
||||
+#define _UAPI_LINUX_MEMFD_H
|
||||
+
|
||||
+/* flags for memfd_create(2) (unsigned int) */
|
||||
+#define MFD_CLOEXEC 0x0001U
|
||||
+#define MFD_ALLOW_SEALING 0x0002U
|
||||
+
|
||||
+#endif /* _UAPI_LINUX_MEMFD_H */
|
||||
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
|
||||
index 47bfa164..f2d7d96f 100644
|
||||
--- a/kernel/sys_ni.c
|
||||
+++ b/kernel/sys_ni.c
|
||||
@@ -191,6 +191,7 @@ cond_syscall(compat_sys_timerfd_settime);
|
||||
cond_syscall(compat_sys_timerfd_gettime);
|
||||
cond_syscall(sys_eventfd);
|
||||
cond_syscall(sys_eventfd2);
|
||||
+cond_syscall(sys_memfd_create);
|
||||
|
||||
/* performance counters: */
|
||||
cond_syscall(sys_perf_event_open);
|
||||
diff --git a/mm/shmem.c b/mm/shmem.c
|
||||
index fbb6b2fc..625fbf09 100644
|
||||
--- a/mm/shmem.c
|
||||
+++ b/mm/shmem.c
|
||||
@@ -63,7 +63,9 @@ static struct vfsmount *shm_mnt;
|
||||
#include <linux/highmem.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/magic.h>
|
||||
+#include <linux/syscalls.h>
|
||||
#include <linux/fcntl.h>
|
||||
+#include <uapi/linux/memfd.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/pgtable.h>
|
||||
@@ -2349,6 +2351,78 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root)
|
||||
shmem_show_mpol(seq, sbinfo->mpol);
|
||||
return 0;
|
||||
}
|
||||
+
|
||||
+
|
||||
+#define MFD_NAME_PREFIX "memfd:"
|
||||
+#define MFD_NAME_PREFIX_LEN (sizeof(MFD_NAME_PREFIX) - 1)
|
||||
+#define MFD_NAME_MAX_LEN (NAME_MAX - MFD_NAME_PREFIX_LEN)
|
||||
+
|
||||
+#define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING)
|
||||
+
|
||||
+SYSCALL_DEFINE2(memfd_create,
|
||||
+ const char __user *, uname,
|
||||
+ unsigned int, flags)
|
||||
+{
|
||||
+ struct shmem_inode_info *info;
|
||||
+ struct file *file;
|
||||
+ int fd, error;
|
||||
+ char *name;
|
||||
+ long len;
|
||||
+
|
||||
+ if (flags & ~(unsigned int)MFD_ALL_FLAGS)
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ /* length includes terminating zero */
|
||||
+ len = strnlen_user(uname, MFD_NAME_MAX_LEN + 1);
|
||||
+ if (len <= 0)
|
||||
+ return -EFAULT;
|
||||
+ if (len > MFD_NAME_MAX_LEN + 1)
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ name = kmalloc(len + MFD_NAME_PREFIX_LEN, GFP_TEMPORARY);
|
||||
+ if (!name)
|
||||
+ return -ENOMEM;
|
||||
+
|
||||
+ strcpy(name, MFD_NAME_PREFIX);
|
||||
+ if (copy_from_user(&name[MFD_NAME_PREFIX_LEN], uname, len)) {
|
||||
+ error = -EFAULT;
|
||||
+ goto err_name;
|
||||
+ }
|
||||
+
|
||||
+ /* terminating-zero may have changed after strnlen_user() returned */
|
||||
+ if (name[len + MFD_NAME_PREFIX_LEN - 1]) {
|
||||
+ error = -EFAULT;
|
||||
+ goto err_name;
|
||||
+ }
|
||||
+
|
||||
+ fd = get_unused_fd_flags((flags & MFD_CLOEXEC) ? O_CLOEXEC : 0);
|
||||
+ if (fd < 0) {
|
||||
+ error = fd;
|
||||
+ goto err_name;
|
||||
+ }
|
||||
+
|
||||
+ file = shmem_file_setup(name, 0, VM_NORESERVE);
|
||||
+ if (IS_ERR(file)) {
|
||||
+ error = PTR_ERR(file);
|
||||
+ goto err_fd;
|
||||
+ }
|
||||
+ info = SHMEM_I(file_inode(file));
|
||||
+ file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
|
||||
+ file->f_flags |= O_RDWR | O_LARGEFILE;
|
||||
+ if (flags & MFD_ALLOW_SEALING)
|
||||
+ info->seals &= ~F_SEAL_SEAL;
|
||||
+
|
||||
+ fd_install(fd, file);
|
||||
+ kfree(name);
|
||||
+ return fd;
|
||||
+
|
||||
+err_fd:
|
||||
+ put_unused_fd(fd);
|
||||
+err_name:
|
||||
+ kfree(name);
|
||||
+ return error;
|
||||
+}
|
||||
+
|
||||
#endif /* CONFIG_TMPFS */
|
||||
|
||||
static void shmem_put_super(struct super_block *sb)
|
||||
--
|
||||
2.38.3
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
From 2e9b4f85f5c1eb2bd269c0dbd1e201841c4c5014 Mon Sep 17 00:00:00 2001
|
||||
From: Adrian Chelaru <che.adrian@yahoo.com>
|
||||
Date: Wed, 8 Feb 2023 16:40:33 +0000
|
||||
Subject: [PATCH 4/5] Backport asm generic add memfd_create system call to
|
||||
unistd
|
||||
|
||||
---
|
||||
include/asm-generic/unistd.h | 4 +++-
|
||||
1 file changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/asm-generic/unistd.h b/include/asm-generic/unistd.h
|
||||
index 991ef01c..f36a75c2 100644
|
||||
--- a/include/asm-generic/unistd.h
|
||||
+++ b/include/asm-generic/unistd.h
|
||||
@@ -691,9 +691,11 @@ __SC_COMP(__NR_process_vm_readv, sys_process_vm_readv, \
|
||||
#define __NR_process_vm_writev 271
|
||||
__SC_COMP(__NR_process_vm_writev, sys_process_vm_writev, \
|
||||
compat_sys_process_vm_writev)
|
||||
+#define __NR_memfd_create 279
|
||||
+__SYSCALL(__NR_memfd_create, sys_memfd_create)
|
||||
|
||||
#undef __NR_syscalls
|
||||
-#define __NR_syscalls 272
|
||||
+#define __NR_syscalls 280
|
||||
|
||||
/*
|
||||
* All syscalls below here should go away really,
|
||||
--
|
||||
2.38.3
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
From da83e93d50ff2dd71f6c8a86d657c2e4793f80dd Mon Sep 17 00:00:00 2001
|
||||
From: Adrian Chelaru <che.adrian@yahoo.com>
|
||||
Date: Wed, 8 Feb 2023 16:45:22 +0000
|
||||
Subject: [PATCH 5/5] Backport ARM wire up memfd_create syscall
|
||||
|
||||
---
|
||||
arch/arm/include/asm/unistd.h | 2 +-
|
||||
arch/arm/kernel/calls.S | 2 ++
|
||||
2 files changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h
|
||||
index 512cd147..f5e64a31 100644
|
||||
--- a/arch/arm/include/asm/unistd.h
|
||||
+++ b/arch/arm/include/asm/unistd.h
|
||||
@@ -404,7 +404,7 @@
|
||||
#define __NR_setns (__NR_SYSCALL_BASE+375)
|
||||
#define __NR_process_vm_readv (__NR_SYSCALL_BASE+376)
|
||||
#define __NR_process_vm_writev (__NR_SYSCALL_BASE+377)
|
||||
-
|
||||
+#define __NR_memfd_create (__NR_SYSCALL_BASE+385)
|
||||
/*
|
||||
* The following SWIs are ARM private.
|
||||
*/
|
||||
diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S
|
||||
index 463ff4a0..2ee871e2 100644
|
||||
--- a/arch/arm/kernel/calls.S
|
||||
+++ b/arch/arm/kernel/calls.S
|
||||
@@ -387,6 +387,14 @@
|
||||
/* 375 */ CALL(sys_setns)
|
||||
CALL(sys_process_vm_readv)
|
||||
CALL(sys_process_vm_writev)
|
||||
+ CALL(sys_ni_syscall)
|
||||
+ CALL(sys_ni_syscall)
|
||||
+/* 380 */ CALL(sys_ni_syscall)
|
||||
+ CALL(sys_ni_syscall)
|
||||
+ CALL(sys_ni_syscall)
|
||||
+ CALL(sys_ni_syscall)
|
||||
+ CALL(sys_ni_syscall)
|
||||
+/* 385 */ CALL(sys_memfd_create)
|
||||
#ifndef syscalls_counted
|
||||
.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
|
||||
#define syscalls_counted
|
||||
--
|
||||
2.38.3
|
||||
|
|
@ -34,6 +34,11 @@ source="
|
|||
fix_the_memset_fix.patch
|
||||
gcc10-extern_YYLOC_global_declaration.patch
|
||||
fix_makefile.patch
|
||||
0001-cache-the-value-of-file_inode-in-struct-file.patch
|
||||
0002-Backport-shm-add-sealing-API.patch
|
||||
0003-Backport-shm-add-memfd-create-syscall.patch
|
||||
0004-Backport-asm-generic-add-memfd_create-system-call-to.patch
|
||||
0005-Backport-ARM-wire-up-memfd_create-syscall.patch
|
||||
"
|
||||
builddir="$srcdir/$_repository-$_commit"
|
||||
|
||||
|
@ -67,4 +72,9 @@ efd1641c0892fddb9c5feea3e49e534fed311b01f0576688b5af766e0160850822d0eb8e296b08c5
|
|||
5c080c27716d124616e4e684fc63bffb2665f00de06e894dfd78f58588feec2fec858fe8234b054061e3db14d28cb90fbac53f4b54c4fac5946d843cf038386c fix_the_memset_fix.patch
|
||||
2b48f1bf0e3f70703d2cdafc47d5e615cc7c56c70bec56b2e3297d3fa4a7a1321d649a8679614553dde8fe52ff1051dae38d5990e3744c9ca986d92187dcdbeb gcc10-extern_YYLOC_global_declaration.patch
|
||||
fb16404be045f4d9c7bf29512321ec2a4cb17111a8c870adff91889f0e6b314265cddb5dd9caa8088425902d2032e9dac4b6ba8c648b32df0efd78edf24550c1 fix_makefile.patch
|
||||
8a0963c2f24e7c784e53781a5a16e540c9aa6fc3db0c9f8d83d28b0a30604472054ca3058051e34fcd900c167af0a68943f4ebffc327f5594361d8eb345c37c4 0001-cache-the-value-of-file_inode-in-struct-file.patch
|
||||
0fede4dd36632e03d3d2d0d7b73038520319b585f1fffbdf005fa2b5b37485ae0ecee0f6ef53906bfe81f7303774b8c7bcd1f85fb1b7a030f596d63eac8df833 0002-Backport-shm-add-sealing-API.patch
|
||||
560b46dab45b14fa0a9fbdb9ddb2bb597a9914b25bb5591d2e24eb483bcc506ee413ac873eb7543a3112e53b535f5e3b1745409c6dc1a62b2651dda766eb1782 0003-Backport-shm-add-memfd-create-syscall.patch
|
||||
e07d7e0104cd37fa45cfb54bda8f6ebaa0ce8a54fa12e57133f0cb1ccc96c5133a25ba936678228b4ffb21a7c65a546e35004935afbf6e8f008265a687cfb0d3 0004-Backport-asm-generic-add-memfd_create-system-call-to.patch
|
||||
22822ab84f3179c749eae3d44ea123c72d24399d8af52f603fceb5ca3f323da33eb0b7656a7db4c6b04963d7b118abbc4ae5def07f1db6066bcc5a7403a11dd4 0005-Backport-ARM-wire-up-memfd_create-syscall.patch
|
||||
"
|
||||
|
|
Loading…
Reference in a new issue