From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Song Liu <song@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org,
live-patching@vger.kernel.org, x86@kernel.org, jikos@kernel.org,
pmladek@suse.com, joe.lawrence@redhat.com,
Miroslav Benes <mbenes@suse.cz>,
Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: [PATCH v9] livepatch: Clear relocation targets on a module removal
Date: Fri, 20 Jan 2023 12:32:53 -0800 [thread overview]
Message-ID: <20230120203253.5r7dkge6x4vsx5ov@treble> (raw)
In-Reply-To: <CAPhsuW436=wRKLixWNtE9Rx=6A0gKrOCR8EUOdwTrPw5W6gddg@mail.gmail.com>
On Fri, Jan 20, 2023 at 11:41:02AM -0800, Song Liu wrote:
> > > The livepatch module has a relocation which references a symbol
> > > in the _previous_ loading of nfsd. When apply_relocate_add()
> > > tries to replace the old relocation with a new one, it sees that
> > > the previous one is nonzero and it errors out.
> >
> > Should we add a selftest to make sure this problem doesn't come back?
>
> IIRC, a selftest for this issue is not easy without Joe's klp-convert work.
> At the moment I use kpatch-build for testing.
Ah right, I remember that now.
> How about:
>
> Signed-off-by: Song Liu <song@kernel.org>
> Originally-by: Miroslav Benes <mbenes@suse.cz>
> Acked-by: Miroslav Benes <mbenes@suse.cz>
> Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Yes, but the ordering looks off, I think it should be more like:
Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Originally-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Song Liu <song@kernel.org>
Acked-by: Miroslav Benes <mbenes@suse.cz>
And then make sure 'From:' is you.
BTW, this patch affects both livepatch and x86, so the subject prefix
should have "x86" added, something like:
livepatch,x86: Clear relocations on module removal
> > This code really needs to be removed anyway, it's been dead for at least
> > 15 years.
>
> Shall we remove it now? Within the same patch? Or with a preparation
> patch?
>
A preparatory patch sounds good.
> > > + (int)ELF64_R_TYPE(rel[i].r_info), loc, val);
> > > + return -ENOEXEC;
> > > + }
> > > + write(loc, &val, write_size);
> > > + } else {
> > > + if (memcmp(loc, &val, write_size)) {
> > > + pr_warn("x86/modules: Clearing invalid relocation target, existing value does not match expected value for type %d, loc %p, val %Lx\n",
> > > + (int)ELF64_R_TYPE(rel[i].r_info), loc, val);
> > > + }
> > > + write(loc, &zero, write_size);
> >
> > If the value doesn't match then something has gone badly wrong. Why go
> > ahead with the clearing in that case?
>
> We can pr_err() then return -ENOEXEC (?). But I guess we need to
> handle the error case in:
> klp_cleanup_module_patches_limited()
> klp_module_coming()
> klp_module_going()
> and all the functions that call klp_module_going().
>
> This seems a big overkill to me...
>
> Or do you mean we just skip the write()?
At the very least, skip the write.
But I really think it should just break out of the loop and return an
error, there's no point in trying to continue clearing the rest of the
relocations if one of them failed.
It's probably fine for the callers to ignore the error, the module's
going to get unloaded regardless.
--
Josh
prev parent reply other threads:[~2023-01-20 20:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230118204728.1876249-1-song@kernel.org>
2023-01-18 22:08 ` [PATCH v9] livepatch: Clear relocation targets on a module removal Josh Poimboeuf
2023-01-19 19:06 ` Song Liu
2023-01-20 6:42 ` Josh Poimboeuf
2023-01-20 17:03 ` Song Liu
2023-01-20 17:28 ` Josh Poimboeuf
2023-01-24 20:08 ` Joe Lawrence
2023-01-24 22:32 ` Josh Poimboeuf
2023-01-20 19:16 ` Josh Poimboeuf
2023-01-20 19:41 ` Song Liu
2023-01-20 20:32 ` Josh Poimboeuf [this message]
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=20230120203253.5r7dkge6x4vsx5ov@treble \
--to=jpoimboe@kernel.org \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=song@kernel.org \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox