Skip to content

Commit b013ed4

Browse files
ljskernelbrauner
authored andcommitted
fs: consistently use can_mmap_file() helper
Since commit c84bf6d ("mm: introduce new .mmap_prepare() file callback"), the f_op->mmap() hook has been deprecated in favour of f_op->mmap_prepare(). Additionally, commit bb666b7 ("mm: add mmap_prepare() compatibility layer for nested file systems") permits the use of the .mmap_prepare() hook even in nested filesystems like overlayfs. There are a number of places where we check only for f_op->mmap - this is incorrect now mmap_prepare exists, so update all of these to use the general helper can_mmap_file(). Most notably, this updates the elf logic to allow for the ability to execute binaries on filesystems which have the .mmap_prepare hook, but additionally we update nested filesystems. Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Link: https://lore.kernel.org/b68145b609532e62bab603dd9686faa6562046ec.1750099179.git.lorenzo.stoakes@oracle.com Acked-by: Kees Cook <kees@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent c6900f2 commit b013ed4

9 files changed

Lines changed: 10 additions & 10 deletions

File tree

fs/backing-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
333333
if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)))
334334
return -EIO;
335335

336-
if (!file->f_op->mmap)
336+
if (!can_mmap_file(file))
337337
return -ENODEV;
338338

339339
vma_set_file(vma, file);

fs/binfmt_elf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
646646
if (!elf_check_arch(interp_elf_ex) ||
647647
elf_check_fdpic(interp_elf_ex))
648648
goto out;
649-
if (!interpreter->f_op->mmap)
649+
if (!can_mmap_file(interpreter))
650650
goto out;
651651

652652
total_size = total_mapping_size(interp_elf_phdata,
@@ -848,7 +848,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
848848
goto out;
849849
if (elf_check_fdpic(elf_ex))
850850
goto out;
851-
if (!bprm->file->f_op->mmap)
851+
if (!can_mmap_file(bprm->file))
852852
goto out;
853853

854854
elf_phdata = load_elf_phdrs(elf_ex, bprm->file);

fs/binfmt_elf_fdpic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int is_elf(struct elfhdr *hdr, struct file *file)
109109
return 0;
110110
if (!elf_check_arch(hdr))
111111
return 0;
112-
if (!file->f_op->mmap)
112+
if (!can_mmap_file(file))
113113
return 0;
114114
return 1;
115115
}

fs/coda/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
160160
size_t count;
161161
int ret;
162162

163-
if (!host_file->f_op->mmap)
163+
if (!can_mmap_file(host_file))
164164
return -ENODEV;
165165

166166
if (WARN_ON(coda_file != vma->vm_file))

fs/ecryptfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int ecryptfs_mmap(struct file *file, struct vm_area_struct *vma)
193193
* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs
194194
* allows recursive mounting, this will need to be extended.
195195
*/
196-
if (!lower_file->f_op->mmap)
196+
if (!can_mmap_file(lower_file))
197197
return -ENODEV;
198198
return generic_file_mmap(file, vma);
199199
}

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ struct inode_operations {
22602260
} ____cacheline_aligned;
22612261

22622262
/* Did the driver provide valid mmap hook configuration? */
2263-
static inline bool file_has_valid_mmap_hooks(struct file *file)
2263+
static inline bool can_mmap_file(struct file *file)
22642264
{
22652265
bool has_mmap = file->f_op->mmap;
22662266
bool has_mmap_prepare = file->f_op->mmap_prepare;

mm/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
475475
vm_flags &= ~VM_MAYEXEC;
476476
}
477477

478-
if (!file_has_valid_mmap_hooks(file))
478+
if (!can_mmap_file(file))
479479
return -ENODEV;
480480
if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
481481
return -EINVAL;

mm/nommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ static int validate_mmap_request(struct file *file,
719719

720720
if (file) {
721721
/* files must support mmap */
722-
if (!file_has_valid_mmap_hooks(file))
722+
if (!can_mmap_file(file))
723723
return -ENODEV;
724724

725725
/* work out if what we've got could possibly be shared

tools/testing/vma/vma_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ static int compat_vma_mmap_prepare(struct file *file,
14641464
}
14651465

14661466
/* Did the driver provide valid mmap hook configuration? */
1467-
static inline bool file_has_valid_mmap_hooks(struct file *file)
1467+
static inline bool can_mmap_file(struct file *file)
14681468
{
14691469
bool has_mmap = file->f_op->mmap;
14701470
bool has_mmap_prepare = file->f_op->mmap_prepare;

0 commit comments

Comments
 (0)