Lines Matching full:file
2 * memfd_create system call and file sealing support
7 * This file is released under the GPL.
13 #include <linux/file.h>
68 struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) in memfd_alloc_folio()
184 static unsigned int *memfd_file_seals_ptr(struct file *file) in memfd_file_seals_ptr() argument
186 if (shmem_file(file)) in memfd_file_seals_ptr()
187 return &SHMEM_I(file_inode(file))->seals; in memfd_file_seals_ptr()
190 if (is_file_hugepages(file)) in memfd_file_seals_ptr()
191 return &HUGETLBFS_I(file_inode(file))->seals; in memfd_file_seals_ptr()
204 static int memfd_add_seals(struct file *file, unsigned int seals) in memfd_add_seals() argument
206 struct inode *inode = file_inode(file); in memfd_add_seals()
212 * Sealing allows multiple parties to share a tmpfs or hugetlbfs file in memfd_add_seals()
213 * but restrict access to a specific subset of file operations. Seals in memfd_add_seals()
221 * may prevent some kinds of access to the file. Currently, the in memfd_add_seals()
223 * SEAL_SEAL: Prevent further seals from being set on this file in memfd_add_seals()
224 * SEAL_SHRINK: Prevent the file from shrinking in memfd_add_seals()
225 * SEAL_GROW: Prevent the file from growing in memfd_add_seals()
226 * SEAL_WRITE: Prevent write access to the file in memfd_add_seals()
227 * SEAL_EXEC: Prevent modification of the exec bits in the file mode in memfd_add_seals()
230 * must prevent seals from being removed. Therefore, sealing a file in memfd_add_seals()
231 * only adds a given set of seals to the file, it never touches in memfd_add_seals()
239 * no plan to support it on other file types. in memfd_add_seals()
242 if (!(file->f_mode & FMODE_WRITE)) in memfd_add_seals()
249 file_seals = memfd_file_seals_ptr(file); in memfd_add_seals()
261 error = mapping_deny_writable(file->f_mapping); in memfd_add_seals()
265 error = memfd_wait_for_pins(file->f_mapping); in memfd_add_seals()
267 mapping_allow_writable(file->f_mapping); in memfd_add_seals()
286 static int memfd_get_seals(struct file *file) in memfd_get_seals() argument
288 unsigned int *seals = memfd_file_seals_ptr(file); in memfd_get_seals()
293 long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg) in memfd_fcntl() argument
299 error = memfd_add_seals(file, arg); in memfd_fcntl()
302 error = memfd_get_seals(file); in memfd_fcntl()
371 int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr) in memfd_check_seals_mmap() argument
374 unsigned int *seals_ptr = memfd_file_seals_ptr(file); in memfd_check_seals_mmap()
432 static struct file *alloc_file(const char *name, unsigned int flags) in alloc_file()
435 struct file *file; in alloc_file() local
438 file = hugetlb_file_setup(name, 0, VM_NORESERVE, in alloc_file()
443 file = shmem_file_setup(name, 0, VM_NORESERVE); in alloc_file()
445 if (IS_ERR(file)) in alloc_file()
446 return file; in alloc_file()
447 file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; in alloc_file()
448 file->f_flags |= O_LARGEFILE; in alloc_file()
451 struct inode *inode = file_inode(file); in alloc_file()
454 file_seals = memfd_file_seals_ptr(file); in alloc_file()
461 file_seals = memfd_file_seals_ptr(file); in alloc_file()
466 return file; in alloc_file()
473 struct file *file; in SYSCALL_DEFINE2() local
491 file = alloc_file(name, flags); in SYSCALL_DEFINE2()
492 if (IS_ERR(file)) { in SYSCALL_DEFINE2()
493 error = PTR_ERR(file); in SYSCALL_DEFINE2()
497 fd_install(fd, file); in SYSCALL_DEFINE2()