2022-09-26 11:27:54

by Greg KH

[permalink] [raw]
Subject: [PATCH 4.14 06/40] efi: libstub: Disable struct randomization

From: Ard Biesheuvel <[email protected]>

[ Upstream commit 1a3887924a7e6edd331be76da7bf4c1e8eab4b1e ]

The EFI stub is a wrapper around the core kernel that makes it look like
a EFI compatible PE/COFF application to the EFI firmware. EFI
applications run on top of the EFI runtime, which is heavily based on
so-called protocols, which are struct types consisting [mostly] of
function pointer members that are instantiated and recorded in a
protocol database.

These structs look like the ideal randomization candidates to the
randstruct plugin (as they only carry function pointers), but of course,
these protocols are contracts between the firmware that exposes them,
and the EFI applications (including our stubbed kernel) that invoke
them. This means that struct randomization for EFI protocols is not a
great idea, and given that the stub shares very little data with the
core kernel that is represented as a randomizable struct, we're better
off just disabling it completely here.

Cc: <[email protected]> # v4.14+
Reported-by: Daniel Marth <[email protected]>
Tested-by: Daniel Marth <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
Acked-by: Kees Cook <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
---
drivers/firmware/efi/libstub/Makefile | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 54dbcec7e06f..7dc2d093962e 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -23,6 +23,13 @@ KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \
$(call cc-option,-ffreestanding) \
$(call cc-option,-fno-stack-protector)

+#
+# struct randomization only makes sense for Linux internal types, which the EFI
+# stub code never touches, so let's turn off struct randomization for the stub
+# altogether
+#
+KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS), $(KBUILD_CFLAGS))
+
# remove SCS flags from all objects in this directory
KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_SCS), $(KBUILD_CFLAGS))

--
2.35.1




2022-09-26 14:55:59

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 4.14 06/40] efi: libstub: Disable struct randomization

Hi!

> These structs look like the ideal randomization candidates to the
> randstruct plugin (as they only carry function pointers), but of course,
> these protocols are contracts between the firmware that exposes them,
> and the EFI applications (including our stubbed kernel) that invoke
> them. This means that struct randomization for EFI protocols is not a
> great idea, and given that the stub shares very little data with the
> core kernel that is represented as a randomizable struct, we're better
> off just disabling it completely here.

> Cc: <[email protected]> # v4.14+

AFAICT RANDSTRUCT_CFLAGS is not available in v4.19, so we should not
take this patch.

Best regards,
Pavel

> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -23,6 +23,13 @@ KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \
> $(call cc-option,-ffreestanding) \
> $(call cc-option,-fno-stack-protector)
>
> +#
> +# struct randomization only makes sense for Linux internal types, which the EFI
> +# stub code never touches, so let's turn off struct randomization for the stub
> +# altogether
> +#
> +KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS), $(KBUILD_CFLAGS))
> +
> # remove SCS flags from all objects in this directory
> KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_SCS), $(KBUILD_CFLAGS))
>

--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany


Attachments:
(No filename) (1.47 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2022-09-26 15:58:48

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [PATCH 4.14 06/40] efi: libstub: Disable struct randomization

On Mon, 26 Sept 2022 at 13:08, Pavel Machek <[email protected]> wrote:
>
> Hi!
>
> > These structs look like the ideal randomization candidates to the
> > randstruct plugin (as they only carry function pointers), but of course,
> > these protocols are contracts between the firmware that exposes them,
> > and the EFI applications (including our stubbed kernel) that invoke
> > them. This means that struct randomization for EFI protocols is not a
> > great idea, and given that the stub shares very little data with the
> > core kernel that is represented as a randomizable struct, we're better
> > off just disabling it completely here.
>
> > Cc: <[email protected]> # v4.14+
>
> AFAICT RANDSTRUCT_CFLAGS is not available in v4.19, so we should not
> take this patch.
>

Ugh, as it turns out, this macro doesn't exist before v5.19 so it
should not be backported beyond that version at all.

Greg, can you please drop this patch from all the -stable trees except
v5.19? Thanks, and apologies for creating confusion.

2022-09-26 17:17:45

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 4.14 06/40] efi: libstub: Disable struct randomization

On Mon, Sep 26, 2022 at 04:16:02PM +0200, Ard Biesheuvel wrote:
> On Mon, 26 Sept 2022 at 13:08, Pavel Machek <[email protected]> wrote:
> >
> > Hi!
> >
> > > These structs look like the ideal randomization candidates to the
> > > randstruct plugin (as they only carry function pointers), but of course,
> > > these protocols are contracts between the firmware that exposes them,
> > > and the EFI applications (including our stubbed kernel) that invoke
> > > them. This means that struct randomization for EFI protocols is not a
> > > great idea, and given that the stub shares very little data with the
> > > core kernel that is represented as a randomizable struct, we're better
> > > off just disabling it completely here.
> >
> > > Cc: <[email protected]> # v4.14+
> >
> > AFAICT RANDSTRUCT_CFLAGS is not available in v4.19, so we should not
> > take this patch.
> >
>
> Ugh, as it turns out, this macro doesn't exist before v5.19 so it
> should not be backported beyond that version at all.
>
> Greg, can you please drop this patch from all the -stable trees except
> v5.19? Thanks, and apologies for creating confusion.

Now dropped from the 4.14, 4.19, and 5.4 queues, it is already in the
5.10 release.

thanks,

greg k-h