Re: [PATCH v4 15/16] module: Move where we mark modules RO,X

From: Peter Zijlstra
Date: Thu Oct 24 2019 - 16:33:21 EST


On Thu, Oct 24, 2019 at 01:31:15PM -0500, Josh Poimboeuf wrote:

> How about something like this? Completely untested, but if you agree
> with this approach I could hack up kpatch-build to test it properly.
>
> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index ab4a4606d19b..597bf32bc591 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -239,6 +239,17 @@ static int klp_resolve_symbols(Elf_Shdr *relasec, struct module *pmod)
> if (ret)
> return ret;
>
> + /*
> + * Prevent module patches from using livepatch relas for
> + * vmlinux symbols. Presumably such symbols are exported and
> + * normal relas can instead be used at patch module loading
> + * time.
> + */
> + if (!vmlinux && core_kernel_text(addr)) {
> + pr_err("unsupported livepatch symbol\n");
> + return -EINVAL;
> + }
> +
> sym->st_value = addr;
> }

If that works, this is much simpler and therefore preferred.