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

How can we tell an instruction is from application code or library code on Linux x86_64

$
0
0

I wanted to know whether an instruction is from userspace or from library code. I observed some application code/data are located at about 0x000055xxxx while libraries and mmaped regions are by default located at 0x00007fcxxxx. Can I use for example, 0x00007f00...00 as a boundary to tell instruction is from the application itself or from the library?

How can I configure this boundary in Linux kernel?


Android TUN interface not working inside Linux-Deploy chroot. Up but no any packets

$
0
0

I am trying to bring up openvpn client on Android 5.0 inside linux-deploy chroot with Debian Buster inside (android kernel 3.10.65)

The tun is up and get ip address, but no any packets transfered. No ping works or any tcp connection. Openvpn successfully keep-alives and didn't drop, stays connected forever. The same config works on my pc. It is not openvpn related. I tried to bring up tun with socat

Socat TUN is also not working http://www.dest-unreach.org/socat/doc/socat-tun.html

socat -d -d -d TCP:10.0.9.77:11443 TUN:192.168.255.2/24,up

2019/10/31 20:32:01 socat[29853] I socat by Gerhard Rieger and contributors - see www.dest-unreach.org
2019/10/31 20:32:01 socat[29853] I This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)
2019/10/31 20:32:01 socat[29853] I This product includes software written by Tim Hudson (tjh@cryptsoft.com)
2019/10/31 20:32:01 socat[29853] N opening connection to AF=2 10.0.9.77:11443
2019/10/31 20:32:01 socat[29853] I starting connect loop
2019/10/31 20:32:01 socat[29853] I socket(2, 1, 6) -> 5
2019/10/31 20:32:01 socat[29853] N successfully connected from local address AF=2 10.0.9.95:52792
2019/10/31 20:32:01 socat[29853] I setting option "iff-up" to 1
2019/10/31 20:32:01 socat[29853] N creating tunnel network interface
2019/10/31 20:32:01 socat[29853] I open("/dev/net/tun", 02, 0666) -> 6
2019/10/31 20:32:01 socat[29853] I socket(2, 2, 0) -> 7
2019/10/31 20:32:01 socat[29853] I resolved and opened all sock addresses
2019/10/31 20:32:01 socat[29853] N starting data transfer loop with FDs [5,5] and [6,6]
2019/10/31 20:32:01 socat[29853] N socket 1 (fd 5) is at EOF
2019/10/31 20:32:02 socat[29853] I poll timed out (no data within 0.500000 seconds)
2019/10/31 20:32:02 socat[29853] I shutdown(5, 2)
2019/10/31 20:32:02 socat[29853] N exiting with status 0

The firewall is totally clean:

iptables-legacy -X
iptables-legacy -t raw -X
iptables-legacy -t nat -X
iptables-legacy -t mangle -X
iptables-legacy -t raw -F
iptables-legacy -t nat -F
iptables-legacy -t mangle -F
iptables-legacy -F

If I run socat-server on android, and my computer as client - both tun0 up, but no ping.

I found on google about android: Only NET_ADMIN is allowed to fully control TUN interfaces

What is means? Maybe CONFIG_PARANOID_NETWORK causes problems?

I tried to usermod -a -G 300{1,2,3,4,5} root but it not helped.

Please help to get packets inside tun interface.

how to mmap a block device request to user space?

$
0
0

My solution is creating a char device bound to the block device. And implementing the mmap related interface of char device. Each time the block device gets the request, tell the char device to mmap the bv_page to the user space.

But there is some issue when handling page fault.

  1. the bv_page is locked before mmap, so request will wait for ever. Is it possible to return VM_FAULT_LOCKED for page fault handling?

  2. kernel handled backing_dev_info of the page, but the related inode is NULL.

So, I wonder whether my solution is possible?

Or is there any other solution to mmap the block device request to user space?

QA AndroidOS cipher suite setting

$
0
0

How can I order and the cipher suite, the elimination of unnecessary cipher suites in AndroidOS?

I want to know the location of the configuration file

Thank you for taking your time.

Where is linux-vdso.so.1 present on the file system

$
0
0

I am learning about VDSO, wrote a simple application which calls gettimeofday()

#define _GNU_SOURCE
#include <sys/syscall.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    struct timeval current_time;

    if (gettimeofday(&current_time, NULL) == -1)
        printf("gettimeofday");

    getchar();

    exit(EXIT_SUCCESS);
}

ldd on the binary shows 'linux-vdso'

$ ldd ./prog
    linux-vdso.so.1 (0x00007ffce147a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6ef9e8e000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f6efa481000)

I did a find for the libvdso library and there is no such library present in my file system.

sudo find / -name 'linux-vdso.so*'

Where is the library present?

How to pass struct to system call, then copy kernel data to that struct

$
0
0

I am trying to pass a struct pointer to a custom system call and then copy the kernel data to the user space.

My main problem is that I have trouble debugging where the problem is. That can be explained by the fact that I am fairly new to the C programming language and while also modifying the kernel source.

So far, I've tried the following:

The struct (just a simplified version of the actual one that the user space program uses (mystruct.h)):

struct mystruct {
    pid_t pid;
        //...
};

My custom call itself:

struct mystruct {
    pid_t pid;
        //...
};

asmlinkage long sys_mysyscall(struct mystruct __user *userStructPtr){
    struct mystruct kernelData;

    if(!userStructPtr){
        return -EFAULT;
    }

    //Insert kernel data into struct
    kernelData.pid = current->pid;
    //...

    //Copy kernelData to userStructPtr (user space)
    if(copy_to_user(userStructPtr, &kernelData, sizeof(kernelData))){
        return -EFAULT;
    }

    return 0;
}

And finally my program that tests it:

int main (void) {
    struct mystruct userStruct;
    printf("%ld\n", syscall(sys_mysyscall, &userStruct));
    printf("PID: %d\n", userStruct.pid);
        return 0;
}

I tried debugging as best as I can. As such, I know I can successfully call my custom system call (thanks to printk) but it returns -1. Plus, I know that the data that I'm inserting into kernelData is good (eg: current->pid yields the right PID). The output of my test program isn't the same as the data inserted into kernelData.

As so, I am unable to find why copy_to_user fails.

Any answer would be greatly appreciated.

Sysfs kernel interaction without user-space application

$
0
0

I am working on a Linux device driver for a piece of hardware that relies on some configuration specific to each implementation. On the first boot-up, we require a user-space application to generate this configuration data through a calibration process. Naturally, I would store this configuration data in a file and read this file when the driver is loaded or the hardware is configured. Reading from a file from inside kernel-space, however, is highly discouraged.

All user-space/kernel-space interaction should occur through the sysfs interface. This confuses me a little bit for two reasons:

  1. The sysfs file-system is virtual, so every time the kernel is booted, the user (or user-space application) would have to write the configuration data to the sysfs filesystem for the kernel to use it.
  2. The driver probe function is run long before a user-space application would have the the ability to write to sysfs.

Are my assumptions about sysfs correct? How would I be able to get this configuration data to the kernel without having to rely on a user-space application to write it to sysfs?

Linux kernel fails to detect rootfs from SD card while booting

$
0
0

I am trying to manually build a mainline kernel and boot in Pine64_Plus board. Linux kernel unable to mount the boot partition. And wierdly it doesn't display any partition under available partition in boot log. I did the below steps. Cloned the linux mainline git repo

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --depth=1

Installed the cross compiler tool chain.

and then..

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make defconfig
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j4 Image

Generated the dtb

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j4 dtbs

Generated the kernel modules

ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make -j4 modules
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=ker_mod_temp_dir make modules modules_install

Partitioned the SD card like below enter image description here

I kept the MLO, Uboot and firmware files in the boot partition.

I downloaded the ArchLinux rootfs from here

I copied the downloaded rootfs to the ROOTFS partition of my SD card.

sudo cp -rT <path-to-downloaded-rootfs> /media/user/ROOTFS

I copied the linux image and dts folder from /arch/arm64/boot to boot folder in the rootfs.

I copied the kernel modules to roots

sudo cp -rT ker_mod_temp_dir /media/user/ROOTFS/lib

enter image description here

I tried to boot the board with the SD card. Uboot successfully boots up. I gave the below commands in Uboot to load the kernel.

setenv kernel_addr_r 0x42000000
setenv dtb_addr_r 0x48000000
ext4load mmc 0:2 $kernel_addr_r /boot/Image
ext4load mmc 0:2 $dtb_addr_r /boot/dts/allwinner/sun50i-a64-pine64-plus.dtb
setenv bootargs console=ttyS0,115200 earlyprintk ignore_loglevel root=/dev/mmcblk0p2 rootfstype=ext4 rw
booti $kernel_addr_r - $dtb_addr_r

Linux kernel boots but it ends with error - [ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---

Boot log

sunxi#booti $kernel_addr_r - $dtb_addr_r
## Flattened Device Tree blob at 48000000
   Booting using the fdt blob at 0x48000000
   Loading Device Tree to 44ff7000, end 44fffba9 ... OK

Starting kernel ...

[mmc]: MMC Device 2 not found
[mmc]: mmc 2 not find, so not exit
INFO:    BL3-1: Next image address = 0x41080000
INFO:    BL3-1: Next image spsr = 0x3c9
[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 5.4.0-rc3 (janani@janani-Vostro-2520) (gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)) #2 SMP PREEMPT Fri Nov 1 13:01:35 IST 2019
[    0.000000] Machine model: Pine64+
[    0.000000] printk: debug: ignoring loglevel setting.
[    0.000000] efi: Getting EFI parameters from FDT:
[    0.000000] efi: UEFI not found.
[    0.000000] cma: Reserved 32 MiB at 0x000000007e000000
[    0.000000] NUMA: No NUMA configuration found
[    0.000000] NUMA: Faking a node at [mem 0x0000000041000000-0x000000007fffffff]
[    0.000000] NUMA: NODE_DATA [mem 0x7dde6800-0x7dde7fff]
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000041000000-0x000000007fffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000041000000-0x000000007fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000041000000-0x000000007fffffff]
[    0.000000] On node 0 totalpages: 258048
[    0.000000]   DMA32 zone: 4032 pages used for memmap
[    0.000000]   DMA32 zone: 0 pages reserved
[    0.000000]   DMA32 zone: 258048 pages, LIFO batch:63
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv0.2 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: Trusted OS migration not required
[    0.000000] percpu: Embedded 22 pages/cpu s52952 r8192 d28968 u90112
[    0.000000] pcpu-alloc: s52952 r8192 d28968 u90112 alloc=22*4096
[    0.000000] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3 
[    0.000000] Detected VIPT I-cache on CPU0
[    0.000000] CPU features: detected: ARM erratum 845719
[    0.000000] CPU features: detected: ARM erratum 843419
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 254016
[    0.000000] Policy zone: DMA32
[    0.000000] Kernel command line: console=ttyS0,115200 earlyprintk ignore_loglevel root=/dev/mmcblk0p2 rootfstype=ext4 rw
[    0.000000] Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.000000] Inode-cache hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 952956K/1032192K available (12156K kernel code, 1860K rwdata, 6420K rodata, 5056K init, 452K bss, 46468K reserved, 32768K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=4.
[    0.000000]  Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] GIC: Using split EOI/Deactivate mode
[    0.000000] random: get_random_bytes called from start_kernel+0x2b8/0x458 with crng_init=0
[    0.000000] arch_timer: Enabling global workaround for Allwinner erratum UNKNOWN1
[    0.000000] arch_timer: CPU0: Trapping CNTVCT access
[    0.000000] arch_timer: cp15 timer(s) running at 24.00MHz (phys).
[    0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[    0.000004] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns
[    0.000656] Console: colour dummy device 80x25
[    0.000738] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=96000)
[    0.000748] pid_max: default: 32768 minimum: 301
[    0.000829] LSM: Security Framework initializing
[    0.000889] Mount-cache hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.000903] Mountpoint-cache hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.024021] ASID allocator initialised with 32768 entries
[    0.032014] rcu: Hierarchical SRCU implementation.
[    0.041639] EFI services will not be available.
[    0.048045] smp: Bringing up secondary CPUs ...
[    5.092138] CPU1: failed to come online
[    5.092145] CPU1: failed in unknown state : 0x0
[   10.216301] CPU2: failed to come online
[   10.216308] CPU2: failed in unknown state : 0x0
[   15.340451] CPU3: failed to come online
[   15.340457] CPU3: failed in unknown state : 0x0
[   15.340505] smp: Brought up 1 node, 1 CPU
[   15.340510] SMP: Total of 1 processors activated.
[   15.340521] CPU features: detected: 32-bit EL0 Support
[   15.340531] CPU features: detected: CRC32 instructions
[   15.346286] CPU: All CPU(s) started at EL2
[   15.346311] alternatives: patching kernel code
[   15.347526] devtmpfs: initialized
[   15.353004] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[   15.353025] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[   15.354219] pinctrl core: initialized pinctrl subsystem
[   15.355443] DMI not present or invalid.
[   15.355817] NET: Registered protocol family 16
[   15.357162] DMA: preallocated 256 KiB pool for atomic allocations
[   15.357176] audit: initializing netlink subsys (disabled)
[   15.358361] cpuidle: using governor menu
[   15.358626] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.
[   15.359812] Serial: AMBA PL011 UART driver
[   15.364601] audit: type=2000 audit(15.344:1): state=initialized audit_enabled=0 res=1
[   15.380908] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[   15.380920] HugeTLB registered 32.0 MiB page size, pre-allocated 0 pages
[   15.380926] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[   15.380933] HugeTLB registered 64.0 KiB page size, pre-allocated 0 pages
[   15.388682] cryptd: max_cpu_qlen set to 1000
[   15.401330] ACPI: Interpreter disabled.
[   15.404770] iommu: Default domain type: Translated 
[   15.404955] vgaarb: loaded
[   15.405266] SCSI subsystem initialized
[   15.408762] libata version 3.00 loaded.
[   15.409025] usbcore: registered new interface driver usbfs
[   15.409065] usbcore: registered new interface driver hub
[   15.409108] usbcore: registered new device driver usb
[   15.409680] pps_core: LinuxPPS API ver. 1 registered
[   15.409686] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[   15.409701] PTP clock support registered
[   15.409802] EDAC MC: Ver: 3.0.0
[   15.416828] FPGA manager framework
[   15.416910] Advanced Linux Sound Architecture Driver Initialized.
[   15.417650] clocksource: Switched to clocksource arch_sys_counter
[   15.417813] VFS: Disk quotas dquot_6.6.0
[   15.417869] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[   15.418051] pnp: PnP ACPI: disabled
[   15.423643] thermal_sys: Registered thermal governor 'step_wise'
[   15.423647] thermal_sys: Registered thermal governor 'power_allocator'
[   15.423942] NET: Registered protocol family 2
[   15.424316] tcp_listen_portaddr_hash hash table entries: 512 (order: 1, 8192 bytes, linear)
[   15.424342] TCP established hash table entries: 8192 (order: 4, 65536 bytes, linear)
[   15.424417] TCP bind hash table entries: 8192 (order: 5, 131072 bytes, linear)
[   15.424565] TCP: Hash tables configured (established 8192 bind 8192)
[   15.424669] UDP hash table entries: 512 (order: 2, 16384 bytes, linear)
[   15.424699] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes, linear)
[   15.424834] NET: Registered protocol family 1
[   15.437311] RPC: Registered named UNIX socket transport module.
[   15.437317] RPC: Registered udp transport module.
[   15.437322] RPC: Registered tcp transport module.
[   15.437326] RPC: Registered tcp NFSv4.1 backchannel transport module.
[   15.437338] PCI: CLS 0 bytes, default 64
[   15.438134] hw perfevents: enabled with armv8_cortex_a53 PMU driver, 7 counters available
[   15.438351] kvm [1]: IPA Size Limit: 40bits
[   15.439050] kvm [1]: vgic interrupt IRQ1
[   15.439134] kvm [1]: Hyp mode initialized successfully
[   15.445931] Initialise system trusted keyrings
[   15.446070] workingset: timestamp_bits=44 max_order=18 bucket_order=0
[   15.453479] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[   15.458294] NFS: Registering the id_resolver key type
[   15.458319] Key type id_resolver registered
[   15.458323] Key type id_legacy registered
[   15.458335] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[   15.458518] 9p: Installing v9fs 9p2000 file system support
[   15.474148] Key type asymmetric registered
[   15.474156] Asymmetric key parser 'x509' registered
[   15.474191] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 245)
[   15.474198] io scheduler mq-deadline registered
[   15.474204] io scheduler kyber registered
[   15.475689] sun50i-de2-bus 1000000.bus: Error couldn't map SRAM to device
[   15.476383] sun4i-usb-phy 1c19400.phy: failed to get clock usb0_phy
[   15.482035] sun50i-a64-r-pinctrl 1f02c00.pinctrl: initialized sunXi PIO driver
[   15.489405] EINJ: ACPI disabled.
[   15.502212] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[   15.504391] SuperH (H)SCI(F) driver initialized
[   15.504889] msm_serial: driver initialized
[   15.513007] loop: module loaded
[   15.517237] libphy: Fixed MDIO Bus: probed
[   15.517519] tun: Universal TUN/TAP device driver, 1.6
[   15.518323] thunder_xcv, ver 1.0
[   15.518361] thunder_bgx, ver 1.0
[   15.518396] nicpf, ver 1.0
[   15.518923] hclge is initializing
[   15.518930] hns3: Hisilicon Ethernet Network Driver for Hip08 Family - version
[   15.518935] hns3: Copyright (c) 2017 Huawei Corporation.
[   15.518990] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
[   15.518994] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[   15.519031] igb: Intel(R) Gigabit Ethernet Network Driver - version 5.6.0-k
[   15.519036] igb: Copyright (c) 2007-2014 Intel Corporation.
[   15.519073] igbvf: Intel(R) Gigabit Virtual Function Network Driver - version 2.4.0-k
[   15.519079] igbvf: Copyright (c) 2009 - 2012 Intel Corporation.
[   15.519367] sky2: driver version 1.30
[   15.519963] VFIO - User Level meta-driver version: 0.3
[   15.525385] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[   15.525393] ehci-pci: EHCI PCI platform driver
[   15.525431] ehci-platform: EHCI generic platform driver
[   15.525709] ehci-platform 1c1a000.usb: EHCI Host Controller
[   15.525733] ehci-platform 1c1a000.usb: new USB bus registered, assigned bus number 1
[   15.525833] ehci-platform 1c1a000.usb: irq 17, io mem 0x01c1a000
[   15.541660] ehci-platform 1c1a000.usb: USB 2.0 started, EHCI 1.00
[   15.542245] hub 1-0:1.0: USB hub found
[   15.542273] hub 1-0:1.0: 1 port detected
[   15.542788] ehci-orion: EHCI orion driver
[   15.542933] ehci-exynos: EHCI EXYNOS driver
[   15.543017] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[   15.543039] ohci-pci: OHCI PCI platform driver
[   15.543101] ohci-platform: OHCI generic platform driver
[   15.543243] ohci-platform 1c1a400.usb: Generic Platform OHCI controller
[   15.543262] ohci-platform 1c1a400.usb: new USB bus registered, assigned bus number 2
[   15.543356] ohci-platform 1c1a400.usb: irq 18, io mem 0x01c1a400
[   15.606146] hub 2-0:1.0: USB hub found
[   15.606173] hub 2-0:1.0: 1 port detected
[   15.606637] ohci-exynos: OHCI EXYNOS driver
[   15.607181] usbcore: registered new interface driver usb-storage
[   15.610102] sun6i-rtc 1f00000.rtc: registered as rtc0
[   15.610111] sun6i-rtc 1f00000.rtc: RTC enabled
[   15.610335] i2c /dev entries driver
[   15.614705] sdhci: Secure Digital Host Controller Interface driver
[   15.614711] sdhci: Copyright(c) Pierre Ossman
[   15.615069] Synopsys Designware Multimedia Card Interface Driver
[   15.615953] sdhci-pltfm: SDHCI platform and OF driver helper
[   15.617242] ledtrig-cpu: registered to indicate activity on CPUs
[   15.618422] usbcore: registered new interface driver usbhid
[   15.618428] usbhid: USB HID core driver
[   15.624090] NET: Registered protocol family 17
[   15.624260] 9pnet: Installing 9P2000 support
[   15.624313] Key type dns_resolver registered
[   15.624694] registered taskstats version 1
[   15.624700] Loading compiled-in X.509 certificates
[   15.637906] sun50i-a64-r-pinctrl 1f02c00.pinctrl: 1f02c00.pinctrl supply vcc-pl not found, using dummy regulator
[   15.638123] sunxi-rsb 1f03400.rsb: RSB running at 3030303 Hz
[   15.638499] axp20x-rsb sunxi-rsb-3a3: AXP20x variant AXP803 found
[   15.650253] dcdc1: supplied by regulator-dummy
[   15.650589] dcdc2: supplied by regulator-dummy
[   15.650808] dcdc4: supplied by regulator-dummy
[   15.651048] dcdc5: supplied by regulator-dummy
[   15.651111] vcc-dram: Bringing 1500000uV into 1360000-1360000uV
[   15.651308] dcdc6: supplied by regulator-dummy
[   15.651509] dc1sw: supplied by regulator-dummy
[   15.651697] aldo1: supplied by regulator-dummy
[   15.651903] aldo2: supplied by regulator-dummy
[   15.652139] aldo3: supplied by regulator-dummy
[   15.652380] dldo1: supplied by regulator-dummy
[   15.652598] dldo2: supplied by regulator-dummy
[   15.652814] dldo3: supplied by regulator-dummy
[   15.653048] dldo4: supplied by regulator-dummy
[   15.653277] eldo1: supplied by regulator-dummy
[   15.653506] eldo2: supplied by regulator-dummy
[   15.653768] eldo3: supplied by regulator-dummy
[   15.653995] fldo1: supplied by regulator-dummy
[   15.654231] fldo2: supplied by regulator-dummy
[   15.654484] rtc-ldo: supplied by regulator-dummy
[   15.654666] ldo-io0: supplied by regulator-dummy
[   15.654876] ldo-io1: supplied by regulator-dummy
[   15.655073] axp20x-rsb sunxi-rsb-3a3: AXP20X driver loaded
[   15.659737] sun50i-a64-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver
[   15.660680] sun50i-a64-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pb not found, using dummy regulator
[   15.661132] printk: console [ttyS0] disabled
[   15.681709] 1c28000.serial: ttyS0 at MMIO 0x1c28000 (irq = 26, base_baud = 1500000) is a U6_16550A
[   16.928325] printk: console [ttyS0] enabled
[   16.934096] ehci-platform 1c1b000.usb: EHCI Host Controller
[   16.939689] ehci-platform 1c1b000.usb: new USB bus registered, assigned bus number 3
[   16.947533] ehci-platform 1c1b000.usb: irq 19, io mem 0x01c1b000
[   16.965665] ehci-platform 1c1b000.usb: USB 2.0 started, EHCI 1.00
[   16.972292] hub 3-0:1.0: USB hub found
[   16.976092] hub 3-0:1.0: 1 port detected
[   16.981558] ohci-platform 1c1b400.usb: Generic Platform OHCI controller
[   16.988223] ohci-platform 1c1b400.usb: new USB bus registered, assigned bus number 4
[   16.996091] ohci-platform 1c1b400.usb: irq 20, io mem 0x01c1b400
[   17.066206] hub 4-0:1.0: USB hub found
[   17.069997] hub 4-0:1.0: 1 port detected
[   17.075561] usb_phy_generic usb_phy_generic.0.auto: usb_phy_generic.0.auto supply vcc not found, using dummy regulator
[   17.086998] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[   17.092774] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus number 5
[   17.101105] hub 5-0:1.0: USB hub found
[   17.104901] hub 5-0:1.0: 1 port detected
[   17.111036] sun50i-a64-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-ph not found, using dummy regulator
[   17.123109] sun50i-a64-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pf not found, using dummy regulator
[   17.133728] sunxi-mmc 1c0f000.mmc: Got CD GPIO
[   17.163428] sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB, uses new timings mode
[   17.172748] sun6i-rtc 1f00000.rtc: setting system clock to 1970-01-01T00:01:49 UTC (109)
[   17.181341] ALSA device list:
[   17.184340]   No soundcards found.
[   17.188171] VFS: Cannot open root device "mmcblk0p2" or unknown-block(0,0): error -6
[   17.195947] Please append a correct "root=" boot option; here are the available partitions:
[   17.204326] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[   17.212579] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc3 #2
[   17.218748] Hardware name: Pine64+ (DT)
[   17.222577] Call trace:
[   17.225026]  dump_backtrace+0x0/0x150
[   17.228685]  show_stack+0x14/0x20
[   17.231997]  dump_stack+0xb0/0xf8
[   17.235308]  panic+0x16c/0x37c
[   17.238360]  mount_block_root+0x1b0/0x2a8
[   17.242362]  mount_root+0x144/0x178
[   17.245845]  prepare_namespace+0x138/0x19c
[   17.249935]  kernel_init_freeable+0x22c/0x24c
[   17.254287]  kernel_init+0x10/0x108
[   17.257772]  ret_from_fork+0x10/0x18
[   17.261348] Kernel Offset: disabled
[   17.264831] CPU features: 0x0002,24002004
[   17.268832] Memory Limit: none
[   17.271888] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---

The below line

Please append a correct "root=" boot option; here are the available partitions:

doesn't display any partition. What could be the reason?

mmc drivers are selected in the config as below CONFIG_MMC_BLOCK=y and CONFIG_MMC_SUNXI=y

What am i doing wrong?


Is there a way to switch to another process context from linux kernel module

$
0
0

I try to change the "current" process to another task as the scheduler do it but it's more complicated than I thought. In other words, I'm looking for KeStackAttachProcess linux equivalent.

Flow: ProcessA -> send ioctl to my device driver with some pid -> In my kernel module I find the task by it's pid ->"context switch" to ProcessB -> do my stuff on this process context

Unable to print the message sent from user space C application to linux kernel module

$
0
0

I have developed a simple linux kernel module :

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>


ssize_t exer_open(struct inode *pinode, struct file *pfile) {

    return 0;
}

ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {

    return 0;
}

ssize_t exer_write(struct file *pfile, const char __user *buffer, size_t length, loff_t *offset) {

    return length;
}

ssize_t exer_close(struct inode *pinode, struct file *pfile) {

    return 0;
}

struct file_operations exer_file_operations = { 
    .owner = THIS_MODULE,
    .open = exer_open,
    .read = exer_read,
    .write = exer_write,
    .release = exer_close,
};

int exer_simple_module_init(void) {

    printk(KERN_ALERT "Inside the %s function\n", __FUNCTION__);
    register_chrdev(240, "Simple Char Drv", &exer_file_operations);
    return 0;
}

void exer_simple_module_exit(void) {

    unregister_chrdev(240, "Simple Char Drv");
}

module_init(exer_simple_module_init);
module_exit(exer_simple_module_exit);

I insert this module to the kernel using insmod command without any problem.

I want to use this module to print a message sent to it by user space program that I have developed too :

#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>


int main()

{

int ret, fd;
char stringToSend[] = "Hello World !";

fd = open("/dev/char_device", O_RDWR);             // Open the device with read/write access

if (fd < 0)
    {
            perror("Failed to open the device...");
            return errno;
    }

ret = write(fd, stringToSend, strlen(stringToSend)); // Send the string to the LKM

if (ret < 0)
    {
            perror("Failed to write the message to the device.");
            return errno;
    }

return 0;

}

When I execute the program and examin the kernel logs using tail -f /var/log/messages command I can see : user.alert kernel: Inside the exer_read function But I cant see the message " Hello World !"

I don't know what I am missing here especially I still beginner in developing modules and using it. Help me please!

Locking on Per CPU variable

$
0
0

I am reading Linux Kernel Development by Robert Love and trying to understand the kernel synchronization mechanism. I am trying to understand some points related to the locking mechanism which is mentioned in the book as follows -


"some situations do not require a spin lock, but do need kernel preemption disabled.The most frequent of these situations is per-processor data. If the data is unique to each processor, there might be no need to protect it with a lock because only that one processor can access the data. If no spin locks are held, the kernel is pre-emptive, and it would be possible for a newly scheduled task to access this same variable.

Consequently, even if this were a uniprocessor computer, the variable could be accessed pseudo-concurrently by multiple processes. Normally, this variable would require a spin lock (to prevent true concurrency on multiprocessing machines). If this were a per- processor variable, however, it might not require a lock.To solve this, kernel preemption can be disabled via preempt_disable()"


So considering a multiprocessor system here - I understand that while per-cpu variable is being manipulated by the current process, another process may be scheduled due to SMP and try to manipulate the same per-cpu variable hence the preemption needs to be disabled as explained in the book. But one point I am not able to understand is that what if we only disable kernel preemption and the current process is trying to manipulate the per-cpu data and at the same time an interrupt occurred on the current processor and since the interrupt has not been disabled, CPU stops the current task and starts executing interrupt handler, Now this handler also want to manipulate the same per-cpu variable. So in this case the variable may ended up containing inconsistent data ?

So does that mean that the interrupt also needs to be disabled on the current processor if the per-cpu variable is also accessed from interrupt handler ?

Platform: Linux on x86

Does my Linux kernel and NIC driver support NIC RX timestamps?

$
0
0

I want to get NIC RX timestamps. This example shows how to obtain them:

https://github.com/majek/openonload/blob/master/src/tests/onload/hwtimestamping/rx_timestamping.c

It contains the below function. Upon running I get an error message output.

static void do_ioctl(struct configuration* cfg, int sock)
{
#ifdef SIOCSHWTSTAMP
  struct ifreq ifr;
  struct hwtstamp_config hwc;
#endif

  if( cfg->cfg_ioctl == NULL )
    return;

#ifdef SIOCSHWTSTAMP
  bzero(&ifr, sizeof(ifr));
  snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", cfg->cfg_ioctl);

  /* Standard kernel ioctl options */
  hwc.flags = 0;
  hwc.tx_type = 0;
  hwc.rx_filter = HWTSTAMP_FILTER_ALL;

  ifr.ifr_data = (char*)&hwc;

  TRY( ioctl(sock, SIOCSHWTSTAMP, &ifr) );
  return;
#else
  (void) sock;
  printf("SIOCHWTSTAMP ioctl not supported on this kernel.\n");     // I get this output
  exit(-ENOTSUP);
  return;
#endif
}

However, when I run the code I get:

SIOCHWTSTAMP ioctl not supported on this kernel

By "kernel", does it mean the NIC driver, or the OS kernel?

I will be switching to use a Solarflare NIC soon and I am unsure whether this will fix the problem, or if the problem is with my Linux kernel?

If I hack it and #define SIOCHWTSTAMP myself I get compile errors not recognizing struct ifreq and struct hwtstamp_config

Linux Ubuntu 18.04 Login Screen

$
0
0

I have a problem with Ubuntu 18.04. After using virtualbox and installing things such as virtualbox guest additions when my computer is starting, keyboard and mouse doesn't work, so I can't login to my computer.(However, I see the difference in the strength of the Wifi and I see changes when I plug/unplug battery)

I have already created bootable usb and I have unistalled virtualbox(with the help of this https://forums.linuxmint.com/viewtopic.php?t=266548), still without any changes.

Do You have any ideas why is it not working? Or do You know where I should look for any logs, which could be a bit more helpful(I have already checked syslog, and boot.log, but without any strange logs).

How do you get debugging symbols working in linux perf tool inside Docker containers?

$
0
0

I am using Docker containers based on the "ubuntu" tag and cannot get linux perf tool to display debugging symbols.

Here is what I'm doing to demonstrate the problem.

First I start a container, here with an interactive shell.

docker run -t -i ubuntu:14.04 /bin/bash

Then from the container prompt I install linux perf tool.

apt-get update
apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`

I can now use the perf tool. My kernel is 3.16.0-77-generic.

Now I'll install gcc, compile a test program, and try to run it under perf record.

apt-get install -y gcc

I paste in the test program into test.c:

#include <stdio.h>

int function(int i) {
    int j;
    for(j = 2; j <= i / 2; j++) {
        if (i % j == 0) {
            return 0;
        }
    }
    return 1;
}

int main() {
    int i;
    for(i = 2; i < 100000; i++) {
        if(function(i)) {
            printf("%d\n", i);
        }
    }
}

Then compile, run, and report: gcc -g -O0 test.c && perf record ./a.out && perf report

The output looks something like this: 72.38% a.out a.out [.] 0x0000000000000544 8.37% a.out a.out [.] 0x000000000000055a 8.30% a.out a.out [.] 0x000000000000053d 7.81% a.out a.out [.] 0x0000000000000551 0.40% a.out a.out [.] 0x0000000000000540

This does not have symbols, even though the executable does have symbol information.

Doing the same general steps outside the container works fine, and shows something like this: 96.96% a.out a.out [.] function 0.35% a.out libc-2.19.so [.] _IO_file_xsputn@@GLIBC_2.2.5 0.14% a.out [kernel.kallsyms] [k] update_curr 0.12% a.out [kernel.kallsyms] [k] update_cfs_shares 0.11% a.out [kernel.kallsyms] [k] _raw_spin_lock_irqsave

In the host system I have already turned on kernel symbols by becoming root and doing: echo 0 > /proc/sys/kernel/kptr_restrict

How do I get the containerized version to work properly and show debugging symbols?

Transfer data from kernel-space to user-space

$
0
0

I am trying to write a system call that can get information about a process in Linux but as the title said, i can't get data from kernel-space. This is my simple code to try to get my student ID from kernel-space.

    struct procinfos {
       long studentID; //for the assignment testing
    };

SYSCALL_DEFINE2(get_proc_info,pid_t, pid, struct procinfos *, info){
            struct procinfos *info1;
            info1->studentID = 1612786;
            int err =(int)copy_to_user(&info->studentID,&info1->studentID,sizeof(info1->studentID));
            printk(KERN_INFO " err =  %d \n",err);
            //printk(KERN_INFO "My ID is %ld\n",info->studentID);
            printk(KERN_INFO " pid =  %d \n",pid); //pid here just for testing whether I pass data to syscall success or fail.
     return EINVAL;
    }

And this is my testing programe(test.c) in user-space.

int main(){
   long sys_return_value;
   struct procinfos info;
   sys_return_value = syscall(548, -1, &info);
   printf("return of sys_get_proc_info is %ld\n",sys_return_value);
   printf("My student ID: %ld\n", info.studentID);
return 0;
}

Finally, what I get is a strange number(not my studentID)

> return of sys_get_proc_info is 22 
My student ID: 94632846337520

How can I fix that ?. Thanks for reading.

P/s:

  • I have tried memcpy() but it's not easy as copy_to_user().
  • I pass "pid" to syscall successfully.
  • If I assign directly in my syscall like info->studentID = 1612786, my test.c will be killed(i really don't know why).
  • I am using linux 5.0.5.

How to open a device file at path: /dev/targetdev?

$
0
0

I have a homework about writing a module in linux kernel. I have declared 2 functions for character driver (open and read). And i can run normally with "sudo cat" command. But when i used user_test.c file to test this module, it doesn't work. It can't open device file at "/dev/targetdev". (In my case, targetdev = "vchar_dev"). Please help me to fix it. Thanks!

//code in module file
static int vchar_driver_open(struct inode *inode, struct file *flip){
 printk("Open successfully\n");
 return 0;
}

//code in user_test.c
#define DEVICE_NODE "/dev/vchar_dev"


int open_chardev() {
    int fd = open(DEVICE_NODE, O_RDWR);
    if(fd < 0) {
        printf("Can not open the device file\n");
        exit(1);
    }
    return fd;
}

How to write to protected pages in the Linux kernel?

$
0
0

I am trying to add a syscall in a module. My rationale is:

  1. This is for a research project, so the exact implementation does not matter.
  2. Adding syscalls in the kernel-core takes a prohibitively long time to re-compile. I can suck up compiling once with an expanded syscall table, but not every time. Even with incremental compiling, linking and archiving the final binary takes a long time.
  3. Since the project is timing sensitive, using kprobes to intercept the syscall handler would slow down the syscall handler.

I am still open to other means of adding a syscall, but for the above reasons, I think that writing to the sys_call_table in a module is the cleanest way to do what I am trying to do.

I've gotten the address of the syscall table from the System.map, disabled kaslr, and I am trying to clear the page protections, but some write-protection is still holding me back.

// following https://web.iiit.ac.in/~arjun.nath/random_notes/modifying_sys_call.html

// clear cr0 write protection
write_cr0 (read_cr0 () & (~ 0x10000));

// clear page write protection
sys_call_table_page = virt_to_page(&sys_call_table[__NR_execves]);
set_pages_rw(sys_call_table_page, 1);

// do write
sys_call_table[__NR_execves] = sys_execves;

However, I'm still getting a permission error, but I don't know the mechanism by which it is enforced:

[   11.145647] ------------[ cut here ]------------
[   11.148893] CR0 WP bit went missing!?
[   11.151539] WARNING: CPU: 0 PID: 749 at arch/x86/kernel/cpu/common.c:386 native_write_cr0+0x3e/0x70
...
Here was a call trace pointing to the write of sys_call_table
...
[   11.332825] ---[ end trace c20c95651874c08b ]---
[   11.336056] CPA  protect  Rodata RO: 0xffff888002804000 - 0xffff888002804fff PFN 2804 req 8000000000000063 prevent 0000000000000002
[   11.343934] CPA  protect  Rodata RO: 0xffffffff82804000 - 0xffffffff82804fff PFN 2804 req 8000000000000163 prevent 0000000000000002
[   11.351720] BUG: unable to handle page fault for address: ffffffff828040e0
[   11.356418] #PF: supervisor write access in kernel mode
[   11.359908] #PF: error_code(0x0003) - permissions violation
[   11.363665] PGD 3010067 P4D 3010067 PUD 3011063 PMD 31e29063 PTE 8000000002804161
[   11.368701] Oops: 0003 [#1] SMP KASAN PTI

full dmesg

Any guesses on how to disable it?

Using dmesg | grep [syscall] not displaying anything

$
0
0

I have written a system call for Linux kernel 5.1 and it is below:

SYSCALL_DEFINE0(helloworld)
{
    printk("helloworld");
    return 0;
}

It is in syscall_64.tbl as the below:

335 common helloworld __x64_sys_helloworld

Below is the test c file:

#include <linux/unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>

#define __NR_helloworld 335
int main(int argc, char *argv[])
{
    syscall(__NR_helloworld);
    return 0;
}

When I run the test file and then dmesg | grep hello nothing displays. How do I get it to display?

Finding a swap device location from the virtual address

$
0
0

With the virtual address, I am trying to find out the exact location of the swap device where the data is stored (e.g., the sector) in my kernel module. I read from here (https://www.kernel.org/doc/gorman/html/understand/understand014.html) that swap entry information is stored in the page table, so I tried something like this:

// Get PTE for the virtual address
mm = current->mm;
pgd = pgd_offset(mm, (unsigned long)addr);  
p4d = p4d_offset(pgd, (unsigned long)addr);
pud = pud_offset(p4d, (unsigned long)addr);
pmd = pmd_offset(pud, (unsigned long)addr);  
pte = pte_offset_map(pmd, (unsigned long)addr);  

// Get swap device position for the PTE
swp_entry = pte_to_swp_entry(*pte);
printk(KERN_INFO "Swap entry: %lu", swp_entry.val);
swap_offset = swp_offset(swp_entry);
printk(KERN_INFO "Swap offset: %lu", swap_offset);

From my understanding, the swap_offset I am getting is an index to a swap_map array, which can be as large as 2^24 entries (covering 64GB of swap space). However, the swap_offset value I am getting is too large, larger than 2^24. With the swap_offset correctly known, my idea was to assume that it represents an offset from swap device starting point (maybe with some division to get the sector number).

Am I understanding something wrong? If I'm totally in the wrong direction, how can I know the swap space location from the virtual address?

Any help is highly appreciated! Thank you.

Kali linux cant move file in other directory [closed]

$
0
0

cant move files other directories with my mouse, but I can copy and paste with ctrl-c/v

Viewing all 12182 articles
Browse latest View live


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