Re: [PATCH 2/9] x86/mm: don't set kernel_set_to_readonly when write protecting fails
From: Edgecombe, Rick P
Date: Tue Nov 24 2026 - 18:01:17 EST
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.
>
> 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.
>
> Report the failure and set kernel_set_to_readonly only when write
> protecting succeeds.
>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>