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

Is there a way to add kexec functionality to busybox initrd?

$
0
0

I have 3 MB of SPI flash on my board and I am able to pack the bzImage, busybox initrd and coreboot ROM into this SPI flash. I am also able to boot to the shell , all using the ROM kernel-as-bootloader.

I have bigger kernel on the USB device. I am also able to detect the USB and mount it. But the problem is busybox does not seem to have kexec utility. I cannot use any other initrd package because my cpio (uncompressed) size should not go beyond 1.4 MB due to memory constraints. U-root has kexec support but the minimal image size easily reaches 3MB or at least, I couldn't find a way to built it lesser than that size.

Hence, is there a way to add kexec support to busybox (compile static binary and copy to initrd? ) or any other initrd package that can suffice the need within 1.4MB size?

EDIT

This post suggests that there may be kexec support available in busybox, but I couldn't find any trace of it. In fact the request to add kexec-tools to busybox was done over a decade ago. But when I did grep in the busybox, I saw no traces of it.


Linux Kernel 4.18.0 , 5.0.0 and above and GNOME 3.30.0 and above not loading , why?

$
0
0

I was trying to install KALI Linux 2019.3 on my laptop , it is of Kernel 5.2.9 and GNOME 3.30.2 from a bootable pendrive. This installations were very easy for me before (i.e. while installing Kali versions 2017.3 and before). But now the newer version of linux OS (any i.e. Kali , Parrot , Ubuntu etc.) based on Kernel 4.14.0 , 4.15.0 , 4.17.0 , 4.18.0 , 4.19.0 and 5.0 , 5.1 , 5.2 and above are not able to load on my laptop. Whenever i boot into this OS's in any way (i.e. Live , Persistence , Install etc.), shows me some error sentences.

AVX2 version of gcm_enc/dec engaged.
AES CTR mode by8 optimization enabled
nvme nvme0: Shutdown timeout set to 8 seconds
nvme nvme0: 8/0/0 default/read/poll queues
 nvme0n1: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
ata1: SATA link down (SStatus 4 SControl 300)

Complete error images are linked below (Different Types)

https://i.stack.imgur.com/cCCIC.jpg

https://i.stack.imgur.com/pyYZm.jpg

https://i.stack.imgur.com/kZAxk.jpg

All the above error screens appear one or the other time.

I tried with all different versions of Linux OS's based on Kernel Kernel 4.18.0 , 5.0.0 and above and Gnome 3.30.0 , but all those was a waste of time.

After all this what i came to know is that my pc is able to load kernel 4.17.0 and below very well , also we need to keep in mind the Gnome 3.28.0 and below.

This happens both in Legacy and UEFI mode.

Please any one give me the solution for this problem , and make my laptop load Kernel 4.18.0 , 5.0.0 and above and also GNOME 3.30.0 and above.

Configuration of my laptop is as follows,

Lenovo S540-15IWL Laptop (ideapad)
Processor: Intel I5-8265U CPU
Bios version: APCN31WW (Latest relese)
SSD: SAMSUNG MZVLB512HAJQ-000L2
Device SCSI\Disk&Ven_NVMe&Prod_SAMSUNG_MZVLB512\5&392c3b2a&0&000000 was migrated.

What is Logger Buffer Sizes Of Developer Option

$
0
0

What is the Logger Buffer Sizes option of developer options?

We have various options like:

  • Off
  • 64 K
  • 256 K
  • 1 M
  • 4 M
  • 16 M

If we are changing the buffer size, do we have any impact in the buffer size of logcat and dmesg utilities. What will be the impact if we are setting the option OFF

Linux latest stable compilation: cannot represent change to vmlinux-gdb.py:

$
0
0

The issue:

  • It's been 20 years since:
    • I last wrote >1K of C code
    • compiled anything >10K source lines
  • My current Distro's support (Ubuntu 16.04) for an 0cf3:e300 Atheros Communications, Inc. WiFi driver is abysmal: 8-12Mbps is the best I get.

What I know about kernel version priorities:

  1. Use your own distro's kernel (out of the question: just too slow)
  2. Use the latest stable kernel
  3. Use the latest LTS kernel

What I've tried:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
git checkout -b stable v5.1.2
cp /boot/config-`uname -r` .config
yes '' | make oldconfig
make -j `getconf _NPROCESSORS_ONLN\' deb-pkg LOCALVERSION=-fab

Which gives me the following error:

dpkg-source: error: cannot represent change to vmlinux-gdb.py:
dpkg-source: error:   new version is symlink to /home/fab-user/Documents/Source/linux/scripts/gdb/vmlinux-gdb.py
dpkg-source: error:   old version is nonexistent

in the following full output:

make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-fab
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
  LEX     scripts/kconfig/lexer.lex.c
  YACC    scripts/kconfig/parser.tab.h
  YACC    scripts/kconfig/parser.tab.c
  HOSTCC  scripts/kconfig/preprocess.o
  HOSTCC  scripts/kconfig/symbol.o
  HOSTCC  scripts/kconfig/lexer.lex.o
  HOSTCC  scripts/kconfig/parser.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --syncconfig Kconfig
  UPD     include/config/kernel.release
make clean
/bin/bash ./scripts/package/mkdebian
  TAR     linux-5.1.2-fab.tar.gz
origversion=$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$//');\
    mv linux-5.1.2-fab.tar.gz ../linux-5.1.2-fab_${origversion}.orig.tar.gz
dpkg-buildpackage -r"fakeroot -u" -a$(cat debian/arch)  -i.git -us -uc
dpkg-buildpackage: source package linux-5.1.2-fab
dpkg-buildpackage: source version 5.1.2-fab-1
dpkg-buildpackage: source distribution xenial
dpkg-buildpackage: source changed by fab-user <fab-user@fab-ux-predator>
dpkg-buildpackage: host architecture amd64
 dpkg-source -i.git --before-build linux
 fakeroot -u debian/rules clean
rm -rf debian/*tmp debian/files
make clean
 dpkg-source -i.git -b linux
dpkg-source: info: using source format '1.0'
dpkg-source: warning: source directory 'linux' is not <sourcepackage>-<upstreamversion> 'linux-5.1.2-fab-5.1.2-fab'
dpkg-source: warning: .orig directory name linux.orig is not <package>-<upstreamversion> (wanted linux-5.1.2-fab-5.1.2-fab.orig)
dpkg-source: info: building linux-5.1.2-fab using existing linux-5.1.2-fab_5.1.2-fab.orig.tar.gz
dpkg-source: info: building linux-5.1.2-fab in linux-5.1.2-fab_5.1.2-fab-1.diff.gz
dpkg-source: error: cannot represent change to vmlinux-gdb.py:
dpkg-source: error:   new version is symlink to /home/fab-user/Documents/Source/linux/scripts/gdb/vmlinux-gdb.py
dpkg-source: error:   old version is nonexistent
dpkg-source: warning: ignoring deletion of file .scmversion, use --include-removal to override
dpkg-source: error: cannot represent change to linux-5.1.1-fab.tar.gz: binary file contents changed
dpkg-source: warning: the diff modifies the following upstream files: 
 .clang-format
 .cocciconfig
 .config.old
 .get_maintainer.ignore
 .mailmap
 .version
 CREDITS
 LICENSES/exceptions/GCC-exception-2.0
 LICENSES/exceptions/Linux-syscall-note
 LICENSES/other/Apache-2.0
 LICENSES/other/CDDL-1.0
 LICENSES/other/GPL-1.0
 LICENSES/other/ISC
 LICENSES/other/Linux-OpenIB
 LICENSES/other/MPL-1.1
 LICENSES/other/X11
 LICENSES/preferred/BSD-2-Clause
 LICENSES/preferred/BSD-3-Clause
 LICENSES/preferred/BSD-3-Clause-Clear
 LICENSES/preferred/GPL-2.0
 LICENSES/preferred/LGPL-2.0
 LICENSES/preferred/LGPL-2.1
 LICENSES/preferred/MIT
 MAINTAINERS
 Module.symvers
 README
dpkg-source: info: use the '3.0 (quilt)' format to have separate and documented changes to upstream files, see dpkg-source(1)
dpkg-source: error: unrepresentable changes to source
dpkg-buildpackage: error: dpkg-source -i.git -b linux gave error exit status 1
scripts/package/Makefile:70: recipe for target 'deb-pkg' failed
make[1]: *** [deb-pkg] Error 1
Makefile:1396: recipe for target 'deb-pkg' failed
make: *** [deb-pkg] Error 2

so I ended up doing:

git checkout -b v4.19.38 v4.19.38

which gives me up to 10MB/S instead of my distro's standard kernel's 12Mbps, and works great, but I need to reboot my machine every 24 hours if I want to keep the full speed of the WiFi Driver.

The question:

Am I doomed to stay on 4.19.38?
Is there a way to get the 4.19.39-5.12 versions working permanently?

What is the difference between possible hrtimer initializations?

$
0
0

According to the hrtimer.h, HRTIMER_MODE_ABS means time value is absolute whereas HRTIMER_MODE_REL means time value is relative to now.

When used in the context of hrtimer_init, CLOCK_MONOTONIC or CLOCK_REALTIME can be also be chosen. This means that hrtimers can be initialized in several ways such as below.

hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);

hrtimer_init(&timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
hrtimer_init(&timer, CLOCK_REALTIME, HRTIMER_MODE_REL);

Upon inspection of hrtimer.c, the 4th intialization has no effect because the clock_id is set back to CLOCK_MONOTONIC if mode is not HRTIMER_MODE_ABS upon initialization.

if (clock_id == CLOCK_REALTIME && mode != HRTIMER_MODE_ABS)
        clock_id = CLOCK_MONOTONIC;

So that leaves us with 3 possible behaviours. Now I understand the CLOCK_REALTIME is affected by system time therefore might be discontinuous, whereas CLOCK_MONOTONIC is the opposite (i.e. it is always ticking forward).

The following is my understanding of the possible behaviours, but they seem way too similar and I am unsure which to choose.

1) hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);

The clock is continuous and time always expires after an absolute time of N. Changes in system time does not affect the clock therefore it does not affect expiry time.

2) hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);

The clock is continuous and time expires N time from now. Changes in system time does not affect the clock therefore it does not affect expiry time from 'now'.

3) hrtimer_init(&timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);

The clock can be set but any changes to system clock still does not affect expiry, because the timer is set to expire at an absolute time of N.

I realized my interpretation could be wrong because the behaviours all look similar. Can anyone shed light on this?

How to set a global nofile limit to avoid "many open files" error?

$
0
0

I have a websocket service. it's strage that have error:"too many open files", but i have set the system configure:

/etc/security/limits.conf
*               soft    nofile          65000
*               hard    nofile          65000

/etc/sysctl.conf
net.ipv4.ip_local_port_range = 1024 65000

ulimit -n
//output 6500

So i think my system configure it's right.

My service is manage by supervisor, it's possible supervisor limits?

check process start by supervisor:

cat /proc/815/limits
Max open files            1024                 4096                 files 

check process manual start:

cat /proc/900/limits
Max open files            65000                 65000                 files 

The reason is used supervisor manage serivce. if i restart supervisor and restart child process, it's "max open files" ok(65000) but wrong(1024) when reboot system supervisor automatically start.

May be supervisor start level is too high and system configure does not work when supervisor start?

edit:

system: ubuntu 12.04 64bit

It's not supervisor problem, all process auto start after system reboot are not use system configure(max open files=1024), but restart it's ok.

update

Maybe the problem is:

Now the question is, how to set a global nofile limit because i don't want to set nofile limit in every upstart script which i need.

How to export kernel functions which written in assembly?

$
0
0

I am working with a PowerPC processor and have to use dcache functions in my kernel module, like: "clean_dcache_range()", implemented in $KERNEL_SOURCE/arch/powerpc/kernel/misc_32.S. this assembly file is compiled during kernel compilation (version 4.1.8) and misc_32.o object file exists in kernel build directory.
However, i can't use this functions in my kernel module and the error "implicit declaration of function" appears when i compile the module using gcc.
Also, the Module.symvers file does not contain these functions. Note that, the mentioned functions are declared as _GLOBAL.
So, what is the problem and how can i solve it?

Adding support for menuconfig / Kconfig in my project

$
0
0

I am planning to add support for menuconfig in my project. The project is not associated with Linux kernel so, I have to write everything from scratch in menuconfig and Makefile.

How do I add support for menuconfig and create Kconfig and make the makefile read the defines in .config?

Any good tutorial to begin with?


Linux interrupt notification to user-space

$
0
0

I am using Linux kernel with preempt-rt patch, I did a a simple test to measure time between interrupt and notification of the interrupt to userspace. The idea is quite simple I have a module, that implements a read:

static ssize_t my_read(struct file *filp, char __user *buf, size_t count,loff_t *f_pos)
{
   atomic_set(&intflag, 0);
   if (wait_event_interruptible(my_hack, atomic_read(&intflag) != 0))
        return -ERESTARTSYS;
   do_gettimeofday(&tv2);
   trace_printk("wait_event_interruptible% d\n",(int) (tv2.tv_usec - tv1.tv_usec));
    return 0;
}

then from the interrupt routine I wake the read:

static irqreturn_t

my_interrupt(int irq, void *dev_id)
{
 ...
 atomic_set(&intflag,1);
 do_gettimeofday(&tv1);
 wake_up_interruptible(&mm_fec_hack);

return IRQ_HANDLED;
}

The value printed is around 65 and 70 e.g.

myproc-532 [002] ....... 8049.789350: 0xbf0c81f0: wake_up_interruptible 65

My CPU is a 4 core:

model name : ARMv7 Processor rev 10 (v7l) BogoMIPS : 7.54

and frequency is

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 996000

I think that 65-70 us is pretty much to wakeup a process.

I tried to change irq and process priority with chrt and to relegate the irq to a specific core with smp_affinity and process to the same core or different core with taskset but the results basically are not changing.

What am I doing wrong?

Zero-copy user-space TCP send of dma_mmap_coherent() mapped memory

$
0
0

I'm running Linux 5.1 on a Cyclone V SoC, which is an FPGA with two ARMv7 cores in one chip. My goal is to gather lots of data from an external interface and stream (part of) this data out through a TCP socket. The challenge here is that the data rate is very high and could come close to saturating the GbE interface. I have a working implementation that just uses write() calls to the socket, but it tops out at 55MB/s; roughly half the theoretical GbE limit. I'm now trying to get zero-copy TCP transmission to work to increase the throughput, but I'm hitting a wall.

To get the data out of the FPGA into Linux user-space, I've written a kernel driver. This driver uses a DMA block in the FPGA to copy a large amount of data from an external interface into DDR3 memory attached to the ARMv7 cores. The driver allocates this memory as a bunch of contiguous 1MB buffers when probed using dma_alloc_coherent() with GFP_USER, and exposes these to the userspace application by implementing mmap() on a file in /dev/ and returning an address to the application using dma_mmap_coherent() on the preallocated buffers.

So far so good; the user-space application is seeing valid data and the throughput is more than enough at >360MB/s with room to spare (the external interface is not fast enough to really see what the upper bound is).

To implement zero-copy TCP networking, my first approach was to use SO_ZEROCOPY on the socket:

sent_bytes = send(fd, buf, len, MSG_ZEROCOPY);
if (sent_bytes < 0) {
    perror("send");
    return -1;
}

However, this results in send: Bad address.

After googling for a bit, my second approach was to use a pipe and splice() followed by vmsplice():

ssize_t sent_bytes;
int pipes[2];
struct iovec iov = {
    .iov_base = buf,
    .iov_len = len
};

pipe(pipes);

sent_bytes = vmsplice(pipes[1], &iov, 1, 0);
if (sent_bytes < 0) {
    perror("vmsplice");
    return -1;
}
sent_bytes = splice(pipes[0], 0, fd, 0, sent_bytes, SPLICE_F_MOVE);
if (sent_bytes < 0) {
    perror("splice");
    return -1;
}

However, the result is the same: vmsplice: Bad address.

Note that if I replace the call to vmsplice() or send() to a function that just prints the data pointed to by buf (or a send()withoutMSG_ZEROCOPY), everything is working just fine; so the data is accessible to userspace, but the vmsplice()/send(..., MSG_ZEROCOPY) calls seem unable to handle it.

What am I missing here? Is there any way of using zero-copy TCP sending with a user-space address obtained from a kernel driver through dma_mmap_coherent()? Is there another approach I could use?

unable to commit image from docker container

$
0
0

enter image description here

We had stopped a docker container named "fig_extractor", and its source docker image was deleted. I need to start the container in different port (at the time of run port is 8010, but now I need to run the container in 8009 port).

I try to commit the image using

docker commit <container-Id> <new_image_name:v1>

but got error like " no such file or directory ", which I think may be due to the removal of that source image.

How can I resolve that?

Android input: msissing ABS_MT_SLOT event from getevent -trl list

$
0
0

I am trying to get multi-touch screen working using Multi-touch protocol type B. Using getevent -il I can see that all the events I want to send recognized. However ABS_MT_SLOT event never comes up in the list, though my device is sending it for sure. Can't figure out what is causing ABS_MT_SLOT events to vanish.

getevent outputs:

getevent -il
could not get driver version for /dev/input/mice, Not a typewriter
add device 1: /dev/input/event1
  bus:      0006
  vendor    0000
  product   0000
  version   0000
  name:     "QVM virtio-input (pointer)"
  location: "virtio3/input0"
  id:       ""
  version:  1.0.1
  events:
    KEY (0001): BTN_MOUSE             BTN_RIGHT             BTN_MIDDLE            BTN_SIDE             
    REL (0002): REL_X                 REL_Y                 REL_HWHEEL            REL_WHEEL            
  input props:
    INPUT_PROP_POINTER
add device 2: /dev/input/event0
  bus:      0006
  vendor    0000
  product   0000
  version   0000
  name:     "QVM virtio-input (touchscreen)"
  location: "virtio2/input0"
  id:       ""
  version:  1.0.1
  events:
    ABS (0003): ABS_MT_SLOT           : value 0, min 0, max 6, fuzz 0, flat 0, resolution 0
                ABS_MT_POSITION_X     : value 0, min 0, max 1279, fuzz 0, flat 0, resolution 0
                ABS_MT_POSITION_Y     : value 0, min 0, max 719, fuzz 0, flat 0, resolution 0
                ABS_MT_TOOL_TYPE      : value 0, min 0, max 0, fuzz 0, flat 0, resolution 0
                ABS_MT_BLOB_ID        : value 0, min 0, max 0, fuzz 0, flat 0, resolution 0
                ABS_MT_TRACKING_ID    : value 0, min 0, max 1000, fuzz 0, flat 0, resolution 0
  input props:
    INPUT_PROP_DIRECT



getevent -trl

could not get driver version for /dev/input/mice, Not a typewriter
add device 1: /dev/input/event1
  name:     "QVM virtio-input (pointer)"
add device 2: /dev/input/event0
  name:     "QVM virtio-input (touchscreen)"
add device 3: /dev/input/event2
  name:     "QVM virtio-input (keyboard)"
could not get driver version for /dev/input/mouse0, Not a typewriter
2
[     403.929099] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     403.929099] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    0000011b            
[     403.929099] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    0000009c            
[     403.929099] /dev/input/event0: EV_SYN       SYN_REPORT           00000000            
[     403.990164] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     403.990164] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    0000011c            
[     403.990164] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    0000009e            
[     403.990164] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 16
[     404.000828] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.000828] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    0000011d            
[     404.000828] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    0000009f            
[     404.000828] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 93
[     404.013335] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.013335] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    0000011f            
[     404.013335] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    000000a2            
[     404.013335] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 79
[     404.024190] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.024190] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    00000122            
[     404.024190] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    000000a6            
[     404.024190] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 92
[     404.032932] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.032932] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    00000127            
[     404.032932] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    000000ab            
[     404.032932] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 114
[     404.043514] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.043514] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    0000012c            
[     404.043514] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    000000b2            
[     404.043514] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 94
[     404.057101] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.057101] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    00000133            
[     404.057101] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    000000ba            
[     404.057101] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 73
[     404.065044] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.065044] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    00000139            
[     404.065044] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    000000c3            
[     404.065044] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 125
[     404.070385] /dev/input/event0: EV_ABS       ABS_MT_TRACKING_ID   00000000            
[     404.070385] /dev/input/event0: EV_ABS       ABS_MT_POSITION_X    00000141            
[     404.070385] /dev/input/event0: EV_ABS       ABS_MT_POSITION_Y    000000cc            
[     404.070385] /dev/input/event0: EV_SYN       SYN_REPORT           00000000             rate 187

Is there a way to change Mount-Point after installation of elementaryOS?

$
0
0

I have recently installed elementary OS on a USB drive from a system running Windows 10, but I booted live from elementary OS DVD for installation purposes.

Now every time I boot my PC without the USB drive, an error is displayed:

error: no such device:

error: unknown file system

Entering rescue mode.....

grub rescue>_

From what I learned it seemed that I need to reinstall the OS and change the mount point to where the windows partition is located, but I have already done many changes to the OS so I don't want to lose any of it... So is there any way to change the mount point without reinstalling or any other way to cure this disease?

Drop skb or expand the outgoing skb

$
0
0

When I capture outgoing packet in kernel by using kernel module, I am using kfree_skb() to drop that packet but it does not work and packet arrives its destination point. I check &skb->user is 1.

change_skb(struct sk_buff *skb) receive the original skb and create a new distinct copy (just copy its payload) and send the new skb. This works, I can see my new packet at the receiver side but I cannot drop the original so that I still see the original one at the receiver side.

Here is my code:

int my_pkt_handling(struct sk_buff *skb, struct net_device *dev, struct packet_type *pkt, struct net_device *org_dev) {

struct ethhdr *eth = eth_hdr(skb);
struct iphdr *iph = ip_hdr(skb);
unsigned char dst_addr[] = {0x00, 0x16, 0x41, 0xaa, 0xf8, 0xf0};
unsigned char src_addr[] = {0x00, 0x1f, 0xe2, 0x12, 0xb0, 0x34};

switch (skb->pkt_type) {
    case PACKET_OUTGOING:
        if ( memcmp(eth->h_dest, dst_addr, ETH_ALEN) == 0 && eth->h_proto == htons(ETH_P_IP) ) {                
            printk(KERN_ALERT"Outgoing| Interface: %4s Type: 0x%4x Src: %pI4 Dest: %pI4 Len: %d SizeOf: %lu User#: %d\n", 
                        skb->dev->name, ntohs(eth->h_proto), &iph->saddr, &iph->daddr, skb->len, sizeof(skb), atomic_read(&skb->users));
            change_skb(skb);
            kfree_skb(skb);
            return 0;
        }
        break;
    default:
        break;
}

return 0;

Adding element twice into Linux kernel double linked list

$
0
0

I am trying to use linux kernel doubly linked-list implementation mentioned in https://github.com/torvalds/linux/blob/master/include/linux/list.h in user-space which its user-space implementation can be found in https://gist.github.com/roychen/1710968

following is the code which I used at first and it works fine :)

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "list.h"

struct Node
{
    int data;
    char name[10];
    struct list_head mylist;
};

int main()
{
    LIST_HEAD(plist);

    struct Node node1 = {.data = 10, .name = "node1", .mylist = LIST_HEAD_INIT(node1.mylist)};
    struct Node node2;

    node2.data = 20;
    strcpy(node2.name, "node2");
    INIT_LIST_HEAD(&node2.mylist);

    list_add_tail(&node1.mylist, &plist);
    list_add_tail(&node2.mylist, &plist);

    struct Node* iter;

    list_for_each_entry(iter, &plist, mylist)
    {
        printf("name = %s, data = %d\n", iter->name, iter->data);
    }

    return 0;
}

the output of the above code is

name = node1, data = 10
name = node2, data = 20

which is as expected.

now assume that I want to add node1twice

Scenario number 1:

    list_add_tail(&node1.mylist, &plist);
    list_add_tail(&node1.mylist, &plist);

output 1:

name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
name = node1, data = 10
... -> non-stopping loop (to infinity)

Scenario number 2:

    list_add_tail(&node1.mylist, &plist);
    list_add_tail(&node2.mylist, &plist);
    list_add_tail(&node1.mylist, &plist);

output 2:

name = node1, data = 10 (-> just one node is added to the list instead of 3 nodes)

The above outputs show that the list.h implementation has bug, at least in one of its function macros.

I don't know where is the bug which we cannot add a node twice in the linked list.

Any idea?! :|

***** EDIT ***** Scenario 3:

    list_add_tail(&node1.mylist, &plist);
    list_add_tail(&node2.mylist, &plist);
    list_add_tail(&node1.mylist, &plist);

    struct Node* iter;

    list_for_each_entry_reverse(iter, &plist, mylist)
    {
        printf("name = %s, data = %d\n", iter->name, iter->data);
    }

output 3:

name = node2, data = 20
name = node1, data = 10
name = node2, data = 20
name = node1, data = 10
name = node2, data = 20
name = node1, data = 10
name = node2, data = 20
name = node1, data = 10
name = node2, data = 20
name = node1, data = 10
... -> non-stopping loop (to infinity)

How to send signal from Linux kernel space to user space in order to notify about an input hardware event

$
0
0

My kernel module code needs to send signal to a user land program, to transfer its execution to registered signal handler.

In fact, I have developed a C program for my embedded board which make LED turns on and off when I push BUTTON ( the input event ). On the other hand, I have just developed a simple Linux module with its basic functions ( OPEN, CLOSE, READ, WRITE ).

I just don't have any idea how to modify my principal program and my kernel module in order to arrive to my objective.

I share with you my user space program :

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>

#include <linux/input.h>

#define BTN_FILE_PATH "/dev/input/event0"
#define LED_PATH "/sys/class/leds"

#define green "green"

void change_led_state(char *led_path, int led_value)
{
    char    lpath[64];
    FILE    *led_fd;

    strncpy(lpath, led_path, sizeof(lpath) - 1);
    lpath[sizeof(lpath) - 1] = '\0';

    led_fd = fopen(lpath, "w");

    if (led_fd == NULL) {
        fprintf(stderr, "simplekey: unable to access led\n");
        return;
    }

    fprintf(led_fd, "%d\n", led_value);

    fclose(led_fd);
}

void reset_leds(void)
{

    change_led_state(LED_PATH "/" green "/brightness", 0);
}

int configure_leds(void)
{
    FILE    *r_fd;
    char    *none_str = "none";

    /* Configure leds for hand control */

    r_fd = fopen(LED_PATH "/" green "/trigger", "w");




    fprintf(r_fd, "%s\n", none_str);


    fclose(r_fd);


    /* Switch off leds */
    reset_leds();

    return 0;
}

void eval_keycode(int code)
{

    static int green_state = 0;

    switch (code) {
    case 260:
        printf("BTN left pressed\n");

        /* figure out green state */

        green_state = green_state ? 0 : 1;

        change_led_state(LED_PATH "/" green "/brightness", green_state);
        break;
    }
}


int main(void)
{
    int file;
    /* how many bytes were read */
    size_t  rb;
    int ret;
    int yalv;
    /* the events (up to 64 at once) */
    struct input_event  ev[64];
    char    *str = BTN_FILE_PATH;

    printf("Starting simplekey app\n");

    ret = configure_leds();
    if (ret < 0)
        exit(1);

    printf("File Path: %s\n", str);

    if((file = open(str, O_RDONLY)) < 0) {
        perror("simplekey: File can not open");
        exit(1);
    }

    for (;;) {
        /* Blocking read */
        rb= read(file, &ev, sizeof(ev));

        if (rb < (int) sizeof(struct input_event)) {
            perror("simplekey: short read");
            exit(1);
        }

        for (yalv = 0;
            yalv < (int) (rb / sizeof(struct input_event));
            yalv++) {
            if (ev[yalv].type == EV_KEY) {
                printf("%ld.%06ld ",
                    ev[yalv].time.tv_sec,
                    ev[yalv].time.tv_usec);
                printf("type %d code %d value %d\n",
                        ev[yalv].type,
                        ev[yalv].code, ev[yalv].value);

                /* Change state on button pressed */
                if (ev[yalv].value == 0)
                    eval_keycode(ev[yalv].code);
            }
        }
    }

    close(file);

And this is the basic kernel module :

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/device.h>  
#include <linux/kernel.h>
#include <linux/uaccess.h>
#include <linux/input.h>

MODULE_LICENSE("GPL");      
MODULE_AUTHOR("Gaston");  
MODULE_DESCRIPTION("A simple Linux char driver"); 
MODULE_VERSION("0.1"); 


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

    printk(KERN_INFO "Device has been opened\n");

    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 0;

}   




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

    printk(KERN_INFO "Device successfully closed\n");
    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_INFO "Initializing the LKM\n");
    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 hope you will help me. Thank you!

AOSP black screen between Linux and Android splash screens

$
0
0

The device is running Android 7 + Linux 4.9. Both successfully show a splash screen, but there's a gap of ~6 seconds between the two where the screen is black. How do I start the boot animation directly after the Linux splash screen ends?

I can't really find any topic related to this problem. For one I know that starting the service bootanimon init doesn't solve the problem.

Acccess to /proc/net/tcp in Android Q

$
0
0

In my VPN application up until Android-9, it was possible to read the /proc/net/tcp files from apps targeting API level < 28. Access from apps no longer seems to work in Android Q. I'm getting an error /proc/net/tcp: open failed: EACCES (Permission denied) while trying to read the file.

In Android-Q privacy change google has addressed Restriction on access to /proc/net filesystem

And I think ConnectivityManager.getConnectionOwnerUid() can be used if the apps compileSDK version is 29. But unfortunately at the moment, I can't change my compileSDK version but I updated the targetSDK version to the latest IE, 29.

Any other possible way to read the file in Android-10? Posting my code for reference

public static final int INDEX_UID_COL = 7;
public static final int INDEX_LOCAL_ADDRESS_COL = 1;
public static final String PROC_FILE = "/proc/net/tcp";

 public static String getPackageName(Context context, int srcPort) {
        String packageName = "";
        try {

            BufferedReader br = new BufferedReader(new FileReader(PROC_FILE));

            //Ignore first line
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                /**
                 * Proc file table column sequence
                 * sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
                 */
                String[] parts = line.trim().split("\\s+");
                if (parts.length >= 8) {
                    String localAddress = parts[INDEX_LOCAL_ADDRESS_COL];
                    if (!localAddress.isEmpty()) {
                        String[] localAddressParts = localAddress.split(":");
                        if (localAddressParts.length == 2) {
                            int port = Integer.parseInt(localAddressParts[1], 16);
                            if (port == srcPort) {
                                int uid = Integer.parseInt(parts[INDEX_UID_COL]);
                                packageName = context.getPackageManager().getNameForUid(uid);
                                break;
                            }
                        }
                    }
                }
            }
            br.close();
        } catch (Exception ex) {
            Log.e("ProcFileParser", ex.getMessage());
        }
        return packageName;
    }

RW region on 64 Bit Linux Kernel Android - overwrite system call pointer with mine in userspace

$
0
0

Is that correct that only 0xffffffc000800000 will be RW on 64 bit Kernel? I want to do something crazy ... overwrite system call pointer to execute my code from Userland in Kernelspace (to escape RKP = Realtime Kernel Protection i.e Samsung KNOX) - https://www.blackhat.com/docs/us-17/thursday/us-17-Shen-Defeating-Samsung-KNOX-With-Zero-Privilege-wp.pdf

Platform is Android Samsung S7 Edge Kernel 3.18

4 Questions (all related to this)

1 is that correct that only 0xffffffc000800000 will be RW?

2 Any ideas why ptmx_open in not in that range?

3 if 2 is possible, Any ideas how to overwrite ptmx_fops->check_flags() or fsync() and later call fsync on /dev/ptmx to call it?

ffffffc00042bddc t pty_unix98_shutdown
ffffffc00042be2c t pty_open
ffffffc00042bed4 t pts_unix98_lookup
ffffffc00042bf24 t pty_resize
ffffffc00042c044 t ptmx_open
ffffffc00042c1c0 t pty_write_room
ffffffc00042c1f8 t pty_close
ffffffc00042c354 t pty_unix98_ioct

4 Any ideas how to use those?

ffffffc0008123b8 t cl_enable_fops_open
ffffffc0008123e4 t mif_margin_fops_open
ffffffc000812410 t g3d_margin_fops_open
ffffffc00081243c t cpu_margin_fops_open
ffffffc000a1fcc8 t adv_max_interval_fops_open
ffffffc000a1fcf4 t adv_min_interval_fops_open
ffffffc000a1fd20 t adv_channel_map_fops_open
ffffffc000a1fd4c t supervision_timeout_fops_open
ffffffc000a1fd78 t conn_latency_fops_open
ffffffc000a1fda4 t conn_max_interval_fops_open
ffffffc000a1fdd0 t conn_min_interval_fops_open
ffffffc000a1fdfc t rpa_timeout_fops_open
ffffffc000a1fe28 t sniff_max_interval_fops_open
ffffffc000a1fe54 t sniff_min_interval_fops_open
ffffffc000a1fe80 t idle_timeout_fops_open
ffffffc000a1feac t auto_accept_delay_fops_open
ffffffc000a1fed8 t voice_setting_fops_open
ffffffc000a1ff00 t conn_info_max_age_fops_open
ffffffc000a1ff2c t conn_info_min_age_fops_open

what should I overwrite and what device file will it be (/dev/*)

Since on my device ptmx_fops is not exposed, wanted to do it/find like this:

https://gist.github.com/fi01/5794566 (32 bit example)

How vruntime of a newly created process initialised in CFS scheduler linux ?

$
0
0

In CFS scheduler, it always picks a process with minimum vruntime. vruntime of a running process is increased by the amount of CPU it consumes.

I have following two questions related to CFS and vruntime.

  1. When multiple processes/threads are newly created, what is the initial vruntime of newly created process/thread ? Is the minimum vruntime in that ready queue at that time of creation or something else ?

  2. If one process is there which has already ran for long and its vruntime is already high, in that scenario a new process is created. Now what will be the initial vruntime of newly created process ( keeping is mind the maximum unfairness ).

Viewing all 12196 articles
Browse latest View live