Skip to content

Commit 955fbe0

Browse files
amir73iljankara
authored andcommitted
Revert "fsnotify: generate pre-content permission event on page fault"
This reverts commit 8392bc2. In the use case of buffered write whose input buffer is mmapped file on a filesystem with a pre-content mark, the prefaulting of the buffer can happen under the filesystem freeze protection (obtained in vfs_write()) which breaks assumptions of pre-content hook and introduces potential deadlock of HSM handler in userspace with filesystem freezing. Now that we have pre-content hooks at file mmap() time, disable the pre-content event hooks on page fault to avoid the potential deadlock. Reported-by: syzbot+7229071b47908b19d5b7@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-fsdevel/7ehxrhbvehlrjwvrduoxsao5k3x4aw275patsb3krkwuq573yv@o2hskrfawbnc/ Fixes: 8392bc2 ("fsnotify: generate pre-content permission event on page fault") Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Link: https://patch.msgid.link/20250312073852.2123409-5-amir73il@gmail.com
1 parent 27773ce commit 955fbe0

File tree

3 files changed

+0
-82
lines changed

3 files changed

+0
-82
lines changed

include/linux/mm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3420,7 +3420,6 @@ extern vm_fault_t filemap_fault(struct vm_fault *vmf);
34203420
extern vm_fault_t filemap_map_pages(struct vm_fault *vmf,
34213421
pgoff_t start_pgoff, pgoff_t end_pgoff);
34223422
extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf);
3423-
extern vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf);
34243423

34253424
extern unsigned long stack_guard_gap;
34263425
/* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */

mm/filemap.c

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <linux/splice.h>
4848
#include <linux/rcupdate_wait.h>
4949
#include <linux/sched/mm.h>
50-
#include <linux/fsnotify.h>
5150
#include <asm/pgalloc.h>
5251
#include <asm/tlbflush.h>
5352
#include "internal.h"
@@ -3336,48 +3335,6 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf)
33363335
return ret;
33373336
}
33383337

3339-
/**
3340-
* filemap_fsnotify_fault - maybe emit a pre-content event.
3341-
* @vmf: struct vm_fault containing details of the fault.
3342-
*
3343-
* If we have a pre-content watch on this file we will emit an event for this
3344-
* range. If we return anything the fault caller should return immediately, we
3345-
* will return VM_FAULT_RETRY if we had to emit an event, which will trigger the
3346-
* fault again and then the fault handler will run the second time through.
3347-
*
3348-
* Return: a bitwise-OR of %VM_FAULT_ codes, 0 if nothing happened.
3349-
*/
3350-
vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf)
3351-
{
3352-
struct file *fpin = NULL;
3353-
int mask = (vmf->flags & FAULT_FLAG_WRITE) ? MAY_WRITE : MAY_ACCESS;
3354-
loff_t pos = vmf->pgoff >> PAGE_SHIFT;
3355-
size_t count = PAGE_SIZE;
3356-
int err;
3357-
3358-
/*
3359-
* We already did this and now we're retrying with everything locked,
3360-
* don't emit the event and continue.
3361-
*/
3362-
if (vmf->flags & FAULT_FLAG_TRIED)
3363-
return 0;
3364-
3365-
/* No watches, we're done. */
3366-
if (likely(!FMODE_FSNOTIFY_HSM(vmf->vma->vm_file->f_mode)))
3367-
return 0;
3368-
3369-
fpin = maybe_unlock_mmap_for_io(vmf, fpin);
3370-
if (!fpin)
3371-
return VM_FAULT_SIGBUS;
3372-
3373-
err = fsnotify_file_area_perm(fpin, mask, &pos, count);
3374-
fput(fpin);
3375-
if (err)
3376-
return VM_FAULT_SIGBUS;
3377-
return VM_FAULT_RETRY;
3378-
}
3379-
EXPORT_SYMBOL_GPL(filemap_fsnotify_fault);
3380-
33813338
/**
33823339
* filemap_fault - read in file data for page fault handling
33833340
* @vmf: struct vm_fault containing details of the fault
@@ -3481,37 +3438,6 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
34813438
* or because readahead was otherwise unable to retrieve it.
34823439
*/
34833440
if (unlikely(!folio_test_uptodate(folio))) {
3484-
/*
3485-
* If this is a precontent file we have can now emit an event to
3486-
* try and populate the folio.
3487-
*/
3488-
if (!(vmf->flags & FAULT_FLAG_TRIED) &&
3489-
unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) {
3490-
loff_t pos = folio_pos(folio);
3491-
size_t count = folio_size(folio);
3492-
3493-
/* We're NOWAIT, we have to retry. */
3494-
if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) {
3495-
folio_unlock(folio);
3496-
goto out_retry;
3497-
}
3498-
3499-
if (mapping_locked)
3500-
filemap_invalidate_unlock_shared(mapping);
3501-
mapping_locked = false;
3502-
3503-
folio_unlock(folio);
3504-
fpin = maybe_unlock_mmap_for_io(vmf, fpin);
3505-
if (!fpin)
3506-
goto out_retry;
3507-
3508-
error = fsnotify_file_area_perm(fpin, MAY_ACCESS, &pos,
3509-
count);
3510-
if (error)
3511-
ret = VM_FAULT_SIGBUS;
3512-
goto out_retry;
3513-
}
3514-
35153441
/*
35163442
* If the invalidate lock is not held, the folio was in cache
35173443
* and uptodate and now it is not. Strange but possible since we

mm/nommu.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,13 +1613,6 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
16131613
}
16141614
EXPORT_SYMBOL(remap_vmalloc_range);
16151615

1616-
vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf)
1617-
{
1618-
BUG();
1619-
return 0;
1620-
}
1621-
EXPORT_SYMBOL_GPL(filemap_fsnotify_fault);
1622-
16231616
vm_fault_t filemap_fault(struct vm_fault *vmf)
16241617
{
16251618
BUG();

0 commit comments

Comments
 (0)