Re: [PATCH v2] KEYS: trusted: Remove redundant static calls usage
From: Jarkko Sakkinen
Date: Tue Oct 10 2023 - 15:08:06 EST
On Tue, 2023-10-10 at 22:05 +0300, Jarkko Sakkinen wrote:
> On Tue, 2023-10-10 at 11:28 -0700, Linus Torvalds wrote:
> > On Thu, 5 Oct 2023 at 22:18, Sumit Garg <sumit.garg@xxxxxxxxxx> wrote:
> > >
> > > Static calls invocations aren't well supported from module __init and
> > > __exit functions. Especially the static call from cleanup_trusted() led
> > > to a crash on x86 kernel with CONFIG_DEBUG_VIRTUAL=y.
> > >
> > > However, the usage of static call invocations for trusted_key_init()
> > > and trusted_key_exit() don't add any value from either a performance or
> > > security perspective. Hence switch to use indirect function calls instead.
> >
> > I applied this patch to my tree, since it is a fix for the issue, and
> > doesn't change any logic otherwise.
> >
> > However, I do note that the code logic is completely broken. It was
> > broken before too, and apparently causes no problems, but it's still
> > wrong.
> >
> > That's a separate issue, and would want a separate patch, but since I
> > noticed it when applying this one, I'm replying here:
> >
> > > + trusted_key_exit = trusted_key_sources[i].ops->exit;
> > > migratable = trusted_key_sources[i].ops->migratable;
> > >
> > > - ret = static_call(trusted_key_init)();
> > > + ret = trusted_key_sources[i].ops->init();
> > > if (!ret)
> > > break;
> >
> > Note how this sets "trusted_key_exit" even when the ->init() function fails.
>
> Sumit, can you remind me why this continues *on any failure*?
>
> E.g. something like this would make more sense to me:
>
> ret = trusted_key_sources[i].ops->init();
> if (!ret) {
> static_call_update(trusted_key_seal, trusted_key_sources[i].ops->seal);
> static_call_update(trusted_key_unseal, trusted_key_sources[i].ops->unseal);
> static_call_update(trusted_key_get_random, get_random);
> static_call_update(trusted_key_exit, trusted_key_sources[i].ops->exit);
Please ignore the line above :-)
BR, Jarkko