Author Topic: Compile a Linux kernel module  (Read 2463 times)

0 Members and 1 Guest are viewing this topic.

Offline PKTKS

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: Compile a Linux kernel module
« Reply #25 on: July 27, 2022, 05:25:11 pm »
Unless you have some very good reasons to use signed stuff...

Keep your life simple.
Get a clean stock tree
Compile it clean and all integrated...
DIFFERENT VERSION from current running... (install clean)

Add it to the boot list.
Avoid grub mess

Paul
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 4735
  • Country: fi
    • My home page and email address
Re: Compile a Linux kernel module
« Reply #26 on: July 27, 2022, 06:27:11 pm »
    sudo pesign -i /boot/vmlinuz-5.15.0-41-generic -o /boot/vmlinuz-5.15.0-41-unsigned -r -u 0
    sudo update-grub
I have a bad feeling about this (won't boot any more), but I'll try.  ;D
It adds a new boot entry.  It does not modify the existing kernel, it creates a copy of it, and tells the update mechanism to add it to your grub menus.  It will not be auto-booted, I think, but you should be able to deliberately select it.

If it were to be that simple to disable the signature checking, than what would stop a malware to do the same?
The idea is that the signature checking chain starts at the EFI BIOS.  Before it runs your bootloader (Grub), it checks its signature.  Then, Grub is supposed to verify the kernel signature before booting it.

I don't like the model myself; I do not run signed kernels.  And I'm obviously hoping here that Grub will let you choose to boot an unsigned kernel; it is just not supposed to auto-boot an unsigned kernel, or indeed the signing scheme is basically irrelevant.  I consider it a MSism, and Canonical marketing, myself.

My security model is such that if someone gets unfettered physical access to my computer, or a root access on it, everything on it must be considered compromised.  After all, if my processes get infected with malware, they can monitor my keypresses without even gaining root access, and relay that to a remote server.  Gaining root access doesn't make my data somehow "even more compromised", it just means the malware is harder to get rid of.
 
The following users thanked this post: RoGeorge

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 4762
  • Country: ro
Re: Compile a Linux kernel module
« Reply #27 on: July 27, 2022, 06:34:40 pm »
Unless you have some very good reasons to use signed stuff...

Keep your life simple.
Get a clean stock tree
Compile it clean and all integrated...
DIFFERENT VERSION from current running... (install clean)

Add it to the boot list.
Avoid grub mess

Paul

I certainly did not ask for signed modules, and I didn't know they were so until yesterday, when I tried to install a modified one.  From now on I'll experiment on another clean install, and let this OS as it is for now.



    sudo pesign -i /boot/vmlinuz-5.15.0-41-generic -o /boot/vmlinuz-5.15.0-41-unsigned -r -u 0
    sudo update-grub

It did reboot, but I didn't see any new grub entry to boot from, same name same version.  Not sure if grub-update was successful:
Code: [Select]
        sudo apt install pesign
        man pesign             
        sudo pesign -i /boot/vmlinuz-5.15.0-41-generic -o /boot/vmlinuz-5.15.0-41-unsigned -r -u 0
        sudo update-grub
            Sourcing file `/etc/default/grub'
            Sourcing file `/etc/default/grub.d/init-select.cfg'
            Generating grub configuration file ...
            Found linux image: vmlinuz-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx
            Found initrd image: initrd.img-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx
            Found linux image: vmlinuz-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx
            Found initrd image: initrd.img-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
            Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
            Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
            dpkg: warning: version 'ed/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
            dpkg: warning: version 'ed/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
            Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
            Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
            dpkg: warning: version 'ed_and_clean_wine/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
            dpkg: warning: version 'ed_and_clean_wine/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
            Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
            Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
            dpkg: warning: version 'ed_wine5_installs/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
            dpkg: warning: version 'ed_wine5_installs/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
            Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
            Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
            dpkg: warning: version 'designer_lxi-tools/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
            dpkg: warning: version 'designer_lxi-tools/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_added_Qt5-designer_lxi-tools
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_added_Qt5-designer_lxi-tools
            Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_added_Qt5-designer_lxi-tools
            Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_added_Qt5-designer_lxi-tools
            dpkg: warning: version 'Hot-Pursuit-attempt/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
            dpkg: warning: version 'Hot-Pursuit-attempt/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_tmp_before_NFS-Hot-Pursuit-attempt
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_tmp_before_NFS-Hot-Pursuit-attempt
            Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_tmp_before_NFS-Hot-Pursuit-attempt
            Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_tmp_before_NFS-Hot-Pursuit-attempt
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_with_games
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_with_games
            Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_with_games
            Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_with_games
            Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_jc7jse
            Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_jc7jse

...
...

            Found initrd image: initrd.img-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_8br34k
            Found linux image: vmlinuz-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_8br34k
            Found initrd image: initrd.img-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_8br34k
            Found linux image: vmlinuz-5.15.0-41-unsigned in rpool/ROOT/ubuntu_ifipuu
            Warning: Couldn't find any valid initrd for dataset rpool/ROOT/ubuntu_ifipuu.
            Found linux image: vmlinuz-5.15.0-41-generic in rpool/ROOT/ubuntu_ifipuu
            Found initrd image: initrd.img-5.15.0-41-generic in rpool/ROOT/ubuntu_ifipuu
            Found linux image: vmlinuz-5.13.0-52-generic in rpool/ROOT/ubuntu_ifipuu
            Found initrd image: initrd.img-5.13.0-52-generic in rpool/ROOT/ubuntu_ifipuu
            cannot open 'bpool/BOOT/default': dataset does not exist
            Warning: didn't find any valid initrd or kernel.
            device-mapper: reload ioctl on osprober-linux-sda4  failed: Device or resource busy
            Command failed.
            Adding boot menu entry for UEFI Firmware Settings
            done


Near the end it sais "Command failed."  :-\

I do see a "/boot/vmlinuz-5.15.0-41-unsigned" file near the "/boot/System.map-5.15.0-41-generic" file, but there was no "unsigned" word anywhere in the grub menus.  I guess it booted the same signed kernel, uname is "5.15.0-41-generic".

By the cat /proc/cmdline at the end, it seems that it's running the old signed one:
Code: [Select]
        sudo pesign -S -i /boot/vmlinuz-5.15.0-41-generic
            ---------------------------------------------
            certificate address is 0x7f6003a3f368
            Content was not encrypted.
            Content is detached; signature cannot be verified.
            The signer's common name is Canonical Ltd. Secure Boot Signing (2017)
            No signer email address.
            Signing time: Wed Jun 29, 2022
            There were certs or crls included.
            ---------------------------------------------
        sudo pesign -S -i /boot/vmlinuz-5.15.0-41-unsigned
            No signatures found.
           
        cat /proc/cmdline
            BOOT_IMAGE=/BOOT/ubuntu_ifipuu@/vmlinuz-5.15.0-41-generic root=ZFS=rpool/ROOT/ubuntu_ifipuu ro quiet splash vt.handoff=1
« Last Edit: July 27, 2022, 06:51:14 pm by RoGeorge »
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 4735
  • Country: fi
    • My home page and email address
Re: Compile a Linux kernel module
« Reply #28 on: July 27, 2022, 07:50:18 pm »
I certainly did not ask for signed modules, and I didn't know they were so until yesterday, when I tried to install a modified one.  From now on I'll experiment on another clean install, and let this OS as it is for now.
What a wart, when a plain sudo update-grub reports errors...
If I were you, I'd test Mint, as a direct replacement for that Ubuntu installation.

(If you want snapshots et cetera but a mainline FS, you could use LVM2 (for snapshotting), and on top of it, an ext4 (leaving a gigabyte or so for overprovisioning and snapshot divergence from current).)

Code: [Select]
            Found linux image: vmlinuz-5.15.0-41-unsigned in rpool/ROOT/ubuntu_ifipuu
            Warning: Couldn't find any valid initrd for dataset rpool/ROOT/ubuntu_ifipuu.
            Found linux image: vmlinuz-5.15.0-41-generic in rpool/ROOT/ubuntu_ifipuu
            Found initrd image: initrd.img-5.15.0-41-generic in rpool/ROOT/ubuntu_ifipuu
Ah, yours wants a matching initrd as well.  Copying initrd.img-5.15.0-41-generic to initrd.img-5.15.0-41-unsigned in rpool/ROOT/ubuntu/ifipuu, and then rerunning sudo update-grub, should make the boot option show up.

You might also consider removing some of your old kernel images, as you seem to have tons and tons of them.

Note that you should be able to boot the modified kernel using kernel command line
Code: [Select]
BOOT_IMAGE=/BOOT/ubuntu_ifipuu@/vmlinuz-5.15.0-41-unsigned root=ZFS=rpool/ROOT/ubuntu_ifipuu ro quiet splash vt.handoff=1in Grub.
 
The following users thanked this post: RoGeorge

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 4762
  • Country: ro
Re: Compile a Linux kernel module
« Reply #29 on: July 27, 2022, 09:55:45 pm »
I certainly did not ask for signed modules, and I didn't know they were so until yesterday, when I tried to install a modified one.  From now on I'll experiment on another clean install, and let this OS as it is for now.
What a wart, when a plain sudo update-grub reports errors...

I didn't meant to not try to finish this exercise, that thought was a way of agreeing with PKTKS about leaving Ubuntu for good at the next install, I would probably not upgrade it from 20.04 LTS to 22.04 LTS, but rather move to something like Devuan, or maybe move to FreeBSD entirely, the most unclutter OS I've seen so far.

Back to the unsigned image, "rpool/ROOT/ubuntu_ifipuu" is a ZFS dataset, ROOT a ZFS volume, and the ones like "rpool/ROOT/ubuntu_ifipuu@a_snapshot_name" are ZFS snapshots, and rpool is the ZFS pool (I might be mixing the ZFS terminology).

While in a normal ZFS one can handle these manually, Ubuntu added another layer, Zsys, that automates snapshots and restores, and adds a more commands on top of standard ZFS, and integrated Zsys with ZFS, systemd and GRUB.  Also, Zsys added a few more proprietary concepts apart from the ZFS ones.

Zsys does automated snaphots from time to time, or when it detects am OS change, like e.g. an install.  I don't know how often Zsys interferes, or how to disable it.  Zsys is made by Canonical, it is still experimental and undocumented.  I do not want to manually handle the ZFS in Ubuntu with Zsys.

Anyway the only place where I can see "vmlinuz-5.15.0-41-unsigned" (or the -original) is "/boot" (without manually handling datasets or snapshots) so just to be sure, I did a copy for any other "generic" as "unsigned", like this:
Code: [Select]
sudo cp /boot/initrd.img-5.15.0-41-generic /boot/initrd.img-5.15.0-41-unsigned
sudo cp /boot/System.map-5.15.0-41-generic /boot/System.map-5.15.0-41-unsigned
sudo cp /boot/config-5.15.0-41-generic /boot/config-5.15.0-41-unsigned

ls -l /boot/*5.15.0-41*
    -rw-r--r-- 1 root root    262026 Jun 24 16:04 /boot/config-5.15.0-41-generic
    -rw-r--r-- 1 root root    262026 Jul 27 23:46 /boot/config-5.15.0-41-unsigned
    -rw-r--r-- 1 root root 170835870 Jul 13 22:37 /boot/initrd.img-5.15.0-41-generic
    -rw-r--r-- 1 root root 170835870 Jul 27 23:43 /boot/initrd.img-5.15.0-41-unsigned
    -rw------- 1 root root   6218651 Jun 24 16:04 /boot/System.map-5.15.0-41-generic
    -rw------- 1 root root   6218651 Jul 27 23:44 /boot/System.map-5.15.0-41-unsigned
    -rw------- 1 root root  11000544 Jun 24 14:37 /boot/vmlinuz-5.15.0-41-generic
    -rw------- 1 root root  10998624 Jul 27 20:22 /boot/vmlinuz-5.15.0-41-unsigned


Code: [Select]
sudo update-grub             
    Sourcing file `/etc/default/grub'
    Sourcing file `/etc/default/grub.d/init-select.cfg'
    Generating grub configuration file ...
    Found linux image: vmlinuz-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx
    Found initrd image: initrd.img-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx
    Found linux image: vmlinuz-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx
    Found initrd image: initrd.img-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx
    Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
    Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
    Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
    Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_wo_AutoKey_for_F12_Timestamp
    dpkg: warning: version 'ed/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
    dpkg: warning: version 'ed/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
    Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
    Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
    Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
    Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@full_OS_config-ed
    dpkg: warning: version 'ed_and_clean_wine/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
    dpkg: warning: version 'ed_and_clean_wine/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
    Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
    Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
    Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
    Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_and_clean_wine
    dpkg: warning: version 'ed_wine5_installs/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
    dpkg: warning: version 'ed_wine5_installs/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
    Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
    Found initrd image: initrd.img-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
    Found linux image: vmlinuz-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
    Found initrd image: initrd.img-5.11.0-27-generic in rpool/ROOT/ubuntu_eqazcx@OS_config-ed_wine5_installs
    dpkg: warning: version 'designer_lxi-tools/vmlinuz-5.11.0-41-generic' has bad syntax: version number does not start with digit
    dpkg: warning: version 'designer_lxi-tools/vmlinuz-5.11.0-27-generic' has bad syntax: version number does not start with digit
    Found linux image: vmlinuz-5.11.0-41-generic in rpool/ROOT/ubuntu_eqazcx@OS_added_Qt5-designer_lxi-tools
...
...
    Found linux image: vmlinuz-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_wb5pqa
    Found initrd image: initrd.img-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_wb5pqa
    Found linux image: vmlinuz-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_wb5pqa
    Found initrd image: initrd.img-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_wb5pqa
    Found linux image: vmlinuz-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_8br34k
    Found initrd image: initrd.img-5.15.0-30-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_8br34k
    Found linux image: vmlinuz-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_8br34k
    Found initrd image: initrd.img-5.13.0-41-generic in rpool/ROOT/ubuntu_eqazcx@autozsys_8br34k
    Found linux image: vmlinuz-5.15.0-41-unsigned in rpool/ROOT/ubuntu_ifipuu
    Found initrd image: initrd.img-5.15.0-41-unsigned in rpool/ROOT/ubuntu_ifipuu
    Found linux image: vmlinuz-5.15.0-41-generic in rpool/ROOT/ubuntu_ifipuu
    Found initrd image: initrd.img-5.15.0-41-generic in rpool/ROOT/ubuntu_ifipuu
    Found linux image: vmlinuz-5.13.0-52-generic in rpool/ROOT/ubuntu_ifipuu
    Found initrd image: initrd.img-5.13.0-52-generic in rpool/ROOT/ubuntu_ifipuu
    cannot open 'bpool/BOOT/default': dataset does not exist
    Warning: didn't find any valid initrd or kernel.
    device-mapper: reload ioctl on osprober-linux-sda4  failed: Device or resource busy
    Command failed.
    Adding boot menu entry for UEFI Firmware Settings
    done
reboot



And it worked, it worked!   :scared:
Code: [Select]
cat /proc/cmdline
    BOOT_IMAGE=/BOOT/ubuntu_ifipuu@/vmlinuz-5.15.0-41-unsigned root=ZFS=rpool/ROOT/ubuntu_ifipuu ro quiet splash
uname -r
    5.15.0-41-generic


Thank you!
 ^-^

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 4735
  • Country: fi
    • My home page and email address
Re: Compile a Linux kernel module
« Reply #30 on: July 28, 2022, 07:30:52 am »
I certainly did not ask for signed modules, and I didn't know they were so until yesterday, when I tried to install a modified one.  From now on I'll experiment on another clean install, and let this OS as it is for now.
What a wart, when a plain sudo update-grub reports errors...
I didn't meant to not try to finish this exercise, that thought was a way of agreeing with PKTKS about leaving Ubuntu for good at the next install, I would probably not upgrade it from 20.04 LTS to 22.04 LTS, but rather move to something like Devuan, or maybe move to FreeBSD entirely, the most unclutter OS I've seen so far.
Oh, no worries either way.  By a wart, I was definitely referring to Ubuntu 20.04 LTS.  I do not like the direction Canonical is taking it, what with the signing and 'snap' packaging.

I much prefer Debian/Devuan.  The reason I'm running Mint on this laptop has to do with helping other people, and is not "optimal"; I'm just more lax about these things than say PKTKS.

Anyway the only place where I can see "vmlinuz-5.15.0-41-unsigned" (or the -original) is "/boot" (without manually handling datasets or snapshots) so just to be sure, I did a copy for any other "generic" as "unsigned", like this:
Code: [Select]
sudo cp /boot/initrd.img-5.15.0-41-generic /boot/initrd.img-5.15.0-41-unsigned
sudo cp /boot/System.map-5.15.0-41-generic /boot/System.map-5.15.0-41-unsigned
sudo cp /boot/config-5.15.0-41-generic /boot/config-5.15.0-41-unsigned
...
sudo update-grub
Yup, that's exactly it.

And it worked, it worked!   :scared:
Well, it is supposed to.  You added a new kernel (albeit the same as an old one, just unsigned), its symbol map and configuration, and most importantly, its initial ramdisk, and then used the update-grub helper to regenerate the grub boot menu for all existing kernels.  If you take a look, you'll find /boot/grub/grub.cfg (and /boot/grub/grubenv) got updated.  Instead of editing it directly, we use /etc/grub.d/, /etc/default/grub, /etc/default/grub.d/ and so on and let update-grub piece a working one together for us.

I knew that ZFS stuff adds some wonky stuff to the config, but not exactly what; I haven't used ZFS at all.
 
The following users thanked this post: RoGeorge

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 4762
  • Country: ro
Re: Compile a Linux kernel module
« Reply #31 on: July 29, 2022, 11:00:46 am »
Meanwhile, found there is also an unsigned package for the linux kernel:
Code: [Select]
apt list *-5.15.0-41-*
            Listing... Done
            linux-buildinfo-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1 amd64
            linux-cloud-tools-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1 amd64
            linux-headers-5.15.0-41-generic/focal-updates,focal-security,now 5.15.0-41.44~20.04.1 amd64 [installed]
            linux-image-5.15.0-41-generic/focal-updates,focal-security,now 5.15.0-41.44~20.04.1 amd64 [installed,automatic]
            linux-image-unsigned-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1 amd64
            linux-modules-5.15.0-41-generic/focal-updates,focal-security,now 5.15.0-41.44~20.04.1 amd64 [installed,automatic]
            linux-modules-extra-5.15.0-41-generic/focal-updates,focal-security,now 5.15.0-41.44~20.04.1 amd64 [installed,automatic]
            linux-modules-iwlwifi-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1 amd64
            linux-modules-nvidia-418-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-modules-nvidia-450-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-modules-nvidia-470-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-modules-nvidia-470-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-modules-nvidia-510-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-modules-nvidia-510-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-modules-nvidia-515-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-modules-nvidia-515-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-418-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-450-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-470-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-470-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-510-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-510-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-515-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-objects-nvidia-515-server-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-signatures-nvidia-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1+1 amd64
            linux-tools-5.15.0-41-generic/focal-updates,focal-security 5.15.0-41.44~20.04.1 amd64

and "apt source linux-image-unsigned-5.15.0-41-generic" will select by itself "linux-hwe-5.15-5.15.0" instead of "linux-image-unsigned-5.15.0-41-generic".  Same thing, a whole kernel build was needed to generate the "Module.symvers" file, without which, modules alone won't compile.

I still don't know who keeps busy the .ko I want to remove in order to replace it with the newly compiled, but anyway, the Quirk I was trying to add it's not needed.

Seems like only a few CA0132 sound card need those QUIRK customisations, most other CA0132 based cards (CA0132 is in fact a CODEC, the generic name for the chipset is Creative Sound Core3D, and includes the Creative hardware DSP cores (has 4 DSP cores, with an architecture descendants from the emu10k and emu10k2 - aka Creative SB Live and Audigy - Creative bought EMU, the ones that designed the first emu10k chips) and an 8051 core that handles the audio CODEC, the DSP engines and the rest of the hardware found inside of that Creative Sound Core3D chipset).



Found some very helpful notes about HDA https://android.googlesource.com/kernel/msm.git/+/android-msm-bullhead-3.10-n-preview-1/Documentation/sound/alsa/HD-Audio.txt from which I realized I could change the Vendor ID of my soundcard live, if it were to check for the already existing QUIRK definitions in the unmodified CA0132 driver.

There is a file tree with most of the properties I was wanting to change, for example (for Card 1 Device 0):
/sys/class/sound/hwC1D0/ there is a writable file named "/sys/class/sound/hwC1D0/vendor_id" with the current text "0x11020011", and another write only file called "reconfigure".  To activate the QUIRK r3di specific to some "Recon3Di" cards defined inside

To change the vendor ID to make active quirks like these from the driver:

Code: [Select]
diff -c ./patch_ca0132.c sound/pci/hda/patch_ca0132.c
            *** ./patch_ca0132.c
            --- sound/pci/hda/patch_ca0132.c        2022-07-27 16:59:02.162469113 +0300
            ***************
            *** 1304,1309 ****
            --- 1304,1310 ----
                    SND_PCI_QUIRK(0x1102, 0x0033, "Sound Blaster ZxR", QUIRK_SBZ),
                    SND_PCI_QUIRK(0x1458, 0xA016, "Recon3Di", QUIRK_R3DI),
                    SND_PCI_QUIRK(0x1458, 0xA026, "Gigabyte G1.Sniper Z97", QUIRK_R3DI),
            +       SND_PCI_QUIRK(0x1102, 0x0011, "ASRock Fatal1ty Z97 Professional", QUIRK_R3DI),
                    SND_PCI_QUIRK(0x1458, 0xA036, "Gigabyte GA-Z170X-Gaming 7", QUIRK_R3DI),
                    SND_PCI_QUIRK(0x3842, 0x1038, "EVGA X99 Classified", QUIRK_R3DI),
                    SND_PCI_QUIRK(0x1102, 0x0013, "Recon3D", QUIRK_R3D),

it is enough to rewrite the content of the "/sys/class/sound/hwC1D0/vendor_id" file, then trigger a reconfigure, like this:
Code: [Select]
        # temporary stop PulseAudio, or else triggering a reconfigure will I/O error as busy
        systemctl --user stop pulseaudio.{socket,service}

        # pretend the current onboard soundcard in "ASRock Fatal1ty Z97 Professional" motherbords,
        #        with vendor ID 0x11020011 would be a 0x1458A026, "Gigabyte G1.Sniper Z97", r3di
        cat /sys/class/sound/hwC1D0/vendor_id
        #        0x11020011  <--  this vendor ID is for "ASRock Fatal1ty Z97 Professional" motherbords

        sudo sh': sudo sh -c "echo 0x1458A026 > /sys/class/sound/hwC1D0/vendor_id"
        sudo sh': sudo sh -c "echo 1 > /sys/class/sound/hwC1D0/reconfig"

        systemctl --user start pulseaudio.{socket,service}

Either with module recompile or with live vendor ID faking, none of the existing quirks worked for my card.   ;D

However, if I let the vendor ID unchanged, and only trigger a reconfigure without changing any settings at all, the "Line-in" appears as an option in any PulseAudio related GUI.  Without manually triggering a reconfigure, there is only "Microphone" and no option to change to "Line-in", as seen in the pics, and it does the same even when booting from a live Ubuntu pendrive.  :-//

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 4735
  • Country: fi
    • My home page and email address
Re: Compile a Linux kernel module
« Reply #32 on: July 29, 2022, 01:57:03 pm »
Are you aware of github.com/Conmanx360/ca0132-tools (Connor McAdams)?

I am more and more convinced that you'd be better off tearing apart a suitable USB audio capture device, or use an USB microcontroller with a suitable ADC input and analog frontend...
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 4762
  • Country: ro
Re: Compile a Linux kernel module
« Reply #33 on: July 29, 2022, 04:59:28 pm »
Yes, forgot to mention that resource, thank you for posting it.

From yesterday's checks, it looks like all his findings are already upstream in the patch_ca0132.c file.  I've diff-ed against the latest kernel from Linus' github repo and nothing has changed in years.  Found the tools, too.  Those are gold in case I've ever want to sniff the messages between the Windows driver and the Windows OS, but I don't think I'll go there.

I don't need to change anything to my soundcard for its daily use, and if it were to really want to record in 24 bits then I'll just install Windows and use the proprietary Creative drivers for Windows.

Though recording in 24 bits for this soundcard would be kind of futile, because the card is too noisy, especially at high sampling rates.  This is the typical noise floor (the picture is from another topic, please consider only the noise floor and ignore the signal):



All this dive into the Linux sound was mostly for learning.  So far it was very interesting for me, I've learn about PulseAudio/Jack/PipeWire + ALSA/OSS + Intel HDA + Linux modules/drivers + recompile own changes and/or add custom kernels to GRUB + many other thing.
 



As a matter of fact, it happens that only seconds ago I was playing with an algorithm specific to emu10k family of DSP's, from the exact github repo you just mentioned.  ;D

The algorithm is bamboozling looking at the C code implementation.  It computes logarithms or exponentials.  :o

It is suppose to be DSP stile, which in hardware is usually implement with a hardware multiplier and an accumulator,  so I'm trying to figure out the hardware that would correspond to the algorithm, or at least a block representation with Z-1 steps, like in filters.

I compiled the C emulation (since it happened that I'm in FreeBSD now, there is no <linux/types.h> so I've blindly used #include <infiniband/types.h>, not sure if this ruins it, I hope not, but at least it compiles).

Made a script to run it for a range of inputs, then pasted the data in a spreadsheet to make a chart.  Well, the shape does look like either as an exponential decay or as a logarithmic increase (looks exactly like the response of an RC circuit, if it were to think in terms passive resistors/capacitors filters).

If anybody curious for a code puzzle, this is the C code for it:
Code: [Select]
/*
 * This file was taken from the emu10k1 archives. I've cleaned up the code a
 * bit and fixed some of the bugs, but other than that it's unchanged.
 */
/*  By: Daniel Bertrand
    Date: Nov 6th, 2000

    Description: A software implementation of creatives LOG and EXP instructions
    found in the emu10k1 processor. (Patent: WO 9901814 (A1))

    I'm not sure if this is even legal, being a software implementation of a patented hardware instruction,
    so I'm releasing it into the public domain (no license, no copyright).

Compiling:

exp:
 gcc  explog.c -o exp

usage:
 ./exp <log_data> <max_exponent_size> <Sign_control>

log:
 gcc  explog.c -DLOG -o log

usage:
 ./log <lin_data> <max_exponent_size> <Sign_control>


--
log converts linear to logarithmic
exp converts logarithmic to linear

Logarithmic representation:


| 31 |30     29-25|28-24        0|
|sign| exponent   |   Mantissa   |

exponent size varies between 2 and 5 bits,

<max_exp_size> is specified in actual value, thus 3 bits is <max_exp_size>=7

max_exp_size can be anyvalue between 2 and 31.
*/


#include <stdio.h>
#include <stdlib.h>

/*
#include <linux/types.h>

search for existing replacements:
find /usr/include -iname types.h
    /usr/include/rpc/types.h
    /usr/include/sys/types.h
    /usr/include/infiniband/types.h
*/

#include <infiniband/types.h>

__u32 log1(__u32 lin_data,__u32 max_exp,__u32 sign_ctrl)
{
int exp = (int)max_exp + 1;
__u32 result;
__u8 sign;


//FIX ME: mask inputs (i think this is what it does, haven't checked it yet):
sign_ctrl &= 0x03;
max_exp &= 0x1f;
sign = (lin_data >> 31) & 0x01;

/* Smallest exponent value is 2, if we're below that, default to 2. */
if (max_exp < 2)
max_exp = 2;

/* If the value is negative, one's complement the bits. */
if (sign)
lin_data= ~lin_data;

/*
* Continue to shift left until we either:
* - End up with the exponent being 0.
* - Or end up with the MSB set.
*/
while (!(lin_data & 0x80000000)) {
lin_data <<= 1;
exp--;
if (!exp)
break;
}

/*
* If the exponent is not 0, shift left by 1 to get rid of the
* implicit bit.
*/
if (exp)
lin_data <<= 1;

if (max_exp & 0x10)
result = (exp << 26) | (lin_data >> 6);
else if (max_exp & 0x8)
result = (exp << 27) | (lin_data >> 5);
else if (max_exp & 0x4)
result = (exp << 28) | (lin_data >> 4);
else
result = (exp << 29) | (lin_data >> 3);


printf("Exponent %d, mantissa 0x%08x, result 0x%08x.\n", exp, ((lin_data >> 1) + 0x80000000) >> 6, result);

/*
  Sign control
  ------------

  the result is complemented depending on the following conditions

  |----------------|----------|---------|
  | Sign Control   | sign=0   | sign=1  |
  |----------------|----------|---------|
  |    00          |    R     |  ~R     |
  |----------------|----------|---------|
  |    01          |    R     |   R     |
  |----------------|----------|---------|
  |    10          |   ~R     |  ~R     |
  |----------------|----------|---------|
  |    11          |   ~R     |   R     |
  |----------------|----------|---------|
*/

switch( sign_ctrl){
case 0:
if (sign)
result = ~result;
break;

case 2:
result = ~result;
break;

case 3:
if (!sign)
result= ~result;
break;

default:
break;
}

return result;
}

__u32 exp1(__u32 log_data,__u32 max_exp,__u32 sign_ctrl)
{
int exp = (int)max_exp + 1;
__u32 result;
__u8 sign;

sign_ctrl &= 0x03;
max_exp &= 0x1f;
sign = (log_data >> 31) & 0x01;

/* Smallest exponent value is 2, if we're below that, default to 2. */
if (max_exp < 2)
max_exp = 2;

/* If the value is negative, one's complement the bits. */
if (sign)
log_data = ~log_data;

//seperate mantissa and exponent
if (max_exp & 0x10) {
exp = log_data >> 26;
log_data <<= 6;
} else if (max_exp & 0x8) {
exp = log_data >> 27;
log_data <<= 5;
} else if (max_exp & 0x4) {
exp = log_data >> 28;
log_data <<= 4;
} else {
exp = log_data >> 29;
log_data <<= 3;
}

//put back the implicit 1
if (exp) {
log_data >>= 1;
log_data |= 0x80000000;
exp--;
}

//shift mantissa back down
result = log_data >> (max_exp - exp);

//handle sign
switch( sign_ctrl){

case 0:
if(sign!=0)
result= ~result;
return result;
case 1:
return result;
case 2:
return ~result;
case 3:
if(sign==0)
result= ~result;
return result;
}

}

int  main (int argc, char *argv[])
{

if(argc!=4){
printf("usage: log <lin_value> <max exponent size> <sign control>");
return -1;
}



#ifdef LOG
printf("0x%08x\n",log1(strtoul(argv[1],NULL,16),strtoul(argv[2],NULL,16),strtoul(argv[3],NULL,16) ));
#else
printf("0x%08x\n",exp1(strtoul(argv[1],NULL,16),strtoul(argv[2],NULL,16),strtoul(argv[3],NULL,16) ));
#endif
return 0;
}

Source:  https://github.com/Conmanx360/ca0132-tools/tree/master/documentation

Compiled it with "gcc emu10k1-explog.c -o explog", and when executed like this:
Code: [Select]
#!/usr/bin/env bash

#!/bin/bash
for i in {0..50}
do
 ./explog 10 $i 1
done


and it produces something like this:




Guess I should probably browse the other input parameter.  ;D

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 4735
  • Country: fi
    • My home page and email address
Re: Compile a Linux kernel module
« Reply #34 on: July 29, 2022, 05:49:33 pm »
If anybody curious for a code puzzle, this is the C code for it:
Use <stdint.h> (or <inttypes.h>), and replace __uN with uintN_t.

What's the puzzle?  It's just emulating an instruction Creative used in its emu10k1 DSP.  I used to have a Creative Sound Blaster Live! with emu10k1 in it.

Code: [Select]
#ifdef LOG
printf("0x%08x\n",log1(strtoul(argv[1],NULL,16),strtoul(argv[2],NULL,16),strtoul(argv[3],NULL,16) ));
#else
printf("0x%08x\n",exp1(strtoul(argv[1],NULL,16),strtoul(argv[2],NULL,16),strtoul(argv[3],NULL,16) ));
#endif
See the ,16?  That means the inputs are in hexadecimal.  (0 is autodetect from prefix – 0x=hex, 0=octal, default decimal.)
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 4762
  • Country: ro
Re: Compile a Linux kernel module
« Reply #35 on: July 29, 2022, 06:04:55 pm »
What's the puzzle?

To me it was not clear how it calculates.  I need to look more carefully and scribble on a piece of paper.  In fact, I never had to solve such problems, and I'm not familiar with the most known ways to compute log or exp with integers and in hardware (meaning no complex algorithms or long recursive loops).

Even so, since the idea was patented (couldn't find the patent number mention in the C comment) I guess it should contain something different that the usual ways of getting exp/log with integers.

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 4762
  • Country: ro
Re: Compile a Linux kernel module
« Reply #36 on: July 29, 2022, 06:38:07 pm »
Doh, is that really calculates en and loge(n), or is it just shifting bits to get 2n or log2(n)?  If it's the second, then what's in it to patent, I don't get it.

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 4735
  • Country: fi
    • My home page and email address
Re: Compile a Linux kernel module
« Reply #37 on: July 29, 2022, 10:39:05 pm »
LOG converts to a customizable floating point format, and EXP back from it.  See LOG at emu10k1 sourceforge project.
 
The following users thanked this post: RoGeorge


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf