• Re: [gentoo-dev] [PATCH] linux-mod.eclass: support module signing

    From Kenton Groombridge@21:1/5 to Kenton Groombridge on Tue Jun 21 20:30:01 2022
    On 22/06/21 02:19PM, Kenton Groombridge wrote:
    eee74b9fca1 adds support for module compression, but this breaks loading
    out of tree modules when module signing is enforced because modules must
    be signed before they are compressed. Additionally, the recommended
    Portage hook[1] no longer works with this change.


    Forgot to include this reference:

    [1] https://wiki.gentoo.org/wiki/Signed_kernel_module_support#Automatically_signing_kernel_modules_.28Portage.29

    Add module signing support in linux-mod.eclass which more or less does exactly what the aforementioned Portage hook does. If the kernel configuration has CONFIG_MODULE_SIG_ALL=y, then read the hash and keys
    from the kernel configuration and call the sign_file tool to sign the
    module before it is compressed.

    Bug: https://bugs.gentoo.org/show_bug.cgi?id=447352
    Signed-off-by: Kenton Groombridge <concord@gentoo.org>
    ---
    eclass/linux-mod.eclass | 16 ++++++++++++++++
    1 file changed, 16 insertions(+)

    diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
    index b7c13cbf7e7..fd40f6d7c6c 100644
    --- a/eclass/linux-mod.eclass
    +++ b/eclass/linux-mod.eclass
    @@ -712,6 +712,22 @@ linux-mod_src_install() {
    cd "${objdir}" || die "${objdir} does not exist"
    insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir}

    + # check here for CONFIG_MODULE_SIG_ALL and sign the module being built if enabled.
    + # modules must be signed before they are compressed.
    +
    + if linux_chkconfig_present MODULE_SIG_ALL; then
    + local module_sig_hash="$(linux_chkconfig_string MODULE_SIG_HASH)"
    + local module_sig_key="$(linux_chkconfig_string MODULE_SIG_KEY)"
    + module_sig_key="${module_sig_key:-certs/signing_key.pem}"
    + if [[ "${module_sig_key#pkcs11:}" == "${module_sig_key}" && "${module_sig_key#/}" == "${module_sig_key}" ]]; then
    + local key_path="${KERNEL_DIR}/${module_sig_key}"
    + else
    + local key_path="${module_sig_key}"
    + fi
    + local cert_path="${KERNEL_DIR}/certs/signing_key.x509" + "${KERNEL_DIR}"/scripts/sign-file ${module_sig_hash//\"} ${key_path//\"} ${cert_path} ${modulename}.${KV_OBJ}
    + fi
    +
    # check here for CONFIG_MODULE_COMPRESS_<compression option> (NONE, GZIP, XZ, ZSTD)
    # and similarily compress the module being built if != NONE.

    --
    2.35.1



    -----BEGIN PGP SIGNATURE-----

    iQKTBAABCgB9FiEEP+u3AkfbrORB/inCFt7v5V9Ft54FAmKyDERfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNG RUJCNzAyNDdEQkFDRTQ0MUZFMjlDMjE2REVFRkU1NUY0NUI3OUUACgkQFt7v5V9F t55Rrg/9EpvkSch82zFayh8fKiQ+k71gfoBGFjn2wpGz8vgwtObbeG2EP97mSH7V SvuDbdOURoOb+Rlm9hZrhX4bhBISgkzqIhCFhCfaJlknJ2bjXUl0Nr0qYFHXutW0 M4znGxUvWeMdwlp3Z+MTL3isdG9YnzG5/mpfo2MvRAxUXIK5Fijw5RCVlbycvyU7 Nyq5uGtxJY3En+SccTUKzEXolG4ainJ+FgIQ9QVHlAE8nnpAkiezDb9Ya/ttk/OS +G22Mcm9VIGpRAnPjTdgEMelEt1twVO+rFD9gDK6jvNpDbijftCu6V1BIEoB97II UJ+/Oa0qk127HQshamE10NdDrCyz9kAMG8cjjsUBLjIy2RkuiJ/pPVY8S0GwZIdN K1J8Kly+bivIPh6bgy6pfdTVWyS+LhFfONyvstt3ZX2Gx1jJUecGOo4jyq29rYRl wZfsuuDkkwPsr2bL3PSR7pnYoaDi6bcTzHj75lp7dMwwwEmgKfirUK7wmRuyZ59m Kq37fisa5ZcIgRgKOxdSpq5SxTnk158DJk8RjUB9UdtLtjabP8tz//AJSE6wJXbC QQywCMXl88DrRZJkGyTjYf+Z9VhOyG6s4qkj9RLdeDpaYLoFmuhmqQSna468zSDB 1fJwr2WdnexoXxTcY0Og81+oW2wBJXJpioxsHr+1dRShl8xM5SA=
    =Qxxd
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenton Groombridge@21:1/5 to All on Tue Jun 21 20:30:01 2022
    eee74b9fca1 adds support for module compression, but this breaks loading
    out of tree modules when module signing is enforced because modules must
    be signed before they are compressed. Additionally, the recommended
    Portage hook[1] no longer works with this change.

    Add module signing support in linux-mod.eclass which more or less does
    exactly what the aforementioned Portage hook does. If the kernel
    configuration has CONFIG_MODULE_SIG_ALL=y, then read the hash and keys
    from the kernel configuration and call the sign_file tool to sign the
    module before it is compressed.

    Bug: https://bugs.gentoo.org/show_bug.cgi?id=447352
    Signed-off-by: Kenton Groombridge <concord@gentoo.org>
    ---
    eclass/linux-mod.eclass | 16 ++++++++++++++++
    1 file changed, 16 insertions(+)

    diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
    index b7c13cbf7e7..fd40f6d7c6c 100644
    --- a/eclass/linux-mod.eclass
    +++ b/eclass/linux-mod.eclass
    @@ -712,6 +712,22 @@ linux-mod_src_install() {
    cd "${objdir}" || die "${objdir} does not exist"
    insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir}

    + # check here for CONFIG_MODULE_SIG_ALL and sign the module being built if enabled.
    + # modules must be signed before they are compressed.
    +
    + if linux_chkconfig_present MODULE_SIG_ALL; then
    + local module_sig_hash="$(linux_chkconfig_string MODULE_SIG_HASH)"
    + local module_sig_key="$(linux_chkconfig_string MODULE_SIG_KEY)"
    + module_sig_key="${module_sig_key:-certs/signing_key.pem}"
    + if [[ "${module_sig_key#pkcs11:}" == "${module_sig_key}" && "${module_sig_key#/}" == "${module_sig_key}" ]]; then
    + local key_path="${KERNEL_DIR}/${module_sig_key}"
    + else
    + local ke
  • From Mike Pagano@21:1/5 to Kenton Groombridge on Thu Jun 23 15:00:01 2022
    On 6/21/22 14:21, Kenton Groombridge wrote:
    On 22/06/21 02:19PM, Kenton Groombridge wrote:
    eee74b9fca1 adds support for module compression, but this breaks loading
    out of tree modules when module signing is enforced because modules must
    be signed before they are compressed. Additionally, the recommended
    Portage hook[1] no longer works with this change.


    Forgot to include this reference:

    [1] https://wiki.gentoo.org/wiki/Signed_kernel_module_support#Automatically_signing_kernel_modules_.28Portage.29

    Add module signing support in linux-mod.eclass which more or less does
    exactly what the aforementioned Portage hook does. If the kernel
    configuration has CONFIG_MODULE_SIG_ALL=y, then read the hash and keys
    from the kernel configuration and call the sign_file tool to sign the
    module before it is compressed.

    Bug: https://bugs.gentoo.org/show_bug.cgi?id=447352
    Signed-off-by: Kenton Groombridge <concord@gentoo.org>
    ---
    eclass/linux-mod.eclass | 16 ++++++++++++++++
    1 file changed, 16 insertions(+)

    diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
    index b7c13cbf7e7..fd40f6d7c6c 100644
    --- a/eclass/linux-mod.eclass
    +++ b/eclass/linux-mod.eclass
    @@ -712,6 +712,22 @@ linux-mod_src_install() {
    cd "${objdir}" || die "${objdir} does not exist"
    insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir} >>
    + # check here for CONFIG_MODULE_SIG_ALL and sign the module being built if enabled.
    + # modules must be signed before they are compressed.
    +
    + if linux_chkconfig_present MODULE_SIG_ALL; then
    + local module_sig_hash="$(linux_chkconfig_string MODULE_SIG_HASH)"
    + local module_sig_key="$(linux_chkconfig_string MODULE_SIG_KEY)"
    + module_sig_key="${module_sig_key:-certs/signing_key.pem}"
    + if [[ "${module_sig_key#pkcs11:}" == "${module_sig_key}" && "${module_sig_key#/}" == "${module_sig_key}" ]]; then
    + local key_path="${KERNEL_DIR}/${module_sig_key}"
    + else
    + local key_path="${module_sig_key}"
    + fi
    + local cert_path="${KERNEL_DIR}/certs/signing_key.x509" >> + "${KERNEL_DIR}"/scripts/sign-file ${module_sig_hash//\"} ${key_path//\"} ${cert_path} ${modulename}.${KV_OBJ}
    + fi
    +
    # check here for CONFIG_MODULE_COMPRESS_<compression option> (NONE, GZIP, XZ, ZSTD)
    # and similarily compress the module being built if != NONE.

    --
    2.35.1




    First of all, thank-you for your work !
    I appreciate any assistance with enhancement or clean-up of these eclasses.

    I tested your patch, are you signing the files in 'work' after they are installed in 'image' ?


    /usr/src/linux/scripts/extract-module-sig.pl -s ./work/kernel/nvidia.ko > /tmp/sig
    Read 47802433 bytes from module file
    Found magic number at 47802433
    Found PKCS#7/CMS encapsulation
    Found 681 bytes of signature [308202a506092a864886f70d010702a0]

    /usr/src/linux/scripts/extract-module-sig.pl -s ./image/lib/modules/5.18.6-gentoo/video/nvidia.ko > /tmp/sig
    Read 47227784 bytes from module file
    Magic number not found at 47227784



    Mike




    --
    Mike Pagano
    Gentoo Developer - Kernel Project
    Gentoo Sources - Lead
    E-Mail : mpagano@gentoo.org
    GnuPG FP : 52CC A0B0 F631 0B17 0142 F83F 92A6 DBEC 81F2 B137
    Public Key : http://http://pgp.mit.edu/pks/lookup?search=0x92A6DBEC81F2B137&op=index

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenton Groombridge@21:1/5 to Mike Pagano on Thu Jun 23 16:40:01 2022
    On 22/06/23 08:51AM, Mike Pagano wrote:
    On 6/21/22 14:21, Kenton Groombridge wrote:
    On 22/06/21 02:19PM, Kenton Groombridge wrote:
    eee74b9fca1 adds support for module compression, but this breaks loading out of tree modules when module signing is enforced because modules must be signed before they are compressed. Additionally, the recommended Portage hook[1] no longer works with this change.


    Forgot to include this reference:

    [1] https://wiki.gentoo.org/wiki/Signed_kernel_module_support#Automatically_signing_kernel_modules_.28Portage.29

    Add module signing support in linux-mod.eclass which more or less does exactly what the aforementioned Portage hook does. If the kernel configuration has CONFIG_MODULE_SIG_ALL=y, then read the hash and keys from the kernel configuration and call the sign_file tool to sign the module before it is compressed.

    Bug: https://bugs.gentoo.org/show_bug.cgi?id=447352
    Signed-off-by: Kenton Groombridge <concord@gentoo.org>
    ---
    eclass/linux-mod.eclass | 16 ++++++++++++++++
    1 file changed, 16 insertions(+)

    diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
    index b7c13cbf7e7..fd40f6d7c6c 100644
    --- a/eclass/linux-mod.eclass
    +++ b/eclass/linux-mod.eclass
    @@ -712,6 +712,22 @@ linux-mod_src_install() {
    cd "${objdir}" || die "${objdir} does not exist"
    insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir}
    + # check here for CONFIG_MODULE_SIG_ALL and sign the module being built if enabled.
    + # modules must be signed before they are compressed.
    +
    + if linux_chkconfig_present MODULE_SIG_ALL; then
    + local module_sig_hash="$(linux_chkconfig_string MODULE_SIG_HASH)"
    + local module_sig_key="$(linux_chkconfig_string MODULE_SIG_KEY)"
    + module_sig_key="${module_sig_key:-certs/signing_key.pem}"
    + if [[ "${module_sig_key#pkcs11:}" == "${module_sig_key}" && "${module_sig_key#/}" == "${module_sig_key}" ]]; then
    + local key_path="${KERNEL_DIR}/${module_sig_key}"
    + else
    + local key_path="${module_sig_key}"
    + fi
    + local cert_path="${KERNEL_DIR}/certs/signing_key.x509" + "${KERNEL_DIR}"/scripts/sign-file ${module_sig_hash//\"} ${key_path//\"} ${cert_path} ${modulename}.${KV_OBJ}
    + fi
    +
    # check here for CONFIG_MODULE_COMPRESS_<compression option> (NONE, GZIP, XZ, ZSTD)
    # and similarily compress the module being built if != NONE.
    --
    2.35.1




    First of all, thank-you for your work !
    I appreciate any assistance with enhancement or clean-up of these eclasses.

    I tested your patch, are you signing the files in 'work' after they are installed in 'image' ?


    /usr/src/linux/scripts/extract-module-sig.pl -s ./work/kernel/nvidia.ko > /tmp/sig
    Read 47802433 bytes from module file
    Found magic number at 47802433
    Found PKCS#7/CMS encapsulation
    Found 681 bytes of signature [308202a506092a864886f70d010702a0]

    /usr/src/linux/scripts/extract-module-sig.pl -s ./image/lib/modules/5.18.6-gentoo/video/nvidia.ko > /tmp/sig
    Read 47227784 bytes from module file
    Magic number not found at 47227784


    Thanks for testing!

    That's odd. In my environment they are signed in 'work' before
    installing to 'image' as they should be.

    # unzstd /lib/modules/5.15.48-gentoo/misc/p_lkrg.ko.zst /lib/modules/5.15.48-gentoo/misc/p_lkrg.ko.zst: 436681 bytes
    # /usr/src/linux/scripts/extract-module-sig.pl -s /lib/modules/5.15.48-gentoo/misc/p_lkrg.ko >sig
    Read 436681 bytes from module file
    Found magic number at 436681
    Found PKCS#7/CMS encapsulation
    Found 681 bytes of signature [308202a506092a864886f70d010702a0]

    The installation of modules in linux-mod_src_install happens after
    signing and compression, so unless I am missing something that shouldn't
    be happening.

    -----BEGIN PGP SIGNATURE-----

    iQKTBAABCgB9FiEEP+u3AkfbrORB/inCFt7v5V9Ft54FAmK0eONfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNG RUJCNzAyNDdEQkFDRTQ0MUZFMjlDMjE2REVFRkU1NUY0NUI3OUUACgkQFt7v5V9F t56o0BAAtQ2HoSTTCL0y2WkGTnDIkv14Ydm5oF5pU21YM9MYVF262Mf6yj8n5CvD bMgn+M74WIFT4PIP7u6BXF62JaO+5zGrlWqAlt9o7ilYoGPqjtYCDrD4b2XROzIR yMBBIseFQQpaud9ElUn8rxhsAwY0iivtq4RG4Et7Do12wOQByXDPWmK0+OKfBKi+ tG976EaW2fGKNHCeMrH1mw1DcoLsM0GpMhUjTU10FLEsEuYcyzyPF0luXX2qqogo txZW242tLrvdKN+5zGc+PXG6yEY9XPXzUqArfs1FF0rneGbp+Zq1iYD9zdP1/vTA +ElxDxELLUtBd19K2CThKJXpH5MDPXJ0XPiOqwY3RWqtqyLehNnRnwfSPv8Cz+G7 KieLe7PbG9KtQ/96heSAAzSWrOh5tsaaojq36CiQOyyAsC+LQIuYXFnAVOoXqO6t 5W0txfOEvy33hGRsTmGXmji1skUY6FMlw05i0LZfogLSc8GH5smnnmGuUGcSQk9U mDED930mr+BvyNSAKRUZpaEmN/gqFlEnomHdKRAwLIzcwnvnJQ2k6A6KntqcUQWK qOdpVW8gcH1kSVootzEbRD4zclNdbsY1UEQe/XKlH63EmYMSW9zJjQkoisFfSDl8 TP9yAiN93QENXXAjYBKqUNrTo7lJfvGSXvaTSWNjAQtYyn0Q578=
    =G7Gj
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to All on Sun Jun 26 13:00:01 2022
    T24gVHVlLCAyMDIyLTA2LTIxIGF0IDE0OjE5IC0wNDAwLCBLZW50b24gR3Jvb21icmlkZ2Ugd3Jv dGU6Cj4gZWVlNzRiOWZjYTEgYWRkcyBzdXBwb3J0IGZvciBtb2R1bGUgY29tcHJlc3Npb24sIGJ1 dCB0aGlzIGJyZWFrcwo+IGxvYWRpbmcKPiBvdXQgb2YgdHJlZSBtb2R1bGVzIHdoZW4gbW9kdWxl IHNpZ25pbmcgaXMgZW5mb3JjZWQgYmVjYXVzZSBtb2R1bGVzCj4gbXVzdAo+IGJlIHNpZ25lZCBi ZWZvcmUgdGhleSBhcmUgY29tcHJlc3NlZC4gQWRkaXRpb25hbGx5LCB0aGUgcmVjb21tZW5kZWQK PiBQb3J0YWdlIGhvb2tbMV0gbm8gbG9uZ2VyIHdvcmtzIHdpdGggdGhpcyBjaGFuZ2UuCj4gCj4g QWRkIG1vZHVsZSBzaWduaW5nIHN1cHBvcnQgaW4gbGludXgtbW9kLmVjbGFzcyB3aGljaCBtb3Jl IG9yIGxlc3MKPiBkb2VzCj4gZXhhY3RseSB3aGF0IHRoZSBhZm9yZW1lbnRpb25lZCBQb3J0YWdl IGhvb2sgZG9lcy4gSWYgdGhlIGtlcm5lbAo+IGNvbmZpZ3VyYXRpb24gaGFzIENPTkZJR19NT0RV TEVfU0lHX0FMTD15LCB0aGVuIHJlYWQgdGhlIGhhc2ggYW5kCj4ga2V5cwo+IGZyb20gdGhlIGtl cm5lbCBjb25maWd1cmF0aW9uIGFuZCBjYWxsIHRoZSBzaWduX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L21lc3NhZ2UvNGIxNWIxYzg1MWYzNzlh MWY4MDJlMmYyODk1Y2RmYTgKCllvdSB3aWxsIGFsc28gbmVlZCBhIGRlcGVuZGVuY3kgb24gb3Bl bnNzbCwgc2luY2Ugc2lnbi1maWxlIHVzZXMgaXQuCgpsbWsgaWYgeW91IG5lZWQgbW9yZSBpbmZv LCBJIG1pZ2h0IHJlbWVtYmVyIG1vcmUgZGV0YWlscywgYnV0IGZvciBub3cKdGhhdCdzIGFsbCBJ IGhhdmUuIEknbGwgdHJ5IHRvIGhlbHAgZ2V0IGl0IGRvbmUsIGJ1dCBteSBhdmFpbGFiaWxpdHkg aXMKc3BvdHR5IGR1ZSB0byBsaW1pdGVkIHRpbWUuCg==

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to Georgy Yakovlev on Sun Jun 26 13:20:01 2022
    On Sun, 2022-06-26 at 03:52 -0700, Georgy Yakovlev wrote:
    On Tue, 2022-06-21 at 14:19 -0400, Kenton Groombridge wrote:
    eee74b9fca1 adds support for module compression, but this breaks
    loading
    out of tree modules when module signing is enforced because modules
    must
    be signed before they are compressed. Additionally, the recommended
    Portage hook[1] no longer works with this change.

    Add module signing support in linux-mod.eclass which more or less
    does
    exactly what the aforementioned Portage hook does. If the kernel configuration has CONFIG_MODULE_SIG_ALL=y, then read the hash and
    keys
    from the kernel configuration and call the sign_file tool to sign
    the
    module before it is compressed.

    Bug: https://bugs.gentoo.org/show_bug.cgi?id=447352
    Signed-off-by: Kenton Groombridge <concord@gentoo.org>
    ---
     eclass/linux-mod.eclass | 16 ++++++++++++++++
     1 file changed, 16 insertions(+)

    diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
    index b7c13cbf7e7..fd40f6d7c6c 100644
    --- a/eclass/linux-mod.eclass
    +++ b/eclass/linux-mod.eclass
    @@ -712,6 +712,22 @@ linux-mod_src_install() {                 cd "${objdir}" || die "${objdir} does not exist"
                    insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir}
     
    +               # check here for CONFIG_MODULE_SIG_ALL and sign the
    module being built if enabled.
    +               # modules must be signed before they are compressed.
    +
    +               if linux_chkconfig_present MODULE_SIG_ALL; then
    +                       local module_sig_hash="$(linux_chkconfig_string MODULE_SIG_HASH)" +                       local module_sig_key="$(linux_chkconfig_string MODULE_SIG_KEY)" +                       module_sig_key="${module_sig_key:-
    certs/signing_key.pem}"
    +                       if [[ "${module_sig_key#pkcs11:}" ==
    "${module_sig_key}" && "${module_sig_key#/}" == "${module_sig_key}"
    ]]; then +                               local key_path="${KERNEL_DIR}/${module_sig_key}" +                       else +                               local key_path="${module_sig_key}"
    +                       fi +                       local cert_path="${KERNEL_DIR}/certs/signing_key.x509" +                       "${KERNEL_DIR}"/scripts/sign-file
    ${module_sig_hash//\"} ${key_path//\"} ${cert_path}
    ${modulename}.${KV_OBJ}
    +               fi
    +
                    # check here for CONFIG_MODULE_COMPRESS_<compression
    option> (NONE, GZIP, XZ, ZSTD)
                    # and similarily compress the module being built if
    != NONE.
     


    Hi,

    I've spent some time in the past ( circa 2018 ) to get this in, but
    gave up due to various reasons, I was not a gentoo dev yet at the
    time.

    I can't see how posted implementation will work tbh.
    portage will strip signature out of the module, unless you prevent
    stripping completely or package uses EAPI>=7, and omits stripping
    modules via dostrip -x on the ko object.
    kernel will NOT load module with stripped signature.

    so either you have to sign in pkg_postinst phase, or prevent
    stripping.
    signing in postinst is not ideal, because if breaks recorded file
    checksums in vdb.

    here's old fork of eclass I made, maybe you can find some helpful
    code
    in there

    https://github.com/gyakovlev/linux-mod.eclass/blob/master/linux-mod.eclass

    old ML discussion we had: https://archives.gentoo.org/gentoo-dev/message/4b15b1c851f379a1f802e2f2895cdfa8

    You will also need a dependency on openssl, since sign-file uses it.

    lmk if you need more info, I might remember more details, but for now
    that's all I have. I'll try to help get it done, but my availability
    is
    spotty due to limited time.

    after reading my old code again and thinking more I think I know what's
    going on.
    1. I've actually solved checksum/strip problem by signing in pkg-
    preinst
    2. my method will likely fail with compressed modules.
    3. your method likely works only if modules are compressed - because
    portage does not strip those I think.

    so looks like we need to combine both methods and do the following:
    - if signing requested without compression - sign in pkg_preinst.
    - if signing requested with compression - sign in src_install

    Do I make sense? I still haven't tested it, just guessing as I read my
    old bash code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenton Groombridge@21:1/5 to Georgy Yakovlev on Mon Jun 27 20:40:01 2022
    On 22/06/26 04:15AM, Georgy Yakovlev wrote:
    On Sun, 2022-06-26 at 03:52 -0700, Georgy Yakovlev wrote:
    On Tue, 2022-06-21 at 14:19 -0400, Kenton Groombridge wrote:
    eee74b9fca1 adds support for module compression, but this breaks
    loading
    out of tree modules when module signing is enforced because modules
    must
    be signed before they are compressed. Additionally, the recommended Portage hook[1] no longer works with this change.

    Add module signing support in linux-mod.eclass which more or less
    does
    exactly what the aforementioned Portage hook does. If the kernel configuration has CONFIG_MODULE_SIG_ALL=y, then read the hash and
    keys
    from the kernel configuration and call the sign_file tool to sign
    the
    module before it is compressed.

    Bug: https://bugs.gentoo.org/show_bug.cgi?id=447352
    Signed-off-by: Kenton Groombridge <concord@gentoo.org>
    ---
     eclass/linux-mod.eclass | 16 ++++++++++++++++
     1 file changed, 16 insertions(+)

    diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
    index b7c13cbf7e7..fd40f6d7c6c 100644
    --- a/eclass/linux-mod.eclass
    +++ b/eclass/linux-mod.eclass
    @@ -712,6 +712,22 @@ linux-mod_src_install() {                 cd "${objdir}" || die "${objdir} does not exist"
                    insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir}
     
    +               # check here for CONFIG_MODULE_SIG_ALL and sign the
    module being built if enabled.
    +               # modules must be signed before they are compressed.
    +
    +               if linux_chkconfig_present MODULE_SIG_ALL; then
    +                       local module_sig_hash="$(linux_chkconfig_string MODULE_SIG_HASH)" +                       local module_sig_key="$(linux_chkconfig_string MODULE_SIG_KEY)" +                       module_sig_key="${module_sig_key:-
    certs/signing_key.pem}"
    +                       if [[ "${module_sig_key#pkcs11:}" ==
    "${module_sig_key}" && "${module_sig_key#/}" == "${module_sig_key}"
    ]]; then +                               local key_path="${KERNEL_DIR}/${module_sig_key}" +                       else +                               local key_path="${module_sig_key}"
    +                       fi +                       local cert_path="${KERNEL_DIR}/certs/signing_key.x509" +                       "${KERNEL_DIR}"/scripts/sign-file
    ${module_sig_hash//\"} ${key_path//\"} ${cert_path} ${modulename}.${KV_OBJ}
    +               fi
    +
                    # check here for CONFIG_MODULE_COMPRESS_<compression
    option> (NONE, GZIP, XZ, ZSTD)
                    # and similarily compress the module being built if
    != NONE.
     


    Hi,

    I've spent some time in the past ( circa 2018 ) to get this in, but
    gave up due to various reasons, I was not a gentoo dev yet at the
    time.

    I can't see how posted implementation will work tbh.
    portage will strip signature out of the module, unless you prevent stripping completely or package uses EAPI>=7, and omits stripping
    modules via dostrip -x on the ko object.
    kernel will NOT load module with stripped signature.

    so either you have to sign in pkg_postinst phase, or prevent
    stripping.
    signing in postinst is not ideal, because if breaks recorded file
    checksums in vdb.

    here's old fork of eclass I made, maybe you can find some helpful
    code
    in there

    https://github.com/gyakovlev/linux-mod.eclass/blob/master/linux-mod.eclass

    old ML discussion we had: https://archives.gentoo.org/gentoo-dev/message/4b15b1c851f379a1f802e2f2895cdfa8

    You will also need a dependency on openssl, since sign-file uses it.

    lmk if you need more info, I might remember more details, but for now that's all I have. I'll try to help get it done, but my availability
    is
    spotty due to limited time.

    after reading my old code again and thinking more I think I know what's
    going on.
    1. I've actually solved checksum/strip problem by signing in pkg-
    preinst
    2. my method will likely fail with compressed modules.
    3. your method likely works only if modules are compressed - because
    portage does not strip those I think.


    This is exactly what I was thinking. I'm pretty sure I wasn't seeing the problematic signature stripping behavior because I have module
    compression enabled.

    Also good point about the OpenSSL dependency. That's something I didn't consider.

    so looks like we need to combine both methods and do the following:
    - if signing requested without compression - sign in pkg_preinst.
    - if signing requested with compression - sign in src_install


    Why can't we do both in pkg_preinst? I am thinking it would be best if
    we drop the current compression implementation and rework your old code
    to handle both compression and signing since the signing code is more or
    less already complete.

    Do I make sense? I still haven't tested it, just guessing as I read my
    old bash code.


    -----BEGIN PGP SIGNATURE-----

    iQKTBAABCgB9FiEEP+u3AkfbrORB/inCFt7v5V9Ft54FAmK5+GxfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNG RUJCNzAyNDdEQkFDRTQ0MUZFMjlDMjE2REVFRkU1NUY0NUI3OUUACgkQFt7v5V9F t54dvRAApABvQ+7TS05OOv5+KeALn4/yJPTSmgVj2Jc/UOHx8MBHVwXP18zywYUo f7g052WHxT78aTYUISZJzrHGvSKFH+Pf39s+C2DriQlAWMUeAPZqxQTHtmmDoxRh 9deQLPd0L0t1JTU0Rcr25vHkkx2izojT6A3BHMdXP8KtuV6ZM3Rf0sY4z6AuU1sB 5h7w5bg694zgQZhEAs5qZwnfEMSg4njstZzQKd0Mm59p4IhIgq+uEuUENuUsTVHL T4ZzSvct8v3VLblN+5W2DJj9dC0lFPzUb/xUZbKpu4tkfa9N7ivwftmhjq79FEIh BuC7V41NhzVFaJpcd3LNM+83aRoFL7gOwSgsl1bNHyXOaom7xVvUbcEUUlrvpDdS 0lGLaPOWxNaehrWzSbZulkKsuP83Hn8e8/pwHIe+hCj/qWfxuKvRmsyBaIZM9Lql RmE4ZbKZ1aeiLvIB8r4hpEbK9bBuD5hOogXJe4LtXUAOxuYOCP0WQ8YhD8rJMpXU h5orto31DcjLROUhw6sA8fbnsbojfCgtXqGpNcIrlupXJ3hSbZdbS2cBz2Twj1gP dXQ/bJWMvUannarYVi8XVxbpDQSV+YH/1/om1UjGyVJPe+j/Rnc967Np/76GHR+G ngIBHZRT6fcUpeEcaP6FlTyNGS+DQ2imj3pvYdV2VuFuuLZ4ng0=
    =MOV6
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Gilbert@21:1/5 to concord@gentoo.org on Mon Jun 27 21:00:02 2022
    On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge <concord@gentoo.org> wrote:
    so looks like we need to combine both methods and do the following:
    - if signing requested without compression - sign in pkg_preinst.
    - if signing requested with compression - sign in src_install


    Why can't we do both in pkg_preinst? I am thinking it would be best if
    we drop the current compression implementation and rework your old code
    to handle both compression and signing since the signing code is more or
    less already complete.

    Signing modules in pkg_preinst seems like a bad idea to me. That means
    you need to copy your private keys around to every host where the
    package might be installed.

    If you sign in src_compile or src_install, you only need private keys
    on the system building your binpkg.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to Kenton Groombridge on Mon Jun 27 21:50:01 2022
    On Mon, 2022-06-27 at 14:35 -0400, Kenton Groombridge wrote:
    On 22/06/26 04:15AM, Georgy Yakovlev wrote:
    On Sun, 2022-06-26 at 03:52 -0700, Georgy Yakovlev wrote:
    On Tue, 2022-06-21 at 14:19 -0400, Kenton Groombridge wrote:
    eee74b9fca1 adds support for module compression, but this
    breaks
    loading
    out of tree modules when module signing is enforced because
    modules
    must
    be signed before they are compressed. Additionally, the
    recommended
    Portage hook[1] no longer works with this change.

    Add module signing support in linux-mod.eclass which more or
    less
    does
    exactly what the aforementioned Portage hook does. If the
    kernel
    configuration has CONFIG_MODULE_SIG_ALL=y, then read the hash
    and
    keys
    from the kernel configuration and call the sign_file tool to
    sign
    the
    module before it is compressed.

    Bug: https://bugs.gentoo.org/show_bug.cgi?id=447352
    Signed-off-by: Kenton Groombridge <concord@gentoo.org>
    ---
     eclass/linux-mod.eclass | 16 ++++++++++++++++
     1 file changed, 16 insertions(+)

    diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
    index b7c13cbf7e7..fd40f6d7c6c 100644
    --- a/eclass/linux-mod.eclass
    +++ b/eclass/linux-mod.eclass
    @@ -712,6 +712,22 @@ linux-mod_src_install() {                 cd "${objdir}" || die "${objdir} does not
    exist"
                    insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir}
     
    +               # check here for CONFIG_MODULE_SIG_ALL and sign
    the
    module being built if enabled.
    +               # modules must be signed before they are compressed.
    +
    +               if linux_chkconfig_present MODULE_SIG_ALL; then
    +                       local module_sig_hash="$(linux_chkconfig_string MODULE_SIG_HASH)" +                       local module_sig_key="$(linux_chkconfig_string MODULE_SIG_KEY)" +                       module_sig_key="${module_sig_key:-
    certs/signing_key.pem}" +                       if [[ "${module_sig_key#pkcs11:}" ==
    "${module_sig_key}" && "${module_sig_key#/}" ==
    "${module_sig_key}"
    ]]; then +                               local key_path="${KERNEL_DIR}/${module_sig_key}" +                       else +                               local key_path="${module_sig_key}" +                       fi +                       local cert_path="${KERNEL_DIR}/certs/signing_key.x509" +                       "${KERNEL_DIR}"/scripts/sign-file
    ${module_sig_hash//\"} ${key_path//\"} ${cert_path} ${modulename}.${KV_OBJ}
    +               fi
    +
                    # check here for CONFIG_MODULE_COMPRESS_<compression
    option> (NONE, GZIP, XZ, ZSTD)
                    # and similarily compress the module being
    built if
    != NONE.
     


    Hi,

    I've spent some time in the past ( circa 2018 ) to get this in,
    but
    gave up due to various reasons, I was not a gentoo dev yet at the
    time.

    I can't see how posted implementation will work tbh.
    portage will strip signature out of the module, unless you
    prevent
    stripping completely or package uses EAPI>=7, and omits stripping
    modules via dostrip -x on the ko object.
    kernel will NOT load module with stripped signature.

    so either you have to sign in pkg_postinst phase, or prevent
    stripping.
    signing in postinst is not ideal, because if breaks recorded file checksums in vdb.

    here's old fork of eclass I made, maybe you can find some helpful
    code
    in there

    https://github.com/gyakovlev/linux-mod.eclass/blob/master/linux-mod.eclass

    old ML discussion we had: https://archives.gentoo.org/gentoo-dev/message/4b15b1c851f379a1f802e2f2895cdfa8

    You will also need a dependency on openssl, since sign-file uses
    it.

    lmk if you need more info, I might remember more details, but for
    now
    that's all I have. I'll try to help get it done, but my
    availability
    is
    spotty due to limited time.

    after reading my old code again and thinking more I think I know
    what's
    going on.
     1. I've actually solved checksum/strip problem by signing in pkg-
    preinst
     2. my method will likely fail with compressed modules.
     3. your method likely works only if modules are compressed -
    because
    portage does not strip those I think.


    This is exactly what I was thinking. I'm pretty sure I wasn't seeing
    the
    problematic signature stripping behavior because I have module
    compression enabled.

    Also good point about the OpenSSL dependency. That's something I
    didn't
    consider.

    so looks like we need to combine both methods and do the following:
     - if signing requested without compression - sign in pkg_preinst.
     - if signing requested with compression - sign in src_install


    Why can't we do both in pkg_preinst? I am thinking it would be best
    if
    we drop the current compression implementation and rework your old
    code
    to handle both compression and signing since the signing code is more
    or
    less already complete.

    i'm not sure if sign-file can sign compressed modules.
    if we let kernel build handle compression - we have to sign prior to compression.
    if we compress modules ourselves then yes, we could sign first indeed.

    but preinst has it's own issues, you've already seen floppym's remark.


    Do I make sense? I still haven't tested it, just guessing as I read
    my
    old bash code.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenton Groombridge@21:1/5 to Mike Gilbert on Mon Jun 27 21:20:01 2022
    On 22/06/27 02:56PM, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge <concord@gentoo.org> wrote:
    so looks like we need to combine both methods and do the following:
    - if signing requested without compression - sign in pkg_preinst.
    - if signing requested with compression - sign in src_install


    Why can't we do both in pkg_preinst? I am thinking it would be best if
    we drop the current compression implementation and rework your old code
    to handle both compression and signing since the signing code is more or less already complete.

    Signing modules in pkg_preinst seems like a bad idea to me. That means
    you need to copy your private keys around to every host where the
    package might be installed.

    If you sign in src_compile or src_install, you only need private keys
    on the system building your binpkg.


    Ah that makes sense. I think the question then is whether or not
    building binpkgs for kernel modules where the target system has its own
    signing keys is something we want to support.

    With that in mind I realize that doing compression in pkg_preinst means
    that target systems can use different compression methods (or no
    compression at all) if desired without much complication.

    -----BEGIN PGP SIGNATURE-----

    iQKTBAABCgB9FiEEP+u3AkfbrORB/inCFt7v5V9Ft54FAmK6AoxfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNG RUJCNzAyNDdEQkFDRTQ0MUZFMjlDMjE2REVFRkU1NUY0NUI3OUUACgkQFt7v5V9F t54ArQ//RZ82UKSrun+ARCxVZV8quL1twgZDCQQLI3ob0PaioiqQAqmLTPhdPeIl fnOH2An5g+0y+WwYhITH7lBlfcRqn29FpdQgEOP1Dw09bKJ5zUwZ+HyohFHmiiWy /9+0kxCes2NfRpQl63ES5DU1wb/Ev/MTHJOgRTYrthmrPkVuHckrQ0hW/VC5V3Wz fPLhIi0vNtm59GRsbqaAgB7Q2nffr6kQufL7/3UNVYVVf1oVGoURZKi1nv1jDrE9 3waENdL5JmhrnuwBtWSaTfitS55Ebq3UBNloNPeVGnxsWLeLYJreM9vrxl3rGhRh aV/CAIh28REtJBmVSjdR+zWlYUnNfQxsrTuc16fGknMHrvTegZlGTG+PtVJ3f69v oMQj4kCX3nKz7l6O8JjS/c+Ast/zr9VWkDt4GdZ03qYKKFHUiVAcwvylFaEyVgMg J9h3O5543xEJ1VWl9y1QNPgFLbgIlKoM39T6BfHqazxVh17x7cvvalIeKDS3BkkG D3ZKsSAbZhNxUKZibaB4rzL4f4IVIOWWLTp9cmViDQGxnDi98WMjiPcRdc6ktLyf ttfl5yIPTAAAsKnHJhF1VBorUzbsh7xGZv4tJVknBtQEwqPlh0cyV3VyuxMCXO7+ zULpK4BkMCDSkbjxKaU5UOI4U46tCRacfERwm8ElB5WG4Hh5lrQ=
    =MBF6
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to Mike Gilbert on Mon Jun 27 21:50:01 2022
    On Mon, 2022-06-27 at 14:56 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge
    <concord@gentoo.org> wrote:
    so looks like we need to combine both methods and do the
    following:
     - if signing requested without compression - sign in
    pkg_preinst.
     - if signing requested with compression - sign in src_install


    Why can't we do both in pkg_preinst? I am thinking it would be best
    if
    we drop the current compression implementation and rework your old
    code
    to handle both compression and signing since the signing code is
    more or
    less already complete.

    Signing modules in pkg_preinst seems like a bad idea to me. That
    means
    you need to copy your private keys around to every host where the
    package might be installed.

    If you sign in src_compile or src_install, you only need private keys
    on the system building your binpkg.


    unfortunately portage will unconditionally strip .ko objects, rendering
    modules unloadable by stripping signature, unless we do dostrip -x
    (requires EAPI7+, which should not be a problem nowadays, but was a
    problem back in 2018), which can be quite unfortunate on debug enabled
    kernels.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Gilbert@21:1/5 to gyakovlev@gentoo.org on Mon Jun 27 22:00:02 2022
    On Mon, Jun 27, 2022 at 3:42 PM Georgy Yakovlev <gyakovlev@gentoo.org> wrote:

    On Mon, 2022-06-27 at 14:56 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge
    <concord@gentoo.org> wrote:
    so looks like we need to combine both methods and do the
    following:
    - if signing requested without compression - sign in
    pkg_preinst.
    - if signing requested with compression - sign in src_install


    Why can't we do both in pkg_preinst? I am thinking it would be best
    if
    we drop the current compression implementation and rework your old
    code
    to handle both compression and signing since the signing code is
    more or
    less already complete.

    Signing modules in pkg_preinst seems like a bad idea to me. That
    means
    you need to copy your private keys around to every host where the
    package might be installed.

    If you sign in src_compile or src_install, you only need private keys
    on the system building your binpkg.


    unfortunately portage will unconditionally strip .ko objects, rendering modules unloadable by stripping signature, unless we do dostrip -x
    (requires EAPI7+, which should not be a problem nowadays, but was a
    problem back in 2018), which can be quite unfortunate on debug enabled kernels.

    Sounds like something to fix/change in Portage. It could probably be
    updated to not strip the signature. However, I would guess the
    signature needs to be updated after the binary is modified in any
    case.

    Or as a workaround you could disable automatic striping via dostrip -x
    and run the proper commands to strip the modules in src_install as
    well.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenton Groombridge@21:1/5 to All on Mon Jun 27 22:10:01 2022
    Why can't we do both in pkg_preinst? I am thinking it would be best
    if
    we drop the current compression implementation and rework your old
    code
    to handle both compression and signing since the signing code is more
    or
    less already complete.

    i'm not sure if sign-file can sign compressed modules.

    sign-file will not error when signing a compressed module, but the
    kernel will not be able to load it.

    if we let kernel build handle compression - we have to sign prior to compression.
    if we compress modules ourselves then yes, we could sign first indeed.

    but preinst has it's own issues, you've already seen floppym's remark.


    -----BEGIN PGP SIGNATURE-----

    iQKTBAABCgB9FiEEP+u3AkfbrORB/inCFt7v5V9Ft54FAmK6DOxfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNG RUJCNzAyNDdEQkFDRTQ0MUZFMjlDMjE2REVFRkU1NUY0NUI3OUUACgkQFt7v5V9F t572IBAAirS7TsdF7GCJYRyDqzXyWDkNsZ7u6OtjEfpC8UdLqhBVQTCRv9joMh3C hl0WW2YDmprL8TWeXGh4r35EheMfokJFxgn6e+wxbfI6QIrSjUz2DbsKMJj/KZNr BmMXPeC/6XymIGXRG83mvvzL2dfdbTCR1YpQDUCQasQ8bvAFedrExXrodINV9Wt8 1KNeQ3oJe0On5MjAN76lpuCHCL9PcaEoplDVXoUdXvNhkaOcVILXBkRhnAPumYT6 y4vVAQ1Vlr7WKr9yah4npt4boeN4WfrhfFSJteGFQJBxmgKz+t0wlHHZ1C/x0ck4 YitQw4qDC6L1wYMMdpgeW3GfCpRpJXz/ljP7khQTU/AwL6ZgzBdYYNwNF5XuofVq DNs8n7X8wVlVjfHmU2sXPRQqb1UIG1F3y1zJwOLxmjF0HxrmBStswVbcU9jlECk6 MY0p30pXPdfWAnCrfptZtWKBj/jFuDWpvH/+6AW3y5Dle3vp+EQyyXkYsuCWF6QC QF3pvw0vXEKw2Mp6mNZ199mVNV2ws7s/nGWo8xefxF3Ss+zn2oHAwI1Ae+mG1Fjr /ozfBLN1B0jaF+YpTSGxCRlx2yfmWhbJFPmds8Ol2yidfuVxO05P7u7H9QtKbNxr ROc7OzqfyPqg/9aCO5bEWyfEt7+YLcHi3O83Rouju5wpJBaEvUg=
    =zMi4
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to Mike Gilbert on Mon Jun 27 23:20:01 2022
    On Mon, 2022-06-27 at 15:49 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 3:42 PM Georgy Yakovlev
    <gyakovlev@gentoo.org> wrote:

    On Mon, 2022-06-27 at 14:56 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge
    <concord@gentoo.org> wrote:
    so looks like we need to combine both methods and do the
    following:
     - if signing requested without compression - sign in
    pkg_preinst.
     - if signing requested with compression - sign in
    src_install


    Why can't we do both in pkg_preinst? I am thinking it would be
    best
    if
    we drop the current compression implementation and rework your
    old
    code
    to handle both compression and signing since the signing code
    is
    more or
    less already complete.

    Signing modules in pkg_preinst seems like a bad idea to me. That
    means
    you need to copy your private keys around to every host where the
    package might be installed.

    If you sign in src_compile or src_install, you only need private
    keys
    on the system building your binpkg.


    unfortunately portage will unconditionally strip .ko objects,
    rendering
    modules unloadable by stripping signature,  unless we do dostrip -x (requires EAPI7+, which should not be a problem nowadays, but was a
    problem back in 2018), which can be quite unfortunate on debug
    enabled
    kernels.

    Sounds like something to fix/change in Portage. It could probably be
    updated to not strip the signature. However, I would guess the
    signature needs to be updated after the binary is modified in any
    case.

    Or as a workaround you could disable automatic striping via dostrip -
    x
    and run the proper commands to strip the modules in src_install as
    well.

    I think even strip itself does not have proper options not to break
    module. Several years back it was the case, basically one has to strip
    first, sign second, otherwise module will be unloadable.

    "Signed modules are BRITTLE as the signature is outside of the defined
    ELF container. Thus they MAY NOT be stripped once the signature is
    computed and attached. Note the entire module is the signed payload,
    including any and all debug information present at the time of
    signing."

    https://www.kernel.org/doc/html/v4.15/admin-guide/module-signing.html#signed-modules-and-stripping

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to Kenton Groombridge on Mon Jun 27 23:30:01 2022
    On Mon, 2022-06-27 at 16:02 -0400, Kenton Groombridge wrote:
    Why can't we do both in pkg_preinst? I am thinking it would be
    best
    if
    we drop the current compression implementation and rework your
    old
    code
    to handle both compression and signing since the signing code is
    more
    or
    less already complete.

    i'm not sure if sign-file can sign compressed modules.

    sign-file will not error when signing a compressed module, but the
    kernel will not be able to load it.

    so we pretty much HAVE to strip->sign->compress, strictly in this
    order. nothing else will work.


    if we let kernel build handle compression - we have to sign prior
    to
    compression.
    if we compress modules ourselves then yes, we could sign first
    indeed.

    but preinst has it's own issues, you've already seen floppym's
    remark.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Gilbert@21:1/5 to gyakovlev@gentoo.org on Tue Jun 28 00:00:01 2022
    On Mon, Jun 27, 2022 at 5:11 PM Georgy Yakovlev <gyakovlev@gentoo.org> wrote:

    On Mon, 2022-06-27 at 15:49 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 3:42 PM Georgy Yakovlev
    <gyakovlev@gentoo.org> wrote:

    On Mon, 2022-06-27 at 14:56 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge
    <concord@gentoo.org> wrote:
    so looks like we need to combine both methods and do the
    following:
    - if signing requested without compression - sign in
    pkg_preinst.
    - if signing requested with compression - sign in
    src_install


    Why can't we do both in pkg_preinst? I am thinking it would be
    best
    if
    we drop the current compression implementation and rework your
    old
    code
    to handle both compression and signing since the signing code
    is
    more or
    less already complete.

    Signing modules in pkg_preinst seems like a bad idea to me. That
    means
    you need to copy your private keys around to every host where the package might be installed.

    If you sign in src_compile or src_install, you only need private
    keys
    on the system building your binpkg.


    unfortunately portage will unconditionally strip .ko objects,
    rendering
    modules unloadable by stripping signature, unless we do dostrip -x (requires EAPI7+, which should not be a problem nowadays, but was a problem back in 2018), which can be quite unfortunate on debug
    enabled
    kernels.

    Sounds like something to fix/change in Portage. It could probably be updated to not strip the signature. However, I would guess the
    signature needs to be updated after the binary is modified in any
    case.

    Or as a workaround you could disable automatic striping via dostrip -
    x
    and run the proper commands to strip the modules in src_install as
    well.

    I think even strip itself does not have proper options not to break
    module. Several years back it was the case, basically one has to strip
    first, sign second, otherwise module will be unloadable.

    "Signed modules are BRITTLE as the signature is outside of the defined
    ELF container. Thus they MAY NOT be stripped once the signature is
    computed and attached. Note the entire module is the signed payload, including any and all debug information present at the time of
    signing."

    https://www.kernel.org/doc/html/v4.15/admin-guide/module-signing.html#signed-modules-and-stripping


    In that case, I think the only viable way to make this work is to
    disable automatic stripping and handle stripping via custom code in
    the ebuild/eclass.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to Mike Gilbert on Tue Jun 28 01:50:01 2022
    On Mon, 2022-06-27 at 17:50 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 5:11 PM Georgy Yakovlev
    <gyakovlev@gentoo.org> wrote:

    On Mon, 2022-06-27 at 15:49 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 3:42 PM Georgy Yakovlev
    <gyakovlev@gentoo.org> wrote:

    On Mon, 2022-06-27 at 14:56 -0400, Mike Gilbert wrote:
    On Mon, Jun 27, 2022 at 2:35 PM Kenton Groombridge <concord@gentoo.org> wrote:
    so looks like we need to combine both methods and do the following:
     - if signing requested without compression - sign in pkg_preinst.
     - if signing requested with compression - sign in
    src_install


    Why can't we do both in pkg_preinst? I am thinking it would
    be
    best
    if
    we drop the current compression implementation and rework
    your
    old
    code
    to handle both compression and signing since the signing
    code
    is
    more or
    less already complete.

    Signing modules in pkg_preinst seems like a bad idea to me.
    That
    means
    you need to copy your private keys around to every host where
    the
    package might be installed.

    If you sign in src_compile or src_install, you only need
    private
    keys
    on the system building your binpkg.


    unfortunately portage will unconditionally strip .ko objects,
    rendering
    modules unloadable by stripping signature,  unless we do
    dostrip -x
    (requires EAPI7+, which should not be a problem nowadays, but
    was a
    problem back in 2018), which can be quite unfortunate on debug
    enabled
    kernels.

    Sounds like something to fix/change in Portage. It could probably
    be
    updated to not strip the signature. However, I would guess the
    signature needs to be updated after the binary is modified in any
    case.

    Or as a workaround you could disable automatic striping via
    dostrip -
    x
    and run the proper commands to strip the modules in src_install
    as
    well.

    I think even strip itself does not have proper options not to break
    module. Several years back it was the case, basically one has to
    strip
    first, sign second, otherwise module will be unloadable.

    "Signed modules are BRITTLE as the signature is outside of the
    defined
    ELF container. Thus they MAY NOT be stripped once the signature is
    computed and attached. Note the entire module is the signed
    payload,
    including any and all debug information present at the time of
    signing."

    https://www.kernel.org/doc/html/v4.15/admin-guide/module-signing.html#signed-modules-and-stripping


    In that case, I think the only viable way to make this work is to
    disable automatic stripping and handle stripping via custom code in
    the ebuild/eclass.

    might work indeed if we do something like (pseudo-bash)

    if [[ module_sign == yes ]]; then
    dostrip -x /lib/modules # to stop portage stripping .ko objects
    manual-strip-respecting-features-nostrip -r /lib/modules
    sign-all-modules -r /lib/modules
    fi
    [[ compress_modules == yes ]] && compress-modules -r /lib/modules


    this will equire eapi-bumping couple of packages https://qa-reports.gentoo.org/output/eapi-per-eclass/linux-mod.eclass/6.txt
    and restricting linux-mod.eclass to eapi7 or later.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Georgy Yakovlev@21:1/5 to All on Tue Jul 5 21:10:01 2022
    ...snip

    In that case, I think the only viable way to make this work is to
    disable automatic stripping and handle stripping via custom code in
    the ebuild/eclass.

    might work indeed if we do something like (pseudo-bash)

    if [[ module_sign == yes ]]; then
        dostrip -x /lib/modules # to stop portage stripping .ko objects
        manual-strip-respecting-features-nostrip -r /lib/modules
        sign-all-modules -r /lib/modules
    fi
    [[ compress_modules == yes ]] && compress-modules -r /lib/modules


    this will equire eapi-bumping couple of packages https://qa-reports.gentoo.org/output/eapi-per-eclass/linux-mod.eclass/6.txt and restricting linux-mod.eclass to eapi7 or later.



    started playing with my old code and got blocked right away:

    looks like dostrip just creates a list of files/directories to strip
    and processed at the very end of install phase.

    so skipping strip and doing manual one might be problematic.
    internally portage uses estrip https://github.com/gentoo/portage/blob/master/bin/estrip
    which contains quite a lot of logic and code and I don't think
    partially re-implementing this in eclass code is appropriate.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenton Groombridge@21:1/5 to Georgy Yakovlev on Tue Jul 5 22:00:01 2022
    On 22/07/05 12:02PM, Georgy Yakovlev wrote:
    started playing with my old code and got blocked right away:

    looks like dostrip just creates a list of files/directories to strip
    and processed at the very end of install phase.

    so skipping strip and doing manual one might be problematic.
    internally portage uses estrip https://github.com/gentoo/portage/blob/master/bin/estrip
    which contains quite a lot of logic and code and I don't think
    partially re-implementing this in eclass code is appropriate.


    I agree I don't think it's appropriate. Would it make sense to be able
    to provide an extra argument to dostrip in order to strip an object
    *now* using the existing logic (and skip later stripping)? i.e.:

    dostrip --now my_module.ko

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Gilbert@21:1/5 to gyakovlev@gentoo.org on Tue Jul 5 22:20:01 2022
    On Tue, Jul 5, 2022 at 3:02 PM Georgy Yakovlev <gyakovlev@gentoo.org> wrote:

    ...snip

    In that case, I think the only viable way to make this work is to
    disable automatic stripping and handle stripping via custom code in
    the ebuild/eclass.

    might work indeed if we do something like (pseudo-bash)

    if [[ module_sign == yes ]]; then
    dostrip -x /lib/modules # to stop portage stripping .ko objects
    manual-strip-respecting-features-nostrip -r /lib/modules
    sign-all-modules -r /lib/modules
    fi
    [[ compress_modules == yes ]] && compress-modules -r /lib/modules


    this will equire eapi-bumping couple of packages https://qa-reports.gentoo.org/output/eapi-per-eclass/linux-mod.eclass/6.txt and restricting linux-mod.eclass to eapi7 or later.



    started playing with my old code and got blocked right away:

    looks like dostrip just creates a list of files/directories to strip
    and processed at the very end of install phase.

    so skipping strip and doing manual one might be problematic.
    internally portage uses estrip https://github.com/gentoo/portage/blob/master/bin/estrip
    which contains quite a lot of logic and code and I don't think
    partially re-implementing this in eclass code is appropriate.


    Looking at the kernel build system, it looks like modules don't get
    stripped by default anyway: you have to explicitly pass
    INSTALL_MOD_STRIP=1 to make modules_install.

    I don't think it would be a major problem to just disable stripping
    entirely for out-of-tree modules when module signing is enabled.

    Alternatively, forget about trying to reimplement estrip and just
    strip the files by calling ${STRIP} --strip-debug, as is done in scripts/Makefile.modinst in the kernel sources. That will conflict
    with FEATURES=splitdebug, but I doubt that's very useful for kernel
    developers anyway.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)