From: Jessica Yu <jeyu@kernel.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org
Subject: Re: [PATCH] module: exclude SHN_UNDEF symbols from kallsyms api
Date: Tue, 5 Jun 2018 09:39:27 +0200 [thread overview]
Message-ID: <20180605073927.ygfa3ucdwnec57e5@d217.suse.de> (raw)
In-Reply-To: <20180604230226.5saxrc75vreg4n2y@treble>
+++ Josh Poimboeuf [04/06/18 18:02 -0500]:
>On Mon, Jun 04, 2018 at 05:56:05PM -0500, Josh Poimboeuf wrote:
>> On Mon, Jun 04, 2018 at 09:54:12AM -0500, Josh Poimboeuf wrote:
>> > On Mon, Jun 04, 2018 at 04:05:11PM +0200, Jessica Yu wrote:
>> > > +++ Josh Poimboeuf [04/06/18 08:16 -0500]:
>> > > > On Mon, Jun 04, 2018 at 03:01:31PM +0200, Jessica Yu wrote:
>> > > > > +++ Jessica Yu [04/06/18 11:54 +0200]:
>> > > > > > +++ Jessica Yu [04/06/18 10:05 +0200]:
>> > > > > > > +++ Josh Poimboeuf [02/06/18 12:32 -0500]:
>> > > > > > > > Hi Jessica,
>> > > > > > > >
>> > > > > > > > I found a bug:
>> > > > > > > >
>> > > > > > > > [root@f25 ~]# modprobe livepatch-sample
>> > > > > > > > [root@f25 ~]# grep ' u ' /proc/kallsyms
>> > > > > > > > ffffffff81161080 u klp_enable_patch [livepatch_sample]
>> > > > > > > > ffffffff81a01800 u __fentry__ [livepatch_sample]
>> > > > > > > > ffffffff81161250 u klp_unregister_patch [livepatch_sample]
>> > > > > > > > ffffffff81161870 u klp_register_patch [livepatch_sample]
>> > > > > > > > ffffffff8131f0b0 u seq_printf [livepatch_sample]
>> > > > > > > >
>> > > > > > > > Notice that livepatch modules' undefined symbols are showing up in
>> > > > > > > > /proc/kallsyms. This can confuse klp_find_object_symbol() which can
>> > > > > > > > cause subtle bugs in livepatch.
>> > > > > > > >
>> > > > > > > > I stared at the module kallsyms code for a bit, but I don't see the bug.
>> > > > > > > > Maybe it has something to do with how we save the symbol table in
>> > > > > > > > copy_module_elf(). Any ideas?
>> > > > > > >
>> > > > > > > Hi Josh!
>> > > > > > >
>> > > > > > > This is because we preserve the entire symbol table for livepatch
>> > > > > > > modules, including the SHN_UNDEF symbols. IIRC, this is so that we can
>> > > > > > > still apply relocations properly with apply_relocate_add() after a
>> > > > > > > to-be-patched object is loaded. Normally we don't save these SHN_UNDEF
>> > > > > > > symbols for modules so they do not appear in /proc/kallsyms.
>> > > > > >
>> > > > > > Hm, if having the full symtab in kallsyms is causing trouble, one
>> > > > > > possibility would be to just have the module kallsyms code simply
>> > > > > > skip/ignore undef symbols. That's what we technically do for normal
>> > > > > > modules anyway (we normally cut undef syms out of the symtab). Haven't
>> > > > > > tested this idea but does that sound like it'd help?
>> > > > >
>> > > > > See if the following patch (untested) helps. It does not fix the
>> > > > > /proc/kallsyms lookup, that requires a separate patch. But it should
>> > > > > exclude the undef symbols from module_kallsyms_on_each_symbol() and
>> > > > > thus also from klp_find_object_symbol().
>> > > >
>> > > > That seems like it would work. But wouldn't it be more robust if we
>> > > > don't store the SHN_UNDEF symbols to start with? Really it's only the
>> > > > SHN_LIVEPATCH symbols that we need to keep, right?
>> > >
>> > > Hm, didn't we have a reason for preserving the original symbol tables?
>> > > It's not that we're storing the undef symbols on purpose, it's just
>> > > that in the case of a livepatch module we keep *all* the symbols.
>> > > IIRC, the original reasoning was that we needed to keep the original
>> > > symtab indices in place, otherwise apply_relocate() (which uses the
>> > > original symbol index encoded in the relocation) won't work.
>> > > Selectively copying only SHN_LIVEPATCH symbols when building the
>> > > module's symbol table will unfortunately mess the symbol indices up :/
>> > > Under these restrictions, it just seemed easier to make kallsyms
>> > > ignore undef symbols.
>> >
>> > Ah, you're right. I'll try out your patch.
>>
>> I can confirm that your patch fixes the issue. Thanks!
>
>BTW you can add my
>
>Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
>Tested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Thanks for testing! Will clean up the patch and formally repost it.
It'll be queued up in modules-next after the merge window.
Thanks,
Jessica
next prev parent reply other threads:[~2018-06-05 7:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-02 17:32 /proc/kallsyms shows undefined symbols for livepatch modules Josh Poimboeuf
2018-06-04 8:05 ` Jessica Yu
2018-06-04 9:54 ` Jessica Yu
2018-06-04 13:01 ` [PATCH] module: exclude SHN_UNDEF symbols from kallsyms api Jessica Yu
2018-06-04 13:16 ` Josh Poimboeuf
2018-06-04 14:05 ` Jessica Yu
2018-06-04 14:54 ` Josh Poimboeuf
2018-06-04 22:56 ` Josh Poimboeuf
2018-06-04 23:02 ` Josh Poimboeuf
2018-06-05 7:39 ` Jessica Yu [this message]
2018-06-05 8:42 Jessica Yu
2018-06-05 13:57 ` Josh Poimboeuf
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=20180605073927.ygfa3ucdwnec57e5@d217.suse.de \
--to=jeyu@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.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;
as well as URLs for NNTP newsgroup(s).