Re: [PATCH v2 6/9] s390/module: Use s390_kernel_write() for late relocations

From: Gerald Schaefer
Date: Wed Apr 22 2020 - 11:21:37 EST


On Wed, 22 Apr 2020 16:40:37 +0200
Gerald Schaefer <gerald.schaefer@xxxxxxxxxx> wrote:

> On Fri, 17 Apr 2020 09:04:31 -0500
> Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
>
> > From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> >
> > Because of late module patching, a livepatch module needs to be able to
> > apply some of its relocations well after it has been loaded. Instead of
> > playing games with module_{dis,en}able_ro(), use existing text poking
> > mechanisms to apply relocations after module loading.
> >
> > So far only x86, s390 and Power have HAVE_LIVEPATCH but only the first
> > two also have STRICT_MODULE_RWX.
> >
> > This will allow removal of the last module_disable_ro() usage in
> > livepatch. The ultimate goal is to completely disallow making
> > executable mappings writable.
> >
> > Also, for the late patching case, use text_mutex, which is supposed to
> > be held for all runtime text patching operations.
> >
> > [ jpoimboe: Split up patches. Use mod state to determine whether
> > memcpy() can be used. Add text_mutex. Make it build. ]
> >
> > Cc: linux-s390@xxxxxxxxxxxxxxx
> > Cc: heiko.carstens@xxxxxxxxxx
> > Suggested-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> > Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> > ---
> > arch/s390/kernel/module.c | 125 ++++++++++++++++++++++++--------------
> > 1 file changed, 79 insertions(+), 46 deletions(-)
>
> Sorry, just noticed this. Heiko will return next month, and I'm not
> really familiar with s390 livepatching. Adding Vasily, he might
> have some more insight.
>
> So, I might be completely wrong here, but using s390_kernel_write()
> for writing to anything other than 1:1 mapped kernel, should go
> horribly wrong, as that runs w/o DAT. It would allow to bypass
> DAT write protection, which I assume is why you want to use it,
> but it should not work on module text section, as that would be
> in vmalloc space and not 1:1 mapped kernel memory.
>
> Not quite sure how to test / trigger this, did this really work for
> you on s390?

OK, using s390_kernel_write() as default write function for module
relocation seems to work fine for me, so apparently I am missing /
mixing up something. Sorry for the noise, please ignore my concern.