Re: [PATCH] powerpc/ptdump: Fix generic ptdump for 64-bit
On Tue, 31 Aug 2021 23:51:51 +1000, Michael Ellerman wrote: > Since the conversion to generic ptdump we see crashes on 64-bit: > > BUG: Unable to handle kernel data access on read at 0xc0eeff7f > Faulting instruction address: 0xc045e5fc > Oops: Kernel access of bad area, sig: 11 [#1] > ... > NIP __walk_page_range+0x2bc/0xce0 > LR __walk_page_range+0x240/0xce0 > Call Trace: > __walk_page_range+0x240/0xce0 (unreliable) > walk_page_range_novma+0x74/0xb0 > ptdump_walk_pgd+0x98/0x170 > ptdump_check_wx+0x88/0xd0 > mark_rodata_ro+0x48/0x80 > kernel_init+0x74/0x1a0 > ret_from_kernel_thread+0x5c/0x64 > > [...] Applied to powerpc/next. [1/1] powerpc/ptdump: Fix generic ptdump for 64-bit https://git.kernel.org/powerpc/c/b14b8b1ed0e15b8f43fba9c25654278a31ee3c2f cheers
Re: [PATCH] powerpc/ptdump: Fix generic ptdump for 64-bit
On Tue, Aug 31, 2021 at 11:51:51PM +1000, Michael Ellerman wrote: > Since the conversion to generic ptdump we see crashes on 64-bit: > > BUG: Unable to handle kernel data access on read at 0xc0eeff7f > Faulting instruction address: 0xc045e5fc > Oops: Kernel access of bad area, sig: 11 [#1] > ... > NIP __walk_page_range+0x2bc/0xce0 > LR __walk_page_range+0x240/0xce0 > Call Trace: > __walk_page_range+0x240/0xce0 (unreliable) > walk_page_range_novma+0x74/0xb0 > ptdump_walk_pgd+0x98/0x170 > ptdump_check_wx+0x88/0xd0 > mark_rodata_ro+0x48/0x80 > kernel_init+0x74/0x1a0 > ret_from_kernel_thread+0x5c/0x64 > > What's happening is that have walked off the end of the kernel page > tables, and started dereferencing junk values. > > That happens because we initialised the ptdump_range to span all the way > up to 0x: > > static struct ptdump_range ptdump_range[] __ro_after_init = { > {TASK_SIZE_MAX, ~0UL}, > > But the kernel page tables don't span that far. So on 64-bit set the end > of the range to be the address immediately past the end of the kernel > page tables, to limit the page table walk to valid addresses. > > Fixes: e084728393a5 ("powerpc/ptdump: Convert powerpc to GENERIC_PTDUMP") > Reported-by: Nathan Chancellor > Signed-off-by: Michael Ellerman Tested-by: Nathan Chancellor > --- > arch/powerpc/mm/ptdump/ptdump.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c > index 2d80d775d15e..bf251191e78d 100644 > --- a/arch/powerpc/mm/ptdump/ptdump.c > +++ b/arch/powerpc/mm/ptdump/ptdump.c > @@ -359,6 +359,8 @@ static int __init ptdump_init(void) > ptdump_range[0].start = KERN_VIRT_START; > else > ptdump_range[0].start = PAGE_OFFSET; > + > + ptdump_range[0].end = PAGE_OFFSET + (PGDIR_SIZE * PTRS_PER_PGD); > #endif > > populate_markers(); > > base-commit: e1ab9a730b426fadc018f91b7c98412473e542fb > prerequisite-patch-id: 942553bda7d83bbae8bf6b2b718033d488ee2410 > prerequisite-patch-id: a14c44e671eba8648c4fe385a2552fd57875ec8a > prerequisite-patch-id: 94f5c890f54da2b46f06c60562e879171fab2be3 > prerequisite-patch-id: 330af32f2aa34a432d450acc9f6e9fd1cec96417 > prerequisite-patch-id: b46c65afa63944f3fb02f4b9bdf940507bb25de6 > prerequisite-patch-id: c4ba00ee949f70d7745f75bad11bbb2416f329f1 > prerequisite-patch-id: f479601944d0aa615716d5349d93bd6e3d5619c1 > prerequisite-patch-id: 9523cde933393b2d68648cecb740efdba9dd8601 > prerequisite-patch-id: 034afc97c841a6dcd2b9932406f391d65d18bf87 > prerequisite-patch-id: effd7ac8a7db6b59a2677c9c3a7ef8b3ef8bdaf8 > prerequisite-patch-id: 23883cf116ee69b452db3c6e10dd49e756e7b5d5 > prerequisite-patch-id: 37b6695321c96db466b0faba9308bacfb79c7ced > prerequisite-patch-id: 83420e68ca4476c9ba5a67aa19e1fdc0b6d656a4 > prerequisite-patch-id: 362219acf820b78b83c6c09071a636b28976a1ce > prerequisite-patch-id: 857513c5f431887d16a59d193834dcec636c73dc > prerequisite-patch-id: 49f6879a819e205b5361280ab923664fcd29daaf > prerequisite-patch-id: 5a37bcf70c5cb44d78de63a64e5ce920a0a7e419 > prerequisite-patch-id: 2c06dd3833117b0498baa198694f6c7e84975840 > prerequisite-patch-id: 5794a211ebbf7f0d416ae882443201621c00f615 > prerequisite-patch-id: 19ed5ae34e233079c7f66376b8d309cac2b57dbc > prerequisite-patch-id: 1d4c82277473e8dbecf83faf6c4a6788538b064d > prerequisite-patch-id: 8cb5ecc4fe23dafb4a43192f93b669c80a548985 > prerequisite-patch-id: 763b8d98c3aefd120862154b94814e3ef3578b5c > prerequisite-patch-id: f45e04e6d030eb157be550976b07dc891fa0836d > prerequisite-patch-id: 07b6fb682675845aca694deff1847bc7a40e1fec > prerequisite-patch-id: 7f1082effa12b1eba445cef90e4749155662888c > prerequisite-patch-id: 76743814dd8e6151c27676ae2e318579d658bf8b > prerequisite-patch-id: 8a6b12c11dbbcd5dda0ccc9877dee1be785e0173 > prerequisite-patch-id: e98f013ce41c27d16f75ac3eb1c7eec4235cca0a > prerequisite-patch-id: 285e11f96169ec82702a69b2fca5318c0e307508 > prerequisite-patch-id: 9fa89fb9f4ac839177307891bb240009f1d55e88 > prerequisite-patch-id: feebaed3f6e0c15e8fa468d64129fe9aa4411d57 > prerequisite-patch-id: 8f1093cf40180a623439d82e563e1dd18194cc19 > prerequisite-patch-id: d042674595d0678e71e5258d55b93d54b5c4 > prerequisite-patch-id: 286812aaed6630139583fd21d388137b8d5a6931 > prerequisite-patch-id: 54af8aa735a12282bb40a0ed87455e268ae356d9 > prerequisite-patch-id: cc5ee85759d99a6ebf18e39634dde65f15476f84 > prerequisite-patch-id: 3f8437c8bfda23c45839596ec432d81a95505061 > prerequisite-patch-id: f30d6fa2c7c7c417ee4bee0827c0ce587570db34 > prerequisite-patch-id: fa402f5deaa301587ced629dfa523728aece4705 > prerequisite-patch-id: 51f326f5de947cea58003cc8b988b54436689d1b > prerequisite-patch-id: 4003c9a6b2792e797c333875e63a184df8fcc7e7 > prerequisite-patch-id: f73fd878eb9b65ecbed3c3ee8ca6725f7e55d5d2 > prerequisite-patch-id: 5e55b3e9b3809da22b8742f0ed356df6d6fdd301 > prerequisite-patch-id:
[PATCH] powerpc/ptdump: Fix generic ptdump for 64-bit
Since the conversion to generic ptdump we see crashes on 64-bit: BUG: Unable to handle kernel data access on read at 0xc0eeff7f Faulting instruction address: 0xc045e5fc Oops: Kernel access of bad area, sig: 11 [#1] ... NIP __walk_page_range+0x2bc/0xce0 LR __walk_page_range+0x240/0xce0 Call Trace: __walk_page_range+0x240/0xce0 (unreliable) walk_page_range_novma+0x74/0xb0 ptdump_walk_pgd+0x98/0x170 ptdump_check_wx+0x88/0xd0 mark_rodata_ro+0x48/0x80 kernel_init+0x74/0x1a0 ret_from_kernel_thread+0x5c/0x64 What's happening is that have walked off the end of the kernel page tables, and started dereferencing junk values. That happens because we initialised the ptdump_range to span all the way up to 0x: static struct ptdump_range ptdump_range[] __ro_after_init = { {TASK_SIZE_MAX, ~0UL}, But the kernel page tables don't span that far. So on 64-bit set the end of the range to be the address immediately past the end of the kernel page tables, to limit the page table walk to valid addresses. Fixes: e084728393a5 ("powerpc/ptdump: Convert powerpc to GENERIC_PTDUMP") Reported-by: Nathan Chancellor Signed-off-by: Michael Ellerman --- arch/powerpc/mm/ptdump/ptdump.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c index 2d80d775d15e..bf251191e78d 100644 --- a/arch/powerpc/mm/ptdump/ptdump.c +++ b/arch/powerpc/mm/ptdump/ptdump.c @@ -359,6 +359,8 @@ static int __init ptdump_init(void) ptdump_range[0].start = KERN_VIRT_START; else ptdump_range[0].start = PAGE_OFFSET; + + ptdump_range[0].end = PAGE_OFFSET + (PGDIR_SIZE * PTRS_PER_PGD); #endif populate_markers(); base-commit: e1ab9a730b426fadc018f91b7c98412473e542fb prerequisite-patch-id: 942553bda7d83bbae8bf6b2b718033d488ee2410 prerequisite-patch-id: a14c44e671eba8648c4fe385a2552fd57875ec8a prerequisite-patch-id: 94f5c890f54da2b46f06c60562e879171fab2be3 prerequisite-patch-id: 330af32f2aa34a432d450acc9f6e9fd1cec96417 prerequisite-patch-id: b46c65afa63944f3fb02f4b9bdf940507bb25de6 prerequisite-patch-id: c4ba00ee949f70d7745f75bad11bbb2416f329f1 prerequisite-patch-id: f479601944d0aa615716d5349d93bd6e3d5619c1 prerequisite-patch-id: 9523cde933393b2d68648cecb740efdba9dd8601 prerequisite-patch-id: 034afc97c841a6dcd2b9932406f391d65d18bf87 prerequisite-patch-id: effd7ac8a7db6b59a2677c9c3a7ef8b3ef8bdaf8 prerequisite-patch-id: 23883cf116ee69b452db3c6e10dd49e756e7b5d5 prerequisite-patch-id: 37b6695321c96db466b0faba9308bacfb79c7ced prerequisite-patch-id: 83420e68ca4476c9ba5a67aa19e1fdc0b6d656a4 prerequisite-patch-id: 362219acf820b78b83c6c09071a636b28976a1ce prerequisite-patch-id: 857513c5f431887d16a59d193834dcec636c73dc prerequisite-patch-id: 49f6879a819e205b5361280ab923664fcd29daaf prerequisite-patch-id: 5a37bcf70c5cb44d78de63a64e5ce920a0a7e419 prerequisite-patch-id: 2c06dd3833117b0498baa198694f6c7e84975840 prerequisite-patch-id: 5794a211ebbf7f0d416ae882443201621c00f615 prerequisite-patch-id: 19ed5ae34e233079c7f66376b8d309cac2b57dbc prerequisite-patch-id: 1d4c82277473e8dbecf83faf6c4a6788538b064d prerequisite-patch-id: 8cb5ecc4fe23dafb4a43192f93b669c80a548985 prerequisite-patch-id: 763b8d98c3aefd120862154b94814e3ef3578b5c prerequisite-patch-id: f45e04e6d030eb157be550976b07dc891fa0836d prerequisite-patch-id: 07b6fb682675845aca694deff1847bc7a40e1fec prerequisite-patch-id: 7f1082effa12b1eba445cef90e4749155662888c prerequisite-patch-id: 76743814dd8e6151c27676ae2e318579d658bf8b prerequisite-patch-id: 8a6b12c11dbbcd5dda0ccc9877dee1be785e0173 prerequisite-patch-id: e98f013ce41c27d16f75ac3eb1c7eec4235cca0a prerequisite-patch-id: 285e11f96169ec82702a69b2fca5318c0e307508 prerequisite-patch-id: 9fa89fb9f4ac839177307891bb240009f1d55e88 prerequisite-patch-id: feebaed3f6e0c15e8fa468d64129fe9aa4411d57 prerequisite-patch-id: 8f1093cf40180a623439d82e563e1dd18194cc19 prerequisite-patch-id: d042674595d0678e71e5258d55b93d54b5c4 prerequisite-patch-id: 286812aaed6630139583fd21d388137b8d5a6931 prerequisite-patch-id: 54af8aa735a12282bb40a0ed87455e268ae356d9 prerequisite-patch-id: cc5ee85759d99a6ebf18e39634dde65f15476f84 prerequisite-patch-id: 3f8437c8bfda23c45839596ec432d81a95505061 prerequisite-patch-id: f30d6fa2c7c7c417ee4bee0827c0ce587570db34 prerequisite-patch-id: fa402f5deaa301587ced629dfa523728aece4705 prerequisite-patch-id: 51f326f5de947cea58003cc8b988b54436689d1b prerequisite-patch-id: 4003c9a6b2792e797c333875e63a184df8fcc7e7 prerequisite-patch-id: f73fd878eb9b65ecbed3c3ee8ca6725f7e55d5d2 prerequisite-patch-id: 5e55b3e9b3809da22b8742f0ed356df6d6fdd301 prerequisite-patch-id: 1fde98fffabd6313d1921d8b2f28691e9a191b1d prerequisite-patch-id: 51c0595fe54ad077c736b7a4351c2f2700ab66d7 prerequisite-patch-id: e490360db8c2dc7cbf693258ca93e4597f165c6f prerequisite-patch-id: c4354b3226d31d8ddb6992956cf0ed12ea97cb8e prerequisite-patch-id: c67a26ed658da4b11a3319e0e99c4a84afb68d80