Skip to content

Commit

Permalink
Merge branch 'akpm' (patches from Andrew)
Browse files Browse the repository at this point in the history
Merge misc fixes from Andrew Morton:
 "12 patches.

  Subsystems affected by this patch series: MAINTAINERS, mailmap, memfd,
  and mm (hugetlb, kasan, hugetlbfs, pagemap, selftests, memcg, and
  slab)"

* emailed patches from Andrew Morton <[email protected]>:
  selftests/memfd: clean up mapping in mfd_fail_write
  mailmap: update Roman Gushchin's email
  MAINTAINERS, SLAB: add Roman as reviewer, git tree
  MAINTAINERS: add Shakeel as a memcg co-maintainer
  MAINTAINERS: remove Vladimir from memcg maintainers
  MAINTAINERS: add Roman as a memcg co-maintainer
  selftest/vm: fix map_fixed_noreplace test failure
  mm: fix use-after-free bug when mm->mmap is reused after being freed
  hugetlbfs: fix a truncation issue in hugepages parameter
  kasan: test: prevent cache merging in kmem_cache_double_destroy
  mm/hugetlb: fix kernel crash with hugetlb mremap
  MAINTAINERS: add sysctl-next git tree
  • Loading branch information
torvalds committed Feb 26, 2022
2 parents 2c8c230 + fda153c commit 086ee11
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ Rémi Denis-Courmont <[email protected]>
Ricardo Ribalda <[email protected]> <[email protected]>
Ricardo Ribalda <[email protected]> Ricardo Ribalda Delgado <[email protected]>
Ricardo Ribalda <[email protected]> <[email protected]>
Roman Gushchin <[email protected]> <[email protected]>
Roman Gushchin <[email protected]> <[email protected]>
Roman Gushchin <[email protected]> <[email protected]>
Ross Zwisler <[email protected]> <[email protected]>
Rudolf Marek <[email protected]>
Rui Saraiva <[email protected]>
Expand Down
6 changes: 5 additions & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -4913,7 +4913,8 @@ F: kernel/cgroup/cpuset.c
CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)
M: Johannes Weiner <[email protected]>
M: Michal Hocko <[email protected]>
M: Vladimir Davydov <[email protected]>
M: Roman Gushchin <[email protected]>
M: Shakeel Butt <[email protected]>
L: [email protected]
L: [email protected]
S: Maintained
Expand Down Expand Up @@ -15567,6 +15568,7 @@ M: Iurii Zaikin <[email protected]>
L: [email protected]
L: [email protected]
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git sysctl-next
F: fs/proc/proc_sysctl.c
F: include/linux/sysctl.h
F: kernel/sysctl-test.c
Expand Down Expand Up @@ -17760,8 +17762,10 @@ M: David Rientjes <[email protected]>
M: Joonsoo Kim <[email protected]>
M: Andrew Morton <[email protected]>
M: Vlastimil Babka <[email protected]>
R: Roman Gushchin <[email protected]>
L: [email protected]
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git
F: include/linux/sl?b*.h
F: mm/sl?b*

Expand Down
5 changes: 4 additions & 1 deletion lib/test_kasan.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,14 @@ static void kmem_cache_invalid_free(struct kunit *test)
kmem_cache_destroy(cache);
}

static void empty_cache_ctor(void *object) { }

static void kmem_cache_double_destroy(struct kunit *test)
{
struct kmem_cache *cache;

cache = kmem_cache_create("test_cache", 200, 0, 0, NULL);
/* Provide a constructor to prevent cache merging. */
cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
kmem_cache_destroy(cache);
KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));
Expand Down
11 changes: 5 additions & 6 deletions mm/hugetlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4159,10 +4159,10 @@ static int __init hugepages_setup(char *s)
pr_warn("HugeTLB: architecture can't support node specific alloc, ignoring!\n");
return 0;
}
if (tmp >= nr_online_nodes)
goto invalid;
node = tmp;
p += count + 1;
if (node < 0 || node >= nr_online_nodes)
goto invalid;
/* Parse hugepages */
if (sscanf(p, "%lu%n", &tmp, &count) != 1)
goto invalid;
Expand Down Expand Up @@ -4851,14 +4851,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
}

static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
unsigned long new_addr, pte_t *src_pte)
unsigned long new_addr, pte_t *src_pte, pte_t *dst_pte)
{
struct hstate *h = hstate_vma(vma);
struct mm_struct *mm = vma->vm_mm;
pte_t *dst_pte, pte;
spinlock_t *src_ptl, *dst_ptl;
pte_t pte;

dst_pte = huge_pte_offset(mm, new_addr, huge_page_size(h));
dst_ptl = huge_pte_lock(h, mm, dst_pte);
src_ptl = huge_pte_lockptr(h, mm, src_pte);

Expand Down Expand Up @@ -4917,7 +4916,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,
if (!dst_pte)
break;

move_huge_pte(vma, old_addr, new_addr, src_pte);
move_huge_pte(vma, old_addr, new_addr, src_pte, dst_pte);
}
flush_tlb_range(vma, old_end - len, old_end);
mmu_notifier_invalidate_range_end(&range);
Expand Down
1 change: 1 addition & 0 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,7 @@ void exit_mmap(struct mm_struct *mm)
vma = remove_vma(vma);
cond_resched();
}
mm->mmap = NULL;
mmap_write_unlock(mm);
vm_unacct_memory(nr_accounted);
}
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/memfd/memfd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ static void mfd_fail_write(int fd)
printf("mmap()+mprotect() didn't fail as expected\n");
abort();
}
munmap(p, mfd_def_size);
}

/* verify PUNCH_HOLE fails */
Expand Down
49 changes: 37 additions & 12 deletions tools/testing/selftests/vm/map_fixed_noreplace.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#define MAP_FIXED_NOREPLACE 0x100000
#endif

#define BASE_ADDRESS (256ul * 1024 * 1024)


static void dump_maps(void)
{
char cmd[32];
Expand All @@ -28,18 +25,46 @@ static void dump_maps(void)
system(cmd);
}

static unsigned long find_base_addr(unsigned long size)
{
void *addr;
unsigned long flags;

flags = MAP_PRIVATE | MAP_ANONYMOUS;
addr = mmap(NULL, size, PROT_NONE, flags, -1, 0);
if (addr == MAP_FAILED) {
printf("Error: couldn't map the space we need for the test\n");
return 0;
}

if (munmap(addr, size) != 0) {
printf("Error: couldn't map the space we need for the test\n");
return 0;
}
return (unsigned long)addr;
}

int main(void)
{
unsigned long base_addr;
unsigned long flags, addr, size, page_size;
char *p;

page_size = sysconf(_SC_PAGE_SIZE);

//let's find a base addr that is free before we start the tests
size = 5 * page_size;
base_addr = find_base_addr(size);
if (!base_addr) {
printf("Error: couldn't map the space we need for the test\n");
return 1;
}

flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE;

// Check we can map all the areas we need below
errno = 0;
addr = BASE_ADDRESS;
addr = base_addr;
size = 5 * page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);

Expand All @@ -60,7 +85,7 @@ int main(void)
printf("unmap() successful\n");

errno = 0;
addr = BASE_ADDRESS + page_size;
addr = base_addr + page_size;
size = 3 * page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
Expand All @@ -80,7 +105,7 @@ int main(void)
* +4 | free | new
*/
errno = 0;
addr = BASE_ADDRESS;
addr = base_addr;
size = 5 * page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
Expand All @@ -101,7 +126,7 @@ int main(void)
* +4 | free |
*/
errno = 0;
addr = BASE_ADDRESS + (2 * page_size);
addr = base_addr + (2 * page_size);
size = page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
Expand All @@ -121,7 +146,7 @@ int main(void)
* +4 | free | new
*/
errno = 0;
addr = BASE_ADDRESS + (3 * page_size);
addr = base_addr + (3 * page_size);
size = 2 * page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
Expand All @@ -141,7 +166,7 @@ int main(void)
* +4 | free |
*/
errno = 0;
addr = BASE_ADDRESS;
addr = base_addr;
size = 2 * page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
Expand All @@ -161,7 +186,7 @@ int main(void)
* +4 | free |
*/
errno = 0;
addr = BASE_ADDRESS;
addr = base_addr;
size = page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
Expand All @@ -181,7 +206,7 @@ int main(void)
* +4 | free | new
*/
errno = 0;
addr = BASE_ADDRESS + (4 * page_size);
addr = base_addr + (4 * page_size);
size = page_size;
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
Expand All @@ -192,7 +217,7 @@ int main(void)
return 1;
}

addr = BASE_ADDRESS;
addr = base_addr;
size = 5 * page_size;
if (munmap((void *)addr, size) != 0) {
dump_maps();
Expand Down

0 comments on commit 086ee11

Please sign in to comment.