From: Nam Cao <namcao@linutronix.de>
To: Joel Granados <j.granados@samsung.com>
Cc: "Mike Rapoport" <rppt@kernel.org>,
"Andreas Dilger" <adilger@dilger.ca>,
"Björn Töpel" <bjorn@kernel.org>,
linux-riscv@lists.infradead.org,
"Thomas Gleixner" <tglx@linutronix.de>,
"Andrew Morton" <akpm@linux-foundation.org>,
"ndesaulniers @ google . com" <ndesaulniers@google.com>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Ingo Molnar" <mingo@kernel.org>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Tejun Heo" <tj@kernel.org>,
"Krister Johansen" <kjlx@templeofstupid.com>,
"Changbin Du" <changbin.du@huawei.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] init: fix allocated page overlapping with PTR_ERR
Date: Tue, 30 Apr 2024 09:31:07 +0200 [thread overview]
Message-ID: <20240430073056.bEG4-yk8@linutronix.de> (raw)
In-Reply-To: <20240429125230.s5pbeye24iw5aurz@joelS2.panther.com>
On Mon, Apr 29, 2024 at 02:52:30PM +0200, Joel Granados wrote:
> On Thu, Apr 18, 2024 at 12:29:43PM +0200, Nam Cao wrote:
> > There is nothing preventing kernel memory allocators from allocating a
> > page that overlaps with PTR_ERR(), except for architecture-specific
> > code that setup memblock.
> >
> > It was discovered that RISCV architecture doesn't setup memblock
> > corectly, leading to a page overlapping with PTR_ERR() being allocated,
> > and subsequently crashing the kernel (link in Close: )
> >
> > The reported crash has nothing to do with PTR_ERR(): the last page
> > (at address 0xfffff000) being allocated leads to an unexpected
> > arithmetic overflow in ext4; but still, this page shouldn't be
> > allocated in the first place.
> >
> > Because PTR_ERR() is an architecture-independent thing, we shouldn't
> > ask every single architecture to set this up. There may be other
> > architectures beside RISCV that have the same problem.
> >
> > Fix this one and for all by reserving the physical memory page that
> > may be mapped to the last virtual memory page as part of low memory.
> >
> > Unfortunately, this means if there is actual memory at this reserved
> > location, that memory will become inaccessible. However, if this page
> > is not reserved, it can only be accessed as high memory, so this
> > doesn't matter if high memory is not supported. Even if high memory is
> > supported, it is still only one page.
> >
> > Closes: https://lore.kernel.org/linux-riscv/878r1ibpdn.fsf@all.your.base.are.belong.to.us
> > Signed-off-by: Nam Cao <namcao@linutronix.de>
> > Cc: <stable@vger.kernel.org> # all versions
> > ---
> > init/main.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/init/main.c b/init/main.c
> > index 881f6230ee59..f8d2793c4641 100644
> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -900,6 +900,7 @@ void start_kernel(void)
> > page_address_init();
> > pr_notice("%s", linux_banner);
> > early_security_init();
> > + memblock_reserve(__pa(-PAGE_SIZE), PAGE_SIZE); /* reserve last page for ERR_PTR */
> > setup_arch(&command_line);
> > setup_boot_config();
> > setup_command_line(command_line);
> > --
> > 2.39.2
> >
>
> I received a similar(ish) report recently
> https://lore.kernel.org/oe-kbuild-all/202404211031.J6l2AfJk-lkp@intel.com/
> regarding RISC-V in init/mail.c. Here is the meat of the report in case
> you want to avoid going to the actual link:
This issue doesn't look like it has anything to do with this patch: this
patch is about overlapping of dynamically allocated memory, while I think
the issue is about overlapping sections during linking (maybe something
wrong with riscv linker script?)
Also, FWIW, this patch is not going to be in mainline because of a
regression.
Nonetheless, I will have a look at this later.
Best regards,
Nam
> "
> ...
> riscv64-linux-ld: section .data LMA [000000000099b000,0000000001424de7] overlaps section .text LMA [0000000000104040,000000000213c543]
> riscv64-linux-ld: section .data..percpu LMA [00000000024e2000,00000000026b46e7] overlaps section .rodata LMA [000000000213c580,000000000292d0dd]
> riscv64-linux-ld: section .rodata VMA [ffffffff8213c580,ffffffff8292d0dd] overlaps section .data VMA [ffffffff82000000,ffffffff82a89de7]
> init/main.o: in function `rdinit_setup':
> >> init/main.c:613:(.init.text+0x358): relocation truncated to fit: R_RISCV_GPREL_I against symbol `__setup_start' defined in .init.rodata section in .tmp_vmlinux.kallsyms1
> net/ipv4/ipconfig.o: in function `ic_dhcp_init_options':
> net/ipv4/ipconfig.c:682:(.init.text+0x9b4): relocation truncated to fit: R_RISCV_GPREL_I against `ic_bootp_cookie'
> net/sunrpc/auth_gss/gss_krb5_mech.o: in function `gss_krb5_prepare_enctype_priority_list':
> >> net/sunrpc/auth_gss/gss_krb5_mech.c:213:(.text.gss_krb5_prepare_enctype_priority_list+0x9c): relocation truncated to fit: R_RISCV_GPREL_I against `gss_krb5_enctypes.0'
> lib/maple_tree.o: in function `mas_leaf_max_gap':
> >> lib/maple_tree.c:1512:(.text.mas_leaf_max_gap+0x2b8): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `ma_dead_node':
> >> lib/maple_tree.c:560:(.text.mas_data_end+0x110): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mas_extend_spanning_null':
> >> lib/maple_tree.c:3662:(.text.mas_extend_spanning_null+0x69c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mas_mab_cp':
> >> lib/maple_tree.c:1943:(.text.mas_mab_cp+0x248): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mab_mas_cp':
> >> lib/maple_tree.c:2000:(.text.mab_mas_cp+0x15c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mas_reuse_node':
> >> lib/maple_tree.c:3416:(.text.mas_reuse_node+0x17c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_slots'
> lib/maple_tree.o: in function `mt_free_walk':
> >> lib/maple_tree.c:5238:(.text.mt_free_walk+0x15c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_slots'
> lib/maple_tree.o: in function `mtree_lookup_walk':
> lib/maple_tree.c:3700:(.text.mtree_lookup_walk+0x94): additional relocation overflows omitted from the output
> ...
>
> "
>
> Could the fix that you have posted here be related to that report?
> Comments are greatly appreciated.
>
> Best
> --
>
> Joel Granados
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Nam Cao <namcao@linutronix.de>
To: Joel Granados <j.granados@samsung.com>
Cc: "Mike Rapoport" <rppt@kernel.org>,
"Andreas Dilger" <adilger@dilger.ca>,
"Björn Töpel" <bjorn@kernel.org>,
linux-riscv@lists.infradead.org,
"Thomas Gleixner" <tglx@linutronix.de>,
"Andrew Morton" <akpm@linux-foundation.org>,
"ndesaulniers @ google . com" <ndesaulniers@google.com>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Ingo Molnar" <mingo@kernel.org>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Tejun Heo" <tj@kernel.org>,
"Krister Johansen" <kjlx@templeofstupid.com>,
"Changbin Du" <changbin.du@huawei.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] init: fix allocated page overlapping with PTR_ERR
Date: Tue, 30 Apr 2024 09:31:07 +0200 [thread overview]
Message-ID: <20240430073056.bEG4-yk8@linutronix.de> (raw)
In-Reply-To: <20240429125230.s5pbeye24iw5aurz@joelS2.panther.com>
On Mon, Apr 29, 2024 at 02:52:30PM +0200, Joel Granados wrote:
> On Thu, Apr 18, 2024 at 12:29:43PM +0200, Nam Cao wrote:
> > There is nothing preventing kernel memory allocators from allocating a
> > page that overlaps with PTR_ERR(), except for architecture-specific
> > code that setup memblock.
> >
> > It was discovered that RISCV architecture doesn't setup memblock
> > corectly, leading to a page overlapping with PTR_ERR() being allocated,
> > and subsequently crashing the kernel (link in Close: )
> >
> > The reported crash has nothing to do with PTR_ERR(): the last page
> > (at address 0xfffff000) being allocated leads to an unexpected
> > arithmetic overflow in ext4; but still, this page shouldn't be
> > allocated in the first place.
> >
> > Because PTR_ERR() is an architecture-independent thing, we shouldn't
> > ask every single architecture to set this up. There may be other
> > architectures beside RISCV that have the same problem.
> >
> > Fix this one and for all by reserving the physical memory page that
> > may be mapped to the last virtual memory page as part of low memory.
> >
> > Unfortunately, this means if there is actual memory at this reserved
> > location, that memory will become inaccessible. However, if this page
> > is not reserved, it can only be accessed as high memory, so this
> > doesn't matter if high memory is not supported. Even if high memory is
> > supported, it is still only one page.
> >
> > Closes: https://lore.kernel.org/linux-riscv/878r1ibpdn.fsf@all.your.base.are.belong.to.us
> > Signed-off-by: Nam Cao <namcao@linutronix.de>
> > Cc: <stable@vger.kernel.org> # all versions
> > ---
> > init/main.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/init/main.c b/init/main.c
> > index 881f6230ee59..f8d2793c4641 100644
> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -900,6 +900,7 @@ void start_kernel(void)
> > page_address_init();
> > pr_notice("%s", linux_banner);
> > early_security_init();
> > + memblock_reserve(__pa(-PAGE_SIZE), PAGE_SIZE); /* reserve last page for ERR_PTR */
> > setup_arch(&command_line);
> > setup_boot_config();
> > setup_command_line(command_line);
> > --
> > 2.39.2
> >
>
> I received a similar(ish) report recently
> https://lore.kernel.org/oe-kbuild-all/202404211031.J6l2AfJk-lkp@intel.com/
> regarding RISC-V in init/mail.c. Here is the meat of the report in case
> you want to avoid going to the actual link:
This issue doesn't look like it has anything to do with this patch: this
patch is about overlapping of dynamically allocated memory, while I think
the issue is about overlapping sections during linking (maybe something
wrong with riscv linker script?)
Also, FWIW, this patch is not going to be in mainline because of a
regression.
Nonetheless, I will have a look at this later.
Best regards,
Nam
> "
> ...
> riscv64-linux-ld: section .data LMA [000000000099b000,0000000001424de7] overlaps section .text LMA [0000000000104040,000000000213c543]
> riscv64-linux-ld: section .data..percpu LMA [00000000024e2000,00000000026b46e7] overlaps section .rodata LMA [000000000213c580,000000000292d0dd]
> riscv64-linux-ld: section .rodata VMA [ffffffff8213c580,ffffffff8292d0dd] overlaps section .data VMA [ffffffff82000000,ffffffff82a89de7]
> init/main.o: in function `rdinit_setup':
> >> init/main.c:613:(.init.text+0x358): relocation truncated to fit: R_RISCV_GPREL_I against symbol `__setup_start' defined in .init.rodata section in .tmp_vmlinux.kallsyms1
> net/ipv4/ipconfig.o: in function `ic_dhcp_init_options':
> net/ipv4/ipconfig.c:682:(.init.text+0x9b4): relocation truncated to fit: R_RISCV_GPREL_I against `ic_bootp_cookie'
> net/sunrpc/auth_gss/gss_krb5_mech.o: in function `gss_krb5_prepare_enctype_priority_list':
> >> net/sunrpc/auth_gss/gss_krb5_mech.c:213:(.text.gss_krb5_prepare_enctype_priority_list+0x9c): relocation truncated to fit: R_RISCV_GPREL_I against `gss_krb5_enctypes.0'
> lib/maple_tree.o: in function `mas_leaf_max_gap':
> >> lib/maple_tree.c:1512:(.text.mas_leaf_max_gap+0x2b8): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `ma_dead_node':
> >> lib/maple_tree.c:560:(.text.mas_data_end+0x110): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mas_extend_spanning_null':
> >> lib/maple_tree.c:3662:(.text.mas_extend_spanning_null+0x69c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mas_mab_cp':
> >> lib/maple_tree.c:1943:(.text.mas_mab_cp+0x248): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mab_mas_cp':
> >> lib/maple_tree.c:2000:(.text.mab_mas_cp+0x15c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_pivots'
> lib/maple_tree.o: in function `mas_reuse_node':
> >> lib/maple_tree.c:3416:(.text.mas_reuse_node+0x17c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_slots'
> lib/maple_tree.o: in function `mt_free_walk':
> >> lib/maple_tree.c:5238:(.text.mt_free_walk+0x15c): relocation truncated to fit: R_RISCV_GPREL_I against `mt_slots'
> lib/maple_tree.o: in function `mtree_lookup_walk':
> lib/maple_tree.c:3700:(.text.mtree_lookup_walk+0x94): additional relocation overflows omitted from the output
> ...
>
> "
>
> Could the fix that you have posted here be related to that report?
> Comments are greatly appreciated.
>
> Best
> --
>
> Joel Granados
next prev parent reply other threads:[~2024-04-30 7:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20240429125236eucas1p24219f2d332e0267794a2f87dea9f39c4@eucas1p2.samsung.com>
2024-04-18 10:29 ` [PATCH] init: fix allocated page overlapping with PTR_ERR Nam Cao
2024-04-18 10:29 ` Nam Cao
2024-04-18 10:54 ` Mike Rapoport
2024-04-18 10:54 ` Mike Rapoport
2024-04-18 11:12 ` Nam Cao
2024-04-18 11:12 ` Nam Cao
2024-04-18 12:41 ` Björn Töpel
2024-04-18 12:41 ` Björn Töpel
2024-04-18 13:01 ` Nam Cao
2024-04-18 13:01 ` Nam Cao
2024-04-18 13:07 ` Nam Cao
2024-04-18 13:07 ` Nam Cao
2024-04-29 12:52 ` Joel Granados
2024-04-29 12:52 ` Joel Granados
2024-04-30 7:31 ` Nam Cao [this message]
2024-04-30 7:31 ` Nam Cao
2024-04-30 8:37 ` Alexandre Ghiti
2024-04-30 8:37 ` Alexandre Ghiti
2024-04-30 13:35 ` Joel Granados
2024-04-30 13:35 ` Joel Granados
2024-04-30 15:42 ` Joel Granados
2024-04-30 15:42 ` Joel Granados
2024-05-10 6:35 ` Nam Cao
2024-05-10 6:35 ` Nam Cao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240430073056.bEG4-yk8@linutronix.de \
--to=namcao@linutronix.de \
--cc=adilger@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bjorn@kernel.org \
--cc=changbin.du@huawei.com \
--cc=christophe.leroy@csgroup.eu \
--cc=geert+renesas@glider.be \
--cc=j.granados@samsung.com \
--cc=kjlx@templeofstupid.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mcgrof@kernel.org \
--cc=mingo@kernel.org \
--cc=ndesaulniers@google.com \
--cc=rppt@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.