Gentoo Archives: gentoo-dev

From: Georgy Yakovlev <gyakovlev@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] linux-mod.eclass: support module signing
Date: Mon, 27 Jun 2022 23:42:58
Message-Id: 0f4a80cb6ee817dc015c1791960df032ae528ea4.camel@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH] linux-mod.eclass: support module signing by Mike Gilbert
1 On Mon, 2022-06-27 at 17:50 -0400, Mike Gilbert wrote:
2 > On Mon, Jun 27, 2022 at 5:11 PM Georgy Yakovlev
3 > <gyakovlev@g.o> wrote:
4 > >
5 > > On Mon, 2022-06-27 at 15:49 -0400, Mike Gilbert wrote:
6 > > > On Mon, Jun 27, 2022 at 3:42 PM Georgy Yakovlev
7 > > > <gyakovlev@g.o> wrote:
8 > > > >
9 > > > > On Mon, 2022-06-27 at 14:56 -0400, Mike Gilbert wrote:
10 > > > > > On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge
11 > > > > > <concord@g.o> wrote:
12 > > > > > > > so looks like we need to combine both methods and do the
13 > > > > > > > following:
14 > > > > > > >  - if signing requested without compression - sign in
15 > > > > > > > pkg_preinst.
16 > > > > > > >  - if signing requested with compression - sign in
17 > > > > > > > src_install
18 > > > > > > >
19 > > > > > >
20 > > > > > > Why can't we do both in pkg_preinst? I am thinking it would
21 > > > > > > be
22 > > > > > > best
23 > > > > > > if
24 > > > > > > we drop the current compression implementation and rework
25 > > > > > > your
26 > > > > > > old
27 > > > > > > code
28 > > > > > > to handle both compression and signing since the signing
29 > > > > > > code
30 > > > > > > is
31 > > > > > > more or
32 > > > > > > less already complete.
33 > > > > >
34 > > > > > Signing modules in pkg_preinst seems like a bad idea to me.
35 > > > > > That
36 > > > > > means
37 > > > > > you need to copy your private keys around to every host where
38 > > > > > the
39 > > > > > package might be installed.
40 > > > > >
41 > > > > > If you sign in src_compile or src_install, you only need
42 > > > > > private
43 > > > > > keys
44 > > > > > on the system building your binpkg.
45 > > > > >
46 > > > >
47 > > > > unfortunately portage will unconditionally strip .ko objects,
48 > > > > rendering
49 > > > > modules unloadable by stripping signature,  unless we do
50 > > > > dostrip -x
51 > > > > (requires EAPI7+, which should not be a problem nowadays, but
52 > > > > was a
53 > > > > problem back in 2018), which can be quite unfortunate on debug
54 > > > > enabled
55 > > > > kernels.
56 > > >
57 > > > Sounds like something to fix/change in Portage. It could probably
58 > > > be
59 > > > updated to not strip the signature. However, I would guess the
60 > > > signature needs to be updated after the binary is modified in any
61 > > > case.
62 > > >
63 > > > Or as a workaround you could disable automatic striping via
64 > > > dostrip -
65 > > > x
66 > > > and run the proper commands to strip the modules in src_install
67 > > > as
68 > > > well.
69 > > >
70 > > I think even strip itself does not have proper options not to break
71 > > module. Several years back it was the case, basically one has to
72 > > strip
73 > > first, sign second, otherwise module will be unloadable.
74 > >
75 > > "Signed modules are BRITTLE as the signature is outside of the
76 > > defined
77 > > ELF container. Thus they MAY NOT be stripped once the signature is
78 > > computed and attached. Note the entire module is the signed
79 > > payload,
80 > > including any and all debug information present at the time of
81 > > signing."
82 > >
83 > > https://www.kernel.org/doc/html/v4.15/admin-guide/module-signing.html#signed-modules-and-stripping
84 > >
85 >
86 > In that case, I think the only viable way to make this work is to
87 > disable automatic stripping and handle stripping via custom code in
88 > the ebuild/eclass.
89 >
90 might work indeed if we do something like (pseudo-bash)
91
92 if [[ module_sign == yes ]]; then
93 dostrip -x /lib/modules # to stop portage stripping .ko objects
94 manual-strip-respecting-features-nostrip -r /lib/modules
95 sign-all-modules -r /lib/modules
96 fi
97 [[ compress_modules == yes ]] && compress-modules -r /lib/modules
98
99
100 this will equire eapi-bumping couple of packages
101 https://qa-reports.gentoo.org/output/eapi-per-eclass/linux-mod.eclass/6.txt
102 and restricting linux-mod.eclass to eapi7 or later.

Replies

Subject Author
Re: [gentoo-dev] [PATCH] linux-mod.eclass: support module signing Georgy Yakovlev <gyakovlev@g.o>