[PATCH 4/5] kexec: fallback to KEXEC_LOAD when KEXEC_FILE_LOAD is not supported.
Michal Suchánek
msuchanek at suse.de
Mon Mar 5 09:49:17 PST 2018
On Fri, 2 Mar 2018 17:17:06 +0800
Dave Young <dyoung at redhat.com> wrote:
> On 02/26/18 at 01:00pm, Michal Suchanek wrote:
> > Not all architectures implement KEXEC_FILE_LOAD. However, on some
> > archiectures KEXEC_FILE_LOAD is required when secure boot is
> > enabled in locked-down mode. Previously users had to select the
> > KEXEC_FILE_LOAD syscall with undocumented -s option. However, if
> > they did pass the option kexec would fail on architectures that do
> > not support it.
> >
> > When no option is passed to select one syscall or the other try
> > KEXEC_FILE_LOAD and fall back to KEXEC_LOAD when not suported.
> >
> > Signed-off-by: Michal Suchanek <msuchanek at suse.de>
> > ---
> > kexec/kexec.c | 43 +++++++++++++++++++++++++++++++++++++++----
> > 1 file changed, 39 insertions(+), 4 deletions(-)
> >
> > diff --git a/kexec/kexec.c b/kexec/kexec.c
> > index a95cfb473d6b..14f56e466a95 100644
> > --- a/kexec/kexec.c
> > +++ b/kexec/kexec.c
> > @@ -1243,6 +1243,7 @@ int main(int argc, char *argv[])
> > int do_unload = 0;
> > int do_reuse_initrd = 0;
> > int do_kexec_file_syscall = 0;
> > + int do_kexec_fallback = 1;
> > int do_status = 0;
> > void *entry = 0;
> > char *type = 0;
> > @@ -1367,9 +1368,11 @@ int main(int argc, char *argv[])
> > break;
> > case OPT_KEXEC_FILE_SYSCALL:
> > do_kexec_file_syscall = 1;
> > + do_kexec_fallback = 0;
> > break;
> > case OPT_KEXEC_SYSCALL:
> > do_kexec_file_syscall = 0;
> > + do_kexec_fallback = 0;
> > break;
> > case OPT_STATUS:
> > do_status = 1;
> > @@ -1442,16 +1445,48 @@ int main(int argc, char *argv[])
> > result = k_status(kexec_flags);
> > }
> > if (do_unload) {
> > - if (do_kexec_file_syscall)
> > + if (do_kexec_file_syscall) {
> > result =
> > kexec_file_unload(kexec_file_flags);
> > - else
> > + if ((result == -ENOSYS) &&
> > do_kexec_fallback)
> > + do_kexec_file_syscall = 0;
> > + }
> > + if (!do_kexec_file_syscall)
> > result = k_unload(kexec_flags);
> > }
> > if (do_load && (result == 0)) {
> > - if (do_kexec_file_syscall)
> > + if (do_kexec_file_syscall) {
> > result = do_kexec_file_load(fileind, argc,
> > argv, kexec_file_flags);
> > - else
> > + if (do_kexec_fallback) switch (result) {
> > + /*
> > + * Something failed with signature
> > verification.
> > + * Reject the image.
> > + */
> > + case -ELIBBAD:
> > + case -EKEYREJECTED:
> > + case -ENOPKG:
> > + case -ENOKEY:
> > + case -EBADMSG:
> > + case -EMSGSIZE:
The above do not need to be listed. These are the return values
expected when checking signature fails. This lists is for documentation
purposes only.
> > + case -ENOTSUPP:
> > + /*
> > + * By default reject or do
> > nothing if
> > + * succeded
> > + */
> > + default: break;
> > + /*
> > + * Parsing image or other
> > options failed
> > + * The image may be
> > invalid or image
> > + * type may not supported
> > by kernel so
> > + * retry parsing in
> > kexec-tools.
> > + */
> > + case -EINVAL:
> > + case -ENOEXEC:
> > + do_kexec_file_syscall = 0;
> > + break;
>
> Why do we need checking so many errno,
Linux returns these when it does not understand the image format.
Because some formats are not supported by KEXEC_LOAD_FILE it makes sense
to try parsing the image in kexec-tools.
> I assumed only fallback in
> case -ENOSYS
which is not even listed.
Thanks
Michal
More information about the kexec
mailing list