amnezia-vpn / amneziawg-linux-kernel-module

AmneziaWG Linux kernel module
https://www.wireguard.com
GNU General Public License v2.0
85 stars 19 forks source link

Missing the function `get_random_u8` #50

Closed Astromis closed 1 week ago

Astromis commented 2 weeks ago

Hi. Tecnhical info of my os

  Virtualization: kvm
Operating System: Ubuntu 22.04.5 LTS
          Kernel: Linux 5.15.0-125-generic
    Architecture: x86-64
 Hardware Vendor: Red Hat
  Hardware Model: KVM

Try to install amneziawg by standraed command

apt install amneziawg

But the installation is crashed. The log is as follows

Hunk #1 succeeded at 75 with fuzz 3 (offset -1 lines).
 patching file netlink.c
 patching file netlink.h
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/main.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/noise.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/device.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/peer.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/timers.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/queueing.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/send.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/receive.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/socket.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/peerlookup.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/allowedips.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/ratelimiter.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/cookie.o
   CC [M]  /var/lib/dkms/amneziawg/1.0.0/build/generated/netlink.o
 /var/lib/dkms/amneziawg/1.0.0/build/generated/netlink.c: In function ‘generate_ipv6_address_with_prefix’:
 /var/lib/dkms/amneziawg/1.0.0/build/generated/netlink.c:251:47: error: implicit declaration of function ‘get_random_u8’; did you mean ‘get_random_u64’? [-Werror=implicit-function-declaration]
   251 |                         addr[prefix_bytes] |= get_random_u8() & ~mask;
       |                                               ^~~~~~~~~~~~~
       |                                               get_random_u64
 cc1: some warnings being treated as errors
 make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/amneziawg/1.0.0/build/generated/netlink.o] Error 1
 make[1]: *** [Makefile:1910: /var/lib/dkms/amneziawg/1.0.0/build/generated] Error 2
 make: *** [Makefile:94: module] Error 2
 make: Leaving directory '/var/lib/dkms/amneziawg/1.0.0/build'
DKMSKernelVersion: 5.15.0-125-generic
Date: Wed Nov 13 09:34:27 2024
DuplicateSignature: dkms:amneziawg-dkms:1.0.0-0~202411121332+7596c5c~ubuntu22.04.1:/var/lib/dkms/amneziawg/1.0.0/build/generated/netlink.c:251:47: error: implicit declaration of function ‘get_random_u8’; did you mean ‘get_random_u64’? [-Werror=implicit-function-declaration]
Package: amneziawg-dkms 1.0.0-0~202411121332+7596c5c~ubuntu22.04.1
PackageVersion: 1.0.0-0~202411121332+7596c5c~ubuntu22.04.1
SourcePackage: amneziawg-linux-kmod
Title: amneziawg-dkms 1.0.0-0~202411121332+7596c5c~ubuntu22.04.1: amneziawg kernel module failed to build

So it says that that installation misses the function get_random_u8. The little investigation shows that actually this function is available in linux kernel headers right in official repo by this link.

I make sure that the linux headers are installed, retried the amnezia installation and it fails again. I looked at installed headers on my system and found out that it really doesn't have the above function. Here is the code snippet in the same area as in Torvalds header.

static inline void add_latent_entropy(void)
{
#if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__)
        add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
#else
        add_device_randomness(NULL, 0);
#endif
}

void get_random_bytes(void *buf, size_t len);
size_t __must_check get_random_bytes_arch(void *buf, size_t len);
u32 get_random_u32(void);
u64 get_random_u64(void);
static inline unsigned int get_random_int(void)
{
        return get_random_u32();
}
static inline unsigned long get_random_long(void)
{
#if BITS_PER_LONG == 64
        return get_random_u64();
#else
        return get_random_u32();
#endif
}

/*
 * On 64-bit architectures, protect against non-terminated C string overflows
 * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
 */

Do you have any ideas how I can fix this?

G2Dolphin commented 2 weeks ago

I have the same problem on the same OS and kernel versions.

Rogov-Ilya commented 2 weeks ago

try replacing sudo apt linux-headers-$(uname -r) with sudo apt linux-headers-5.15.0-25-generic

Astromis commented 2 weeks ago

@Rogov-Ilya, thanks for reply.

I installed the another headers and remove sourced one. Unfortunately, it seems that it somewhere got to know which kernel version is installed and tried to build the module for this and if it can't find the headers for this kernel version it just skips the building. It's interesting that installation continues.

...
Building for 5.15.0-125-generic
Module build for kernel 5.15.0-125-generic was skipped since the
kernel headers for this kernel does not seem to be installed.
Setting up amneziawg (1.0.20210914-0~202410011335+c0b400c~ubuntu22.04.1) ...

Maybe I should try to install the particular kernel?

vasly commented 2 weeks ago

I have the same error for Ubuntu 5.15.0-125-generic

lisachev commented 2 weeks ago

Ubuntu 22.04.5 LTS x86_64 5.15.0-125-generic

confirmed error

RomikB commented 1 week ago

Same error. Ubuntu 5.15.0-125-generic have no definition for get_random_u8.

g0ha1 commented 1 week ago

same error on 5.15.0-125, tryed to install on older kernel version, like 5.15.0-25 got same error

vprgr commented 1 week ago

confirmed error

leninalive commented 1 week ago

Should be fixed in latest packages.