Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all 6330 articles
Browse latest View live

detour hooking usermode functions from the kernel

$
0
0

I have a kernel mode driver and I'm trying to implement a way so that I can make usermode hooks from it. I need to hook usermode functions via detour/jmp from the kernel.


Why is the difference between a task_struct pointer and a field inside that struct so large?

$
0
0

This statement:

pr_err("init=%p head=%p offset=%zd\n", 
        &init_task, &init_task.thread_group,
        offsetof(struct task_struct, thread_group));

produces this output when compiled into a kernel module and insmod'ed:

init=00000000b0561be0 head=00000000cab9146b offset=2416

My question is why are the two addresses so far apart when they should only be 2416 bytes apart ? When printing the symbol offsets in GDB, I also get expected values, and I'm not sure where else to look:

(gdb) p &init_task
$1 = (struct task_struct *) 0xffffffff82613780 <init_task>
(gdb) p &init_task.thread_group 
$2 = (struct list_head *) 0xffffffff826140f0 <init_task+2416>

EDIT: %zx instead of %p yields correct numbers. So, no %p support in printk() I guess ?

Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-bloc(8,2)

$
0
0

I am a spanish speaker so excuse me for my bad english.

I am learning how to compile slackware kernel, so I have downloaded linux-3.2.7.tar.bz2 from http://www.kernel.org

Conditions:

  • Slackware installed on a vmware virtual machine.
  • Host o.s windows 7.
  • Slackware root filesystem: ext4
  • Slackware old kernel: 2.6.37.6

Basically I have followed the following steps:

#cd /usr/src
#tar jvxf linux-3.2.2.tar.bz2
#mv /usr/src/linux /usr/src/linux.old 
#ln -s /usr/src/linux-3.2.2 /usr/src/linux
#cd linux-3.2.2
#make mrproper
#cp /usr/src/linux-2.6.37.6/.config /usr/src/linux-3.2.2/.config
#make menuconfig

Load an alternate configuration file: .config INCLUDED (OPTION Y):

ATA/ATAPI/MFM/RLL support (DEPRECATED) (at Device drivers)

  • SCSI generic support (at Device drivers)
  • second extended support (at filesystems)
  • ext3 journaling (all)
  • ext4 (all)
  • ext4 (at filesystems)
  • JBD (ext4) debuggin support
  • JBD2 (ext4) debugging support
  • ReiserFS support
  • XFS filesystem support
  • "compile kernel with debug info" (at kernel hacking)

    make dep

    make clean

    make bzImage

    make modules

    make modules_install

    mv /boot/System.map /boot/System.map.old

    cp /usr/src/linux/System.map /boot/System.map-3.2.2

    ln -s /boot/System.map-3.2.2 /boot/System.map

    mv /boot/vmlinuz /boot/vmlinuz.old

    cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-3.2.2

    ln -s /boot/vmlinuz-3.2.2 /boot/vmlinuz

    nano -w /etc/lilo.conf

ADDED THE FOLLOWING LINES:

image=/boot/vmlinuz.old
label = oldSlack
root = /dev/sda2
read-only

#lilo
#lilo -q
#shutdown -r now

When kernel 3.2.2 is booting, it stops showing the following:

VFS: Cannot open root device "802" or unknown-block(8,2)
Please append a correct "root=" boot option
Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-bloc(8,2)

I hate this message because I have recompiled the kernel many times, and after hours of compilation I always get this message. :(

Can anyone help me to understand what I am doing bad or why is that error?

Getting the name of subdirectories and their number in the Linux kernel [closed]

$
0
0

I am writing a Linux driver that should read the names of subdirectories and the number in the folder. For example, /tmp/users_dir has subdirectories /user1, /user2, and so on. How do I determine the names of subdirectories contained in /tmp/user_dir and their number? I think I should go in the direction of dentry, but I don 't know what functions there are for my task.

Find the logical parent pid of a container

$
0
0

TL; DR : I'd like to know without relying too much on the underlying containerization engine which process spawned a container when a new container is started

With recent containerization tools, the main process of a container is generally not the descendant of the process that spawned it. This is because containers are ran daemonized. For exemple with docker, if docker runs a detached container, its ancestors will be containerd-shim, containerd and systemd/init(1) but not the shell that spawned it!

Is there a kernel-level way when a container is created to tell which is logical parent, i.e. the process that created it? I’d like to do something like the following pseudocode:

int on_container_spawn(int container_rootpid) {
    int logical_parent = find_logical_parent(container_pid, ...) 
    pr_debug("logical parent of %d is %d", logical_parent, container_rootpid);
    return  logical_parent;
}

Although I didn’t try yet, it seems that for OCI-based containers, the prestart hook must be a good place to look at but this works only for OCI-based containers and won’t for example work for LXC containers.

Is there a way to get this information without relying too much on the underlying technology? If it’s not feasible do you know how can I do it for a specific technology?


Note: I am perfectly aware that the process that spawned the container can be terminated before the container but it doesn’t matter for my use case.

Why doesn't Linux use fibers instead of preemptive multitasking?

$
0
0
  1. Can someone please explain what coroutines and fibers are? What problem do they solve in comparison to the regular routines and multitasking mechanism.
  2. Why does Linux use preemptive multitasking instead of cooperative multitasking?

Ubuntu 16.04 can't execute any apt-get stuck at - 0% [Working] [closed]

$
0
0

Can't execute any apt install and upgrade stuck at - 0% [Working]. I also can't ping ppa.launchpad.net. The problem occurred when I started installing the "npm" package. curl and wget command can't reach any host.

VPS is hosted on OVH SAS. uname -a informations: Linux vps801329 4.4.0-176-generic #206-Ubuntu SMP Fri Feb 28 05:02:04 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux.

Ubuntu version:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:        16.04
Codename:       xenial

This is what I tried a:

sudo apt-get clean
sudo apt-get check

Storage is not full, no problems with RAM and CPU. Bandwidth is ok. Can somebody give me a solution fast?

Removing the default keyboard's interrupt handler in Linux

$
0
0

Is there a way to free the default keyboard interrupt handler using free_irq from a kernel module?

I've tried to call free_irq(1, NULL), which doesn't work since we I don't know the handler's cookie (2nd argument).

Thanks in advance :)

Update: my kernel version is 4.10.0.


Failed to build Kernel 4.9 on Jetson Nano

$
0
0

I'm trying to build Kernel 4.9 on Jetson Nano, but I got the following Error messages:

In file included from ....../kernel-4.9/include/asm-generic/bug.h:13:0, from ....../kernel-4.9/arch/arm64/include/asm/bug.h:67, from ....../kernel-4.9/include/linux/bug.h:4, from ....../kernel-4.9/arch/arm64/include/asm/cmpxchg.h:21, from ....../kernel-4.9/arch/arm64/include/asm/atomic.h:41, from ....../kernel-4.9/include/linux/atomic.h:4, from ....../nvidia/drivers/media/platform/tegra/camera/vi/channel.c:13: ....../nvidia/drivers/media/platform/tegra/camera/vi/channel.c: In function ‘tegra_channel_s_parm’: ....../kernel-4.9/include/linux/kernel.h:838:48: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ ^ ....../nvidia/include/media/mc_common.h:265:2: note: in expansion of macro ‘container_of’ container_of(vdev, struct tegra_channel, video) ^~~~~~~~~~~~ ....../nvidia/drivers/media/platform/tegra/camera/vi/channel.c:2029:37: note: in expansion of macro ‘to_tegra_channel’ struct tegra_channel *chan = to_tegra_channel(vfh->vdev); ^~~~~~~~~~~~~~~~ ....../kernel-4.9/include/linux/kernel.h:838:48: note: (near initialization for ‘chan’) const typeof( ((type *)0)->member ) *__mptr = (ptr); \ ^ ....../nvidia/include/media/mc_common.h:265:2: note: in expansion of macro ‘container_of’ container_of(vdev, struct tegra_channel, video) ^~~~~~~~~~~~ ....../nvidia/drivers/media/platform/tegra/camera/vi/channel.c:2029:37: note: in expansion of macro ‘to_tegra_channel’ struct tegra_channel *chan = to_tegra_channel(vfh->vdev); ^~~~~~~~~~~~~~~~ ....../nvidia/drivers/media/platform/tegra/camera/vi/channel.c: In function ‘tegra_channel_g_parm’: ....../kernel-4.9/include/linux/kernel.h:838:48: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ ^ ....../nvidia/include/media/mc_common.h:265:2: note: in expansion of macro ‘container_of’ container_of(vdev, struct tegra_channel, video) ^~~~~~~~~~~~ ....../nvidia/drivers/media/platform/tegra/camera/vi/channel.c:2039:37: note: in expansion of macro ‘to_tegra_channel’ struct tegra_channel *chan = to_tegra_channel(vfh->vdev); ^~~~~~~~~~~~~~~~ ....../kernel-4.9/include/linux/kernel.h:838:48: note: (near initialization for ‘chan’) const typeof( ((type *)0)->member ) *__mptr = (ptr); \ ^ ....../nvidia/include/media/mc_common.h:265:2: note: in expansion of macro ‘container_of’ container_of(vdev, struct tegra_channel, video) ^~~~~~~~~~~~ ....../nvidia/drivers/media/platform/tegra/camera/vi/channel.c:2039:37: note: in expansion of macro ‘to_tegra_channel’ struct tegra_channel chan = to_tegra_channel(vfh->vdev); ^~~~~~~~~~~~~~~~ LD drivers/media/platform/tegra-vivid/built-in.o CC
drivers/media/platform/tegra/camera/camera_gpio.o cc1: all warnings being treated as errors ....../kernel-4.9/scripts/Makefile.build:335: recipe for target 'drivers/media/platform/tegra/camera/vi/channel.o' failed make[7]:
[drivers/media/platform/tegra/camera/vi/channel.o] Error 1 ....../kernel-4.9/scripts/Makefile.build:649: recipe for target 'drivers/media/platform/tegra/camera/vi' failed make[6]: [drivers/media/platform/tegra/camera/vi] Error 2 make[6]: Waiting for unfinished jobs.... CC
drivers/media/platform/tegra/mipical/mipi_cal.o ....../kernel-4.9/scripts/Makefile.build:649: recipe for target 'drivers/media/platform/tegra/camera' failed make[5]: [drivers/media/platform/tegra/camera] Error 2 make[5]: Waiting for unfinished jobs.... CC
drivers/media/platform/tegra/mipical/vmipi/vmipi.o LD
drivers/media/platform/tegra/mipical/built-in.o ....../kernel-4.9/scripts/Makefile.build:649: recipe for target 'drivers/media/platform/tegra' failed make[4]: [drivers/media/platform/tegra] Error 2 ....../kernel-4.9/scripts/Makefile.build:649: recipe for target 'drivers/media/platform' failed make[3]: [drivers/media/platform] Error 2 ....../kernel-4.9/scripts/Makefile.build:649: recipe for target 'drivers/media' failed make[2]: [drivers/media] Error 2 ....../kernel-4.9/Makefile:1104: recipe for target 'drivers' failed make[1]: [drivers] Error 2 make[1]: * Waiting for unfinished jobs.... make[1]: Leaving directory '........../kernel_out' Makefile:171: recipe for target 'sub-make' failed make: *** [sub-make] Error 2

Line 838 in file ....../kernel-4.9/include/linux/kernel.h is:

 837 #define container_of(ptr, type, member) ({          \
 838     const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 839     (type *)( (char *)__mptr - offsetof(type,member) );})

My Compiler is gcc/g++ 7.5.0 .

➜  kernel-4.9 gcc --version
gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

➜  kernel-4.9 g++ --version
g++ (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Can anybody give me a hand?

Cheers Pei

Incorrect selection of kernel headers: expected 4.19.x, got 3.18.x

$
0
0

I'm trying to compile buildroot with a kernel 4.19 but when I'm compiling I have this error :

Incorrect selection of kernel headers: expected 4.19.x, got 3.18.x
package/pkg-generic.mk:306: recipe for target '/home/localuser/newOS/buildroot/output/build/linux-headers-STD_LIV_3.18/.stamp_staging_installed' failed
make[1]: *** [/home/localuser/newOS/buildroot/output_agila/build/linux-headers-STD_LIV_3.18.140-vab820/.stamp_staging_installed] Error 1
Makefile:84: recipe for target '_all' failed
make: *** [_all] Error 2

Does anybody now how to solve this problem?

Allocate page with execution privileges at an arbitrary currently unused virtual address in a windows kernel driver

$
0
0

I'm writing a kernel mode driver (Windows 10 64-bit) where I require code execution at a virtual address in another driver's virtual address space that is currently unused(MmIsAddressValid returns false).

What I have tried:

  1. calling the undocumented ntoskrnl function MiFillPteHierarchy. This function returns 4 pointers one of which is meant to be a pointer to the PTE structure which I would need to change in order to give code execution privileges to the page. I have found that when I deference these pointers I get a page segmentation fault BSOD. The function works fine when I give it an address for which MmIsAddressValid returns true(which is to be expected).

The MIFILLPTEHIERARCHY function in ntoskrnl returns 4 virtual addresses corresponding to the PTE,PDE,PDPTE, and PML4E(to the best of my knowledge) Here is the function sig I have:

typedef uint64_t(__fastcall* MIFILLPTEHIERARCHY)(void* virtualaddy, PTE_HIERARCHY* hierarchy);

The PTE_HIERARCHY structure looks like this

struct PTE_HIERARCHY {
    PTE* pte;
    uint64_t* PDE;
    uint64_t* PDPTE;
    uint64_t* PML4E;
};

(PTE structure is the only one i've made)

as per the INTEL manual I have been reading https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-3a-part-1-manual.pdf The PTE structure looks like this:

union PTE{

    uint64_t raw;

    struct {
        uint64_t present : 1; //Present; must be 1 to map a 4-KByte pag
        uint64_t read_write : 1; //Read/write; if 0, writes may not be allowed to the 4-KByte page referenced by this entry (see Section 4
        uint64_t user_supervisor : 1; //User/supervisor; if 0, user-mode accesses are not allowed to the 4-KByte page referenced by this entry (see Section 4.6)
        uint64_t PWT : 1; //Page-level write-through; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9.
        uint64_t PCD : 1; //Page-level cache disable; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9.2
        uint64_t accessed : 1; //Accessed; indicates whether software has accessed the 4-KByte page referenced by this entry (see Section 4.8
        uint64_t dirty : 1; //Dirty; indicates whether software has written to the 4-KByte page referenced by this entry (see Section 4.8)
        uint64_t PAT : 1; //Indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9.2)
        uint64_t global : 1; //Global; if CR4.PGE = 1, determines whether the translation is global (see Section 4.10); ignored otherwis
        uint64_t ignored : 3;
        uint64_t physical_page_address : 36; //Physical address of the 4-KByte page referenced by this entry
        uint64_t reserved : 4;
        uint64_t ignored2 : 7;
        uint64_t protection_key : 4; //Protection key; if CR4.PKE = 1, determines the protection key of the page (see Section 4.6.2); ignored otherwise
        uint64_t xd : 1; //if IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 4-KByte page controlled by this entry; see Section 4.6); otherwise, reserved (must be 0
    }values;

};

My implementation:



//enumerate system modules
uint32_t buffersize=0;
PRTL_PROCESS_MODULES mods=nullptr;
            ZwQuerySystemInformation(SystemModuleInformation,0,buffersize,&buffersize);
mods = (PRTL_PROCESS_MODULES)ExAllocatePool(NonPagedPool, buffersize);
ZwQuerySystemInformation(SystemModuleInformation, mods, buffersize, &buffersize);

//using ACPI as an example
const char* drivername = "ACPI.sys";
for (uint32_t i = 0; i < mods->NumberOfModules; i++) {
    RTL_PROCESS_MODULE_INFORMATION mod = mods->Modules[i];
    char currentdriver[0x100] = { 0 };
    memcpy(&currentdriver[0], &mod.FullPathName[mod.OffsetToFileName], 8);
    if (!strcmp(currentdriver, drivername)) {
            imagebase = mod.ImageBase[i]
            imagesize=mod.size[i]

            break;
}
}

//I then find some unused virtual address in the drivers address space
//something like 
for imagebase < address < imagebase+imagesize
if(!MmIsAddressValid(address))
targetaddress= address
else
address++

//query MiFillPteHierarchy for PTE hierarchy
PTE_HIERARCHY hierarchy = {0};
MiFillPteHierarchy(targetaddress, &hierarchy);

hierarchy.PTE->values.present //BSOD here


//However if I have a virtual address where MmIsAddressValid returns true;
hierarchy.PTE->values.present //NO BSOD 

My idea was to get the PTE structure and modify it such that I have code execution privileges and the OS/CPU doesn't overwrite this virtual memory region with another page.

  1. MmMapLockedPagesSpecifyCache. When I use this method the return pointer is nowhere near where the target virtual address is.

This is my code using this method

//where MmIsAddressValid(targetvirtualaddress)=false
void* pool = ExAllocatePool(NonPagedPool/PagePool(tried both),50);
memset(pool, 0, 50);
PMDL MDL = IoAllocateMdl(pool, 50, false, false, nullptr);
MmBuildMdlForNonPagedPool(MDL);
void* resultantaddress = MmMapLockedPagesSpecifyCache(MDL, KernelMode, MmNonCached, targetvirtualaddress, false, HighPagePriority);
//resultantaddress is nowhere near targetvirtualaddress

Ideally what I would want:

MmIsAddressValid(targetaddress) returns false //windows can overwrite
//do something to page here
MmIsAddressValid(targetaddress) returns true //windows wont overwrite
//modify PTE to gain code execution privileges 

(To the best of my knowledge if MmIsAddressValid returns true it means windows knows the virtual address is in use and won't try to overwrite it)

I guess my question is why does de-referencing the PTE/PDE for this virtual address that is not being used result in a BSOD(page segmentation fault)? And why does MmMapLockedPagesSpecifyCache not allocate a page anywhere near the target address? And If both of these methods will not work for my purposes what can I do?

Kernel appears to have died, IT WILL RESTART AUTOMATICALLY - JUPYTER NOTEBOOK

$
0
0

I've been trying this code for a while and I am getting the above mentioned error. I've tried to upgrade the numby. Everything is fine but still I get the error.

I've attached the code here:

import numpy as np
import cv2
from matplotlib import pyplot as plt


img = cv2.imread('D:\motog5plus camera\IMG_20180617_120221162.jpg')
mask = np.zeros(img.shape[:2],np.uint8)

bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)

rect = (50,50,450,290)
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)

mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]

plt.imshow(img),plt.colorbar(),plt.show()

while compiling linux kernel to old version (2.6.11) and I got stuck

$
0
0

I am a newbie at studying linux kernel, and i've received an assignment.

I'm trying to compile the old linux kernel=2.6.11 and got some errors. Current environment is following:

distro: ubuntu 14.04 64bit
kernel: 4.4.0
gcc: 4.8.4
binutils: 2.24

I set menuconfig as default and tried my first compile, I met following errors:

scripts/kconfig/mconf arch/x86_64/Kconfig
#
# using defaults found in .config
#


*** End of Linux kernel configuration.
*** Execute 'make' to build the kernel or try 'make help'.

ilak@ilak-vm:~/workspace/linux-2.6.11$ make
  CHK     include/linux/version.h
  SPLIT   include/linux/autoconf.h -> include/config/*
make[1]: `arch/x86_64/kernel/asm-offsets.s' is up to date.
  CHK     include/asm-x86_64/offset.h
  CHK     include/linux/compile.h
  CHK     usr/initramfs_list
  CC      arch/x86_64/kernel/process.o
In file included from include/asm/smp.h:18:0,
                 from include/linux/smp.h:19,
                 from include/linux/sched.h:25,
                 from arch/x86_64/kernel/process.c:22:
include/asm/mpspec.h:79:2: warning: ‘packed’ attribute ignored for field of type ‘unsigned char[6]’ [-Wattributes]
  unsigned char mpc_bustype[6] __attribute((packed));
  ^
In file included from include/asm/processor.h:19:0,
                 from include/linux/spinlock.h:16,
                 from include/linux/capability.h:45,
                 from include/linux/sched.h:7,
                 from arch/x86_64/kernel/process.c:22:
include/asm/apic.h: In function ‘apic_write_atomic’:
include/asm/system.h:185:22: warning: value computed is not used [-Wunused-value]
 #define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
                      ^
include/asm/apic.h:47:2: note: in expansion of macro ‘xchg’
  xchg((volatile unsigned int *)(APIC_BASE+reg), v);
  ^
In file included from include/asm/mmu_context.h:5:0,
                 from arch/x86_64/kernel/process.c:43:
arch/x86_64/kernel/process.c: At top level:
include/asm/desc.h:202:2: warning: ‘set_ldt_desc’ is static but used in inline function ‘load_LDT_nolock’ which is not static [enabled by default]
  set_ldt_desc(cpu, pc->ldt, count);
  ^
In file included from arch/x86_64/kernel/process.c:37:0:
include/asm/uaccess.h:47:39: warning: ‘current_thread_info’ is static but used in inline function ‘verify_area’ which is not static [enabled by default]
   :"1" (addr),"g" ((long)(size)),"g" (current_thread_info()->addr_limit.seg)); \
                                       ^
include/asm/uaccess.h:50:38: note: in expansion of macro ‘__range_not_ok’
 #define access_ok(type, addr, size) (__range_not_ok(addr,size) == 0)
                                      ^
include/asm/uaccess.h:54:9: note: in expansion of macro ‘access_ok’
  return access_ok(type,addr,size) ? 0 : -EFAULT;
         ^
In file included from include/linux/mm.h:36:0,
                 from arch/x86_64/kernel/process.c:24:
include/asm/pgtable.h:264:46: warning: ‘set_pte’ is static but used in inline function ‘pte_mkwrite’ which is not static [enabled by default]
 extern inline pte_t pte_mkwrite(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; }
                                              ^
include/asm/pgtable.h:263:46: warning: ‘set_pte’ is static but used in inline function ‘pte_mkyoung’ which is not static [enabled by default]
 extern inline pte_t pte_mkyoung(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
                                              ^
include/asm/pgtable.h:262:46: warning: ‘set_pte’ is static but used in inline function ‘pte_mkdirty’ which is not static [enabled by default]
 extern inline pte_t pte_mkdirty(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
                                              ^
include/asm/pgtable.h:261:45: warning: ‘set_pte’ is static but used in inline function ‘pte_mkexec’ which is not static [enabled by default]
 extern inline pte_t pte_mkexec(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
                                             ^
include/asm/pgtable.h:260:45: warning: ‘set_pte’ is static but used in inline function ‘pte_mkread’ which is not static [enabled by default]
 extern inline pte_t pte_mkread(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
                                             ^
include/asm/pgtable.h:259:48: warning: ‘set_pte’ is static but used in inline function ‘pte_wrprotect’ which is not static [enabled by default]
 extern inline pte_t pte_wrprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW)); return pte; }
                                                ^
include/asm/pgtable.h:258:44: warning: ‘set_pte’ is static but used in inline function ‘pte_mkold’ which is not static [enabled by default]
 extern inline pte_t pte_mkold(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
                                            ^
include/asm/pgtable.h:257:46: warning: ‘set_pte’ is static but used in inline function ‘pte_mkclean’ which is not static [enabled by default]
 extern inline pte_t pte_mkclean(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
                                              ^
include/asm/pgtable.h:256:48: warning: ‘set_pte’ is static but used in inline function ‘pte_exprotect’ which is not static [enabled by default]
 extern inline pte_t pte_exprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
                                                ^
include/asm/pgtable.h:255:48: warning: ‘set_pte’ is static but used in inline function ‘pte_rdprotect’ which is not static [enabled by default]
 extern inline pte_t pte_rdprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
                                                ^
include/asm/pgtable.h:99:2: warning: ‘set_pgd’ is static but used in inline function ‘pgd_clear’ which is not static [enabled by default]
  set_pgd(pgd, __pgd(0));
  ^
include/asm/pgtable.h:89:2: warning: ‘set_pud’ is static but used in inline function ‘pud_clear’ which is not static [enabled by default]
  set_pud(pud, __pud(0));
  ^
arch/x86_64/kernel/process.c: Assembler messages:
arch/x86_64/kernel/process.c:459: Error: unsupported instruction `mov'
arch/x86_64/kernel/process.c:463: Error: unsupported instruction `mov'
arch/x86_64/kernel/process.c:393: Error: unsupported instruction `mov'
arch/x86_64/kernel/process.c:394: Error: unsupported instruction `mov'
arch/x86_64/kernel/process.c:395: Error: unsupported instruction `mov'
arch/x86_64/kernel/process.c:396: Error: unsupported instruction `mov'
make[1]: *** [arch/x86_64/kernel/process.o] Error 1
make: *** [arch/x86_64/kernel] Error 2

After searching some information on Google, I thought binutils may be the problem and tried something but it seemed to be unhelpful.

What would be the matter and what would i need to compile the old kernel version?

Thx in advance

Don't misunderstand RBF kernel for svm or regression

$
0
0

I found that Gaussian kernel is actually not gaussian-shaped.

I just made a point source at the center of the image

and implemented gaussian kernel ridge regression.

and the shape has spatial frequency on the gaussian curve.

it means that It is not 100% radial dependent.

in other words we can't make 100% gaussian RBF prediction model.

if you are okey with low accuracy. then just keep using Support vector machine with gaussian kernel

the following pictures are the source image and result of the regression

enter image description here

enter image description here

and this is my test code in Matlab

This is my test code of Matlab

Kernel Regression
close all
clc
clear all

Variables
fOrder = 2.0;
nNumberofData = 50;
fLamda = 0.001;
fSigma = 10;

nWidth = 50;
nHeight = 50;

a1 = 0.1;
a2 = 0.0;
a3 = 0.7;
a4 = 2.0;
a5 = 0.5;

Dev Data
pfDevData = zeros(nHeight,nWidth);


 X_Temp = [25,20];
 y_Temp = [300];

[nNumberOfValidData,~] = size(X_Temp);

for nCnt = 1:1:nNumberOfValidData
    r = X_Temp(nCnt,1);
    c = X_Temp(nCnt,2);
    pfDevData(r,c) = y_Temp(nCnt,1);
end



X = zeros(nNumberofData*nNumberofData,2);
y = zeros(nNumberofData*nNumberofData,1);
nCnt = 0;
for r = 1:1:nNumberofData
    for c = 1:1:nNumberofData
        nCnt = nCnt + 1;
        X(nCnt,1) = double(r);
        X(nCnt,2) = double(c);
        y(nCnt,1) = pfDevData(r,c);
    end
end


figure
mesh(pfDevData)
figure
imagesc(pfDevData)

Make Kernel
K_1 = diag(X*X')*ones(nNumberofData*nNumberofData,1)';
K_2 = ones(nNumberofData*nNumberofData,1)*diag(X*X')';
K_3 = -2.0*X*X';
K_Total = K_1 + K_2 + K_3;

K = exp(-(K_Total)/(2.0*fSigma*fSigma))/(sqrt(2.0*pi)*fSigma);

Regression Data
pfRegression = zeros(nHeight,nWidth);

pfTemp = y'*inv(K + 0.5*fLamda*eye(nNumberofData*nNumberofData))*K;
pfRegression = reshape(pfTemp, [nNumberofData nNumberofData])';

figure
mesh(pfRegression)


figure
imagesc(pfRegression)

figure
plot(pfRegression(25,:))

No rule to make target, needed by '__build'. Stop

$
0
0

I am building a module in yocto environment.

In local.conf of yocto, I have:

IMAGE_INSTALL_append += " kernel-modules kernel-devsrc kernel-dev"

This can pass the bitbake and generated a final image.

I used this image to boot, it can boot and login.

I tried to build a module in yocto.

It shows:

...Building loadable kernel module

make: Entering directory '/home/srmt-1.5.0/srmt-lkm'

/usr/bin/make -C /lib/modules/5.4.20-yocto-standard/build M=/home/srmt-1.5.0/srmt-lkm modules

make[1]: Entering directory '/lib/modules/5.4.20-yocto-standard/build'

make[2]: *** No rule to make target '/home/srmt-1.5.0/srmt-lkm/srmtMwaitLKM.o', needed by '__build'.  Stop.

make[1]: *** [Makefile:1652: /home/srmt-1.5.0/srmt-lkm] Error 2

make[1]: Leaving directory '/lib/modules/5.4.20-yocto-standard/build'

make: *** [Makefile:39: all] Error 2

make: Leaving directory '/home/srmt-1.5.0/srmt-lkm'

I don't know what does it mean:

make[2]: *** No rule to make target '/home/srmt-1.5.0/srmt-lkm/srmtMwaitLKM.o', needed by '__build'.  Stop.

I confirmed I have the folder - /lib/modules/5.4.20-yocto-standard/build, and there are files inside.

The same package I built it in a Ubuntu 18 OS, it has no problem.


what are mali.ko and ump.ko used for in lib/modules

$
0
0

I found two kernel modules in /lib/modules folder, they are mali.ko and ump.ko, and I tried to google some information about it, unfortunately, I found nothing valuable information.

if you have worked on those two kernel modules, can you tell me what they are used for ?

thanks.

Convert dmesg timestamp to custom date format

$
0
0

I am trying to understand the dmesg timestamp and find it hard to convert that to change it to java date/custom date format.

any help is much appreciated.

Sample dmesg log:

[14614.647880] airo(eth1): link lost (missed beacons)

Thanks!

My Jupyter notebook shows an error 'connecting to kernel '. I dont know what to do?

$
0
0

I am not to able to run codes on my Jupyter notebook.It shows connecting to kernel and then shows not connected. Same with spyder and those connected with Anaconda.

This is the log of the notebook
[I 15:46:35.196 NotebookApp] JupyterLab extension loaded from C:\Users\mm\Anaconda3\lib\site-packages\jupyterlab
[I 15:46:35.215 NotebookApp] JupyterLab application directory is C:\Users\mm\Anaconda3\share\jupyter\lab
[I 15:46:35.322 NotebookApp] Serving notebooks from local directory: C:\Users\mm
[I 15:46:35.322 NotebookApp] The Jupyter Notebook is running at:
[I 15:46:35.323 NotebookApp] http://localhost:8888/?token=53a396a048abbd68e66ad5dcf1cdacef2aab87ef7b8aa2b7
[I 15:46:35.323 NotebookApp]  or http://127.0.0.1:8888/?token=53a396a048abbd68e66ad5dcf1cdacef2aab87ef7b8aa2b7
[I 15:46:35.323 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:46:35.602 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/mm/AppData/Roaming/jupyter/runtime/nbserver-3080-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=53a396a048abbd68e66ad5dcf1cdacef2aab87ef7b8aa2b7
     or http://127.0.0.1:8888/?token=53a396a048abbd68e66ad5dcf1cdacef2aab87ef7b8aa2b7
[W 15:47:27.021 NotebookApp] Notebook Assignment_DBSCAN.ipynb is not trusted
[I 15:47:28.255 NotebookApp] Kernel started: a993bb8f-8adc-45f8-a5ca-833913a566be
Traceback (most recent call last):
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\__init__.py", line 55, in <module>
    from .core.application import Application
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "C:\Users\mm\Anaconda3\lib\pdb.py", line 76, in <module>
    import code
  File "C:\Users\mm\code.py", line 40
    mul_lr = linear_model.LogisticRegression(multi_class='multinomial', solver='newton-cg',max_iter =1000)
         ^
IndentationError: expected an indented block
[I 15:47:31.156 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
Traceback (most recent call last):
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\__init__.py", line 55, in <module>
    from .core.application import Application
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "C:\Users\mm\Anaconda3\lib\pdb.py", line 76, in <module>
    import code
  File "C:\Users\mm\code.py", line 40
    mul_lr = linear_model.LogisticRegression(multi_class='multinomial', solver='newton-cg',max_iter =1000)
         ^
IndentationError: expected an indented block
[I 15:47:34.190 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
Traceback (most recent call last):
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\__init__.py", line 55, in <module>
    from .core.application import Application
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "C:\Users\mm\Anaconda3\lib\pdb.py", line 76, in <module>
    import code
  File "C:\Users\mm\code.py", line 40
    mul_lr = linear_model.LogisticRegression(multi_class='multinomial', solver='newton-cg',max_iter =1000)
         ^
IndentationError: expected an indented block
[I 15:47:37.202 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
Traceback (most recent call last):
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\__init__.py", line 55, in <module>
    from .core.application import Application
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "C:\Users\mm\Anaconda3\lib\pdb.py", line 76, in <module>
    import code
  File "C:\Users\mm\code.py", line 40
    mul_lr = linear_model.LogisticRegression(multi_class='multinomial', solver='newton-cg',max_iter =1000)
         ^
IndentationError: expected an indented block
[I 15:47:40.234 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\mm\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "C:\Users\mm\Anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\__init__.py", line 55, in <module>
    from .core.application import Application
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "C:\Users\mm\Anaconda3\lib\site-packages\IPython\core\debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "C:\Users\mm\Anaconda3\lib\pdb.py", line 76, in <module>
    import code
  File "C:\Users\mm\code.py", line 40
    mul_lr = linear_model.LogisticRegression(multi_class='multinomial', solver='newton-cg',max_iter =1000)
         ^
IndentationError: expected an indented block
[W 15:47:43.264 NotebookApp] KernelRestarter: restart failed
[W 15:47:43.264 NotebookApp] Kernel a993bb8f-8adc-45f8-a5ca-833913a566be died, removing from map.
[W 15:47:49.307 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020
[W 15:48:13.422 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020
[W 15:48:28.368 NotebookApp] Timeout waiting for kernel_info reply from a993bb8f-8adc-45f8-a5ca-833913a566be
[E 15:48:28.373 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: a993bb8f-8adc-45f8-a5ca-833913a566be)
[W 15:48:28.378 NotebookApp] 404 GET /api/kernels/a993bb8f-8adc-45f8-a5ca-833913a566be/channels?session_id=58c6e2286d514efba8596e9d46e58020 (::1): Kernel does not exist: a993bb8f-8adc-45f8-a5ca-833913a566be
[W 15:48:28.455 NotebookApp] 404 GET /api/kernels/a993bb8f-8adc-45f8-a5ca-833913a566be/channels?session_id=58c6e2286d514efba8596e9d46e58020 (::1) 39147.31ms referer=None
[W 15:48:28.457 NotebookApp] 404 GET /api/kernels/a993bb8f-8adc-45f8-a5ca-833913a566be/channels?session_id=58c6e2286d514efba8596e9d46e58020 (::1): Kernel does not exist: a993bb8f-8adc-45f8-a5ca-833913a566be
[W 15:48:28.464 NotebookApp] 404 GET /api/kernels/a993bb8f-8adc-45f8-a5ca-833913a566be/channels?session_id=58c6e2286d514efba8596e9d46e58020 (::1) 15044.70ms referer=None
[W 15:48:32.499 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020
[W 15:49:00.539 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020
[W 15:49:36.554 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020
[W 15:50:28.588 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020
[I 15:51:44.444 NotebookApp] 302 GET /notebooks/Untitled11.ipynb?kernel_name=python3 (::1) 2.99ms
[W 15:51:52.595 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020
[W 15:56:53.025 NotebookApp] Replacing stale connection: a993bb8f-8adc-45f8-a5ca-833913a566be:58c6e2286d514efba8596e9d46e58020

How to understander comments and condition check in the Linux GSO function skb_segment()

$
0
0

Recently I've been reading Linux kernel network stack code, but now I'm stuck at few lines of in the function skb_segment(), I've already understood all kinds of TSO/UFO/GSO/GRO offloadings, but I simply can't understand how these lines make sense.

code:

/**
 *  skb_segment - Perform protocol segmentation on skb.
 *  @head_skb: buffer to segment
 *  @features: features for the output path (see dev->features)
 *
 *  This function performs segmentation on the given skb.  It returns
 *  a pointer to the first in a list of new skbs for the segments.
 *  In case of error it returns ERR_PTR(err).
 */
struct sk_buff *skb_segment(struct sk_buff *head_skb,
                netdev_features_t features)
{
... ...
    if (list_skb && !list_skb->head_frag && skb_headlen(list_skb) &&
        (skb_shinfo(head_skb)->gso_type & SKB_GSO_DODGY)) {
        /* gso_size is untrusted, and we have a frag_list with a linear
         * non head_frag head.
         *
         * (we assume checking the first list_skb member suffices;
         * i.e if either of the list_skb members have non head_frag
         * head, then the first one has too).
         *
         * If head_skb's headlen does not fit requested gso_size, it
         * means that the frag_list members do NOT terminate on exact
         * gso_size boundaries. Hence we cannot perform skb_frag_t page
         * sharing. Therefore we must fallback to copying the frag_list
         * skbs; we do so by disabling SG.
         */
        if (mss != GSO_BY_FRAGS && mss != skb_headlen(head_skb))
            features &= ~NETIF_F_SG;
    }
... ...
   * If head_skb's headlen does not fit requested gso_size, it
   * means that the frag_list members do NOT terminate on exact
   * gso_size boundaries.

I don't understand whe head_skb's headlen has to fit requested gso_size, and if it doesn't, how could it mean "the frag_list members do NOT terminate on exact gso_size boundaries"

Can't the head_skb to have data of multiple size of gso_size, and the data has a little bit(not in gso_size) in the head part of sk_buff? and the code in the skb_segment() seems do copy that bit of data in the head part regardless of the gso_size checks.

        skb_copy_from_linear_data_offset(head_skb, offset,
                         skb_put(nskb, hsize), hsize);

Do anybody have any idea?

Thanks.

How to send and receive a struct through netlink?

$
0
0

I'm trying to send a struct from user-space to my module in kernel space using netlink, my struct in the user-space is:

struct test{
  unsigned int length;
  char name[MAX_NAME_LENGTH];
};

and in the kernel space is:

struct test{
  __u32 length;
  char name[MAX_NAME_LENGTH];
};

where MAX_NAME_LENGTH is a macro defined to be equal 50.

In the user-space, I've the function main which send my struct to the kernel with the following code:

int main(){

    struct iovec iov[2];
    int sock_fd;
    struct sockaddr_nl src_add;
    struct sockaddr_nl dest_add;
    struct nlmsghdr * nl_hdr = NULL;
    struct msghdr msg; 

    struct test message;
    memset(&message, 0, sizeof(struct test));
    message.length = 18;
    strcpy(message.name, "Just a test\0");

    sock_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_USER);

    if (sock_fd < 0){
        printf("Netlink socket creation failed\n");
        return -1;
    }

    memset(&src_add, 0, sizeof(src_add));
    src_add.nl_family = AF_NETLINK;
    src_add.nl_pid    = getpid();

    memset(&dest_add, 0, sizeof(dest_add));
    dest_add.nl_family = AF_NETLINK;
    dest_add.nl_pid    = 0; // Send to linux kernel
    dest_add.nl_groups = 0; // Unicast

    bind(sock_fd,(struct sockaddr *)&src_add,sizeof(src_add));

    nl_hdr = (struct nlmsghdr *) malloc(NLMSG_SPACE(sizeof(struct test)));

    memset(nl_hdr, 0, NLMSG_SPACE(sizeof (struct test)));

    nl_hdr->nlmsg_len   = NLMSG_SPACE(sizeof(struct test));
    nl_hdr->nlmsg_pid   = getpid();
    nl_hdr->nlmsg_flags = 0;

    iov[0].iov_base = (void *)nl_hdr;
    iov[0].iov_len  = nl_hdr->nlmsg_len;
    iov[1].iov_base = &message;
    iov[1].iov_len  = sizeof(struct test);

    memset(&msg,0, sizeof(msg));
    msg.msg_name    = (void *)&dest_add;
    msg.msg_namelen = sizeof(dest_add);
    msg.msg_iov     = &iov[0];
    msg.msg_iovlen  = 2;

    sendmsg(sock_fd,&msg,0);

    close(sock_fd);

    return 0;
}

And in the kernel side I've registered a function called callback to be called every time that a message is received, this is the callback function:

static void callback(struct sk_buff *skb){


    struct nlmsghdr *nl_hdr;
    struct test * msg_rcv;

    nl_hdr  = (struct nlmsghdr*)skb->data;
    msg_rcv = (struct test*) nlmsg_data(nl_hdr); 

    printk(KERN_INFO "Priting the length and name in the struct:%u, %s\n",msg_rcv->length, msg_rcv->name);

}

When I run these codes and see the dmesg output I receive the following message: Priting the length and name in the struct:0,, so why the fields of the struct filled in the user-space side aren't being sent to the kernel?

Btw, NETLINK_USER is defined as 31.

Viewing all 6330 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>