Skip to content

Commit 2d28e01

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc fixes from Andrew Morton: "2 fixes" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: hugetlbfs: fix races and page leaks during migration kasan: turn off asan-stack for clang-8 and earlier
2 parents 6357c81 + cb6acd0 commit 2d28e01

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

fs/hugetlbfs/inode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,18 @@ static int hugetlbfs_migrate_page(struct address_space *mapping,
859859
rc = migrate_huge_page_move_mapping(mapping, newpage, page);
860860
if (rc != MIGRATEPAGE_SUCCESS)
861861
return rc;
862+
863+
/*
864+
* page_private is subpool pointer in hugetlb pages. Transfer to
865+
* new page. PagePrivate is not associated with page_private for
866+
* hugetlb pages and can not be set here as only page_huge_active
867+
* pages can be migrated.
868+
*/
869+
if (page_private(page)) {
870+
set_page_private(newpage, page_private(page));
871+
set_page_private(page, 0);
872+
}
873+
862874
if (mode != MIGRATE_SYNC_NO_COPY)
863875
migrate_page_copy(newpage, page);
864876
else

lib/Kconfig.kasan

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,28 @@ config KASAN_INLINE
113113

114114
endchoice
115115

116+
config KASAN_STACK_ENABLE
117+
bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST
118+
default !(CLANG_VERSION < 90000)
119+
depends on KASAN
120+
help
121+
The LLVM stack address sanitizer has a know problem that
122+
causes excessive stack usage in a lot of functions, see
123+
https://bugs.llvm.org/show_bug.cgi?id=38809
124+
Disabling asan-stack makes it safe to run kernels build
125+
with clang-8 with KASAN enabled, though it loses some of
126+
the functionality.
127+
This feature is always disabled when compile-testing with clang-8
128+
or earlier to avoid cluttering the output in stack overflow
129+
warnings, but clang-8 users can still enable it for builds without
130+
CONFIG_COMPILE_TEST. On gcc and later clang versions it is
131+
assumed to always be safe to use and enabled by default.
132+
133+
config KASAN_STACK
134+
int
135+
default 1 if KASAN_STACK_ENABLE || CC_IS_GCC
136+
default 0
137+
116138
config KASAN_S390_4_LEVEL_PAGING
117139
bool "KASan: use 4-level paging"
118140
depends on KASAN && S390

mm/hugetlb.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,7 +3624,6 @@ static vm_fault_t hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
36243624
copy_user_huge_page(new_page, old_page, address, vma,
36253625
pages_per_huge_page(h));
36263626
__SetPageUptodate(new_page);
3627-
set_page_huge_active(new_page);
36283627

36293628
mmu_notifier_range_init(&range, mm, haddr, haddr + huge_page_size(h));
36303629
mmu_notifier_invalidate_range_start(&range);
@@ -3645,6 +3644,7 @@ static vm_fault_t hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
36453644
make_huge_pte(vma, new_page, 1));
36463645
page_remove_rmap(old_page, true);
36473646
hugepage_add_new_anon_rmap(new_page, vma, haddr);
3647+
set_page_huge_active(new_page);
36483648
/* Make the old page be freed below */
36493649
new_page = old_page;
36503650
}
@@ -3729,6 +3729,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
37293729
pte_t new_pte;
37303730
spinlock_t *ptl;
37313731
unsigned long haddr = address & huge_page_mask(h);
3732+
bool new_page = false;
37323733

37333734
/*
37343735
* Currently, we are forced to kill the process in the event the
@@ -3790,7 +3791,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
37903791
}
37913792
clear_huge_page(page, address, pages_per_huge_page(h));
37923793
__SetPageUptodate(page);
3793-
set_page_huge_active(page);
3794+
new_page = true;
37943795

37953796
if (vma->vm_flags & VM_MAYSHARE) {
37963797
int err = huge_add_to_page_cache(page, mapping, idx);
@@ -3861,6 +3862,15 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm,
38613862
}
38623863

38633864
spin_unlock(ptl);
3865+
3866+
/*
3867+
* Only make newly allocated pages active. Existing pages found
3868+
* in the pagecache could be !page_huge_active() if they have been
3869+
* isolated for migration.
3870+
*/
3871+
if (new_page)
3872+
set_page_huge_active(page);
3873+
38643874
unlock_page(page);
38653875
out:
38663876
return ret;
@@ -4095,7 +4105,6 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
40954105
* the set_pte_at() write.
40964106
*/
40974107
__SetPageUptodate(page);
4098-
set_page_huge_active(page);
40994108

41004109
mapping = dst_vma->vm_file->f_mapping;
41014110
idx = vma_hugecache_offset(h, dst_vma, dst_addr);
@@ -4163,6 +4172,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
41634172
update_mmu_cache(dst_vma, dst_addr, dst_pte);
41644173

41654174
spin_unlock(ptl);
4175+
set_page_huge_active(page);
41664176
if (vm_shared)
41674177
unlock_page(page);
41684178
ret = 0;

mm/migrate.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,16 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
13151315
lock_page(hpage);
13161316
}
13171317

1318+
/*
1319+
* Check for pages which are in the process of being freed. Without
1320+
* page_mapping() set, hugetlbfs specific move page routine will not
1321+
* be called and we could leak usage counts for subpools.
1322+
*/
1323+
if (page_private(hpage) && !page_mapping(hpage)) {
1324+
rc = -EBUSY;
1325+
goto out_unlock;
1326+
}
1327+
13181328
if (PageAnon(hpage))
13191329
anon_vma = page_get_anon_vma(hpage);
13201330

@@ -1345,6 +1355,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
13451355
put_new_page = NULL;
13461356
}
13471357

1358+
out_unlock:
13481359
unlock_page(hpage);
13491360
out:
13501361
if (rc != -EAGAIN)

scripts/Makefile.kasan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ else
2626
CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
2727
$(call cc-param,asan-globals=1) \
2828
$(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
29-
$(call cc-param,asan-stack=1) \
29+
$(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \
3030
$(call cc-param,asan-use-after-scope=1) \
3131
$(call cc-param,asan-instrument-allocas=1)
3232
endif

0 commit comments

Comments
 (0)