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()
173 static unsigned int *memfd_file_seals_ptr(struct file *file) in memfd_file_seals_ptr() argument
175 if (shmem_file(file)) in memfd_file_seals_ptr()
176 return &SHMEM_I(file_inode(file))->seals; in memfd_file_seals_ptr()
179 if (is_file_hugepages(file)) in memfd_file_seals_ptr()
180 return &HUGETLBFS_I(file_inode(file))->seals; in memfd_file_seals_ptr()
193 static int memfd_add_seals(struct file *file, unsigned int seals) in memfd_add_seals() argument
195 struct inode *inode = file_inode(file); in memfd_add_seals()
201 * Sealing allows multiple parties to share a tmpfs or hugetlbfs file in memfd_add_seals()
202 * but restrict access to a specific subset of file operations. Seals in memfd_add_seals()
210 * may prevent some kinds of access to the file. Currently, the in memfd_add_seals()
212 * SEAL_SEAL: Prevent further seals from being set on this file in memfd_add_seals()
213 * SEAL_SHRINK: Prevent the file from shrinking in memfd_add_seals()
214 * SEAL_GROW: Prevent the file from growing in memfd_add_seals()
215 * SEAL_WRITE: Prevent write access to the file in memfd_add_seals()
216 * SEAL_EXEC: Prevent modification of the exec bits in the file mode in memfd_add_seals()
219 * must prevent seals from being removed. Therefore, sealing a file in memfd_add_seals()
220 * only adds a given set of seals to the file, it never touches in memfd_add_seals()
228 * no plan to support it on other file types. in memfd_add_seals()
231 if (!(file->f_mode & FMODE_WRITE)) in memfd_add_seals()
238 file_seals = memfd_file_seals_ptr(file); in memfd_add_seals()
250 error = mapping_deny_writable(file->f_mapping); in memfd_add_seals()
254 error = memfd_wait_for_pins(file->f_mapping); in memfd_add_seals()
256 mapping_allow_writable(file->f_mapping); in memfd_add_seals()
275 static int memfd_get_seals(struct file *file) in memfd_get_seals() argument
277 unsigned int *seals = memfd_file_seals_ptr(file); in memfd_get_seals()
282 long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg) in memfd_fcntl() argument
288 error = memfd_add_seals(file, arg); in memfd_fcntl()
291 error = memfd_get_seals(file); in memfd_fcntl()
360 int memfd_check_seals_mmap(struct file *file, unsigned long *vm_flags_ptr) in memfd_check_seals_mmap() argument
363 unsigned int *seals_ptr = memfd_file_seals_ptr(file); in memfd_check_seals_mmap()
421 static struct file *alloc_file(const char *name, unsigned int flags) in alloc_file()
424 struct file *file; in alloc_file() local
427 file = hugetlb_file_setup(name, 0, VM_NORESERVE, in alloc_file()
432 file = shmem_file_setup(name, 0, VM_NORESERVE); in alloc_file()
434 if (IS_ERR(file)) in alloc_file()
435 return file; in alloc_file()
436 file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; in alloc_file()
437 file->f_flags |= O_LARGEFILE; in alloc_file()
440 struct inode *inode = file_inode(file); in alloc_file()
443 file_seals = memfd_file_seals_ptr(file); in alloc_file()
450 file_seals = memfd_file_seals_ptr(file); in alloc_file()
455 return file; in alloc_file()
462 struct file *file; in SYSCALL_DEFINE2() local
480 file = alloc_file(name, flags); in SYSCALL_DEFINE2()
481 if (IS_ERR(file)) { in SYSCALL_DEFINE2()
482 error = PTR_ERR(file); in SYSCALL_DEFINE2()
486 fd_install(fd, file); in SYSCALL_DEFINE2()