Commit a31200eb authored by David Hildenbrand's avatar David Hildenbrand Committed by Kefeng Wang
Browse files

uprobes: use pagesize-aligned virtual address when replacing pages

mainline inclusion
from mainline-v6.8-rc3
commit 4dca82d14174fe53f656a6bc32398db1bdd8f481
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I98AW9
CVE: NA

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

uprobes passes an unaligned page mapping address to
folio_add_new_anon_rmap(), which ends up triggering a VM_BUG_ON() we
recently extended in commit 372cbd4d5a066 ("mm: non-pmd-mappable, large
folios for folio_add_new_anon_rmap()").

Arguably, this is uprobes code doing something wrong; however, for the
time being it would have likely worked in rmap code because
__folio_set_anon() would set folio->index to the same value.

Looking at __replace_page(), we'd also pass slightly wrong values to
mmu_notifier_range_init(), page_vma_mapped_walk(), flush_cache_page(),
ptep_clear_flush() and set_pte_at_notify().  I suspect most of them are
fine, but let's just mark the introducing commit as the one needed fixing.
I don't think CC stable is warranted.

We'll add more sanity checks in rmap code separately, to make sure that we
always get properly aligned addresses.

Link: https://lkml.kernel.org/r/20240115100731.91007-1-david@redhat.com


Fixes: c517ee74 ("uprobes: __replace_page() should not use page_address_in_vma()")
Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Reported-by: default avatarJiri Olsa <jolsa@kernel.org>
Closes: https://lkml.kernel.org/r/ZaMR2EWN-HvlCfUl@krava


Tested-by: default avatarJiri Olsa <jolsa@kernel.org>
Reviewed-by: default avatarRyan Roberts <ryan.roberts@arm.com>
Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 4dca82d14174fe53f656a6bc32398db1bdd8f481)
Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
parent 15f5b002
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -539,7 +539,7 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
		}
	}

	ret = __replace_page(vma, vaddr, old_page, new_page);
	ret = __replace_page(vma, vaddr & PAGE_MASK, old_page, new_page);
	if (new_page)
		put_page(new_page);
put_old: