Re: [PATCH 2/9] x86/mm: don't set kernel_set_to_readonly when write protecting fails

From: Mike Rapoport

Date: Wed Nov 25 2026 - 04:06:06 EST


On Tue, Nov 24, 2026 at 11:01:06PM +0000, Edgecombe, Rick P wrote:
> On Thu, 2026-11-12 at 18:31 +0200, Mike Rapoport (Microsoft) wrote:
> > mark_rodata_ro() ignores the result of write protecting the kernel text
> > and rodata. It can fail when CPA cannot allocate a page table to split a
> > large page, and then a part of the text and rodata stays writable.
>
> Seems like something very unlikely to happen before the kernel has even finished
> booting. Probably other worse problems are coming in that case.

Yeah, most probably we'll crash a few cycles later :)

> > kernel_set_to_readonly is set anyway, and CPA enforces the static
> > protections of rodata from then on. On 64-bit the next call,
> > set_memory_nx() for the data, may find the writable rodata and warn
> > about a conflict with the static protections, which does not say what
> > actually went wrong.

But here we'll see the failure where it happened rather than a
static_protection's WARN a bit later.

Another thing is that hopefully we'll be able to make set_memory_*()
__must_check everywhere Really Soon.

s390 are already doing it:

https://lore.kernel.org/linux-s390/20261118144709.202520-1-hca@xxxxxxxxxxxxx/

> >
> > Report the failure and set kernel_set_to_readonly only when write
> > protecting succeeds.
> >
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
>
>

--
Sincerely yours,
Mike.