Commit b7d43693 authored by Zhihao Cheng's avatar Zhihao Cheng Committed by Zhihao Cheng
Browse files

mm: page_cache_ra_order: Restore 'PF_MEMALLOC_NOFS' flag in 'fallback' branch

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAWTIW


CVE: NA

--------------------------------

When an ext4 image is mounted with '-obuffered_iomap', the readahead and
defragmentation on the same file may let readahead process miss restoring
'PF_MEMALLOC_NOFS' flag, which could fail subsequent memory allocations
in the same process. Specifically:
 ioctl(fd, EXT4_IOC_MOVE_EXT)   read(fd)
		    page_cache_ra_order
	             nofs = memalloc_nofs_save()
		     // set 'PF_MEMALLOC_NOFS' for current
ext4_move_extents
 ext4_disable_buffered_iomap_aops
  mapping_clear_large_folios
                     if (unlikely(!mapping_large_folio_support(mapping)))
		      goto fallback // Forget clearing 'PF_MEMALLOC_NOFS'

Fix it by adding 'memalloc_nofs_restore' in 'fallback' branch.

Fixes: 1325aef8 ("mm: use memalloc_nofs_save() in page_cache_ra_order()")
Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
parent b5213571
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -523,6 +523,7 @@ void page_cache_ra_order(struct readahead_control *ractl,

	if (unlikely(!mapping_large_folio_support(mapping))) {
		filemap_invalidate_unlock_shared(mapping);
		memalloc_nofs_restore(nofs);
		goto fallback;
	}