Hello!
I'm trying compile and run UML (version 4.1) on x86_64. It builds and
runs fine as a normal program. But when run under gdb, it produces
several segmentation faults.

This is how I build and run it (based on
http://user-mode-linux.sourceforge.net/hacking.html instructions and
disk image from http://fs.devloop.org.uk/ ):
cd linux &&
make mrproper &&
make mrproper ARCH=um &&
git checkout v4.1 &&
make defconfig ARCH=um &&
make -j6 ARCH=um &&
cd .. &&
gdb --args linux/linux ubda=BusyBox-1.13.2-amd64-root_fs mem=256m


And this is a complete gdb output:

===========================================================
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from linux/linux...done.
(gdb) r
Starting program: /root/exfat/linux/linux
ubda=BusyBox-1.13.2-amd64-root_fs mem=256m
Core dump limits :
soft - 0
hard - NONE
Core dump limits :
soft - 0
hard - NONE
Core dump limits :
soft - 0
hard - NONE
Core dump limits :
soft - 0
hard - NONE
Checking environment variables for a tempdir...none found
Checking if /dev/shm is on tmpfs...OK
Checking PROT_EXEC mmap in /dev/shm...OK
Core dump limits :
soft - 0
hard - NONE
Checking environment variables for a tempdir...none found
Checking if /dev/shm is on tmpfs...OK
Checking PROT_EXEC mmap in /dev/shm...OK
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Initializing cgroup subsys cpuacct
Linux version 4.1.0 (root@linux64) (gcc version 4.9.2 (GCC) ) #1 Tue
Aug 4 17:31:01 CEST 2015
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 64640
Kernel command line: ubda=BusyBox-1.13.2-amd64-root_fs mem=256m root=98:0
PID hash table entries: 1024 (order: 1, 8192 bytes)
Dentry cache hash table entries: 32768 (order: 6, 262144 bytes)
Inode-cache hash table entries: 16384 (order: 5, 131072 bytes)
Memory: 253796K/262144K available (2471K kernel code, 624K rwdata,
780K rodata, 109K init, 161K bss, 8348K reserved, 0K cma-reserved)
NR_IRQS:15
clocksource itimer: mask: 0xffffffffffffffff max_cycles: 0x1d854df40,
max_idle_ns: 3526361616960 ns
Calibrating delay loop... 2649.29 BogoMIPS (lpj=13246464)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes)
Initializing cgroup subsys blkio
Initializing cgroup subsys devices
Initializing cgroup subsys freezer
Checking that host ptys support output SIGIO...Yes
Checking that host ptys support SIGIO on close...No, enabling workaround
devtmpfs: initialized
Using 2.6 host AIO
clocksource jiffies: mask: 0xffffffff max_cycles: 0xffffffff,
max_idle_ns: 19112604462750000 ns
NET: Registered protocol family 16
Switched to clocksource itimer
NET: Registered protocol family 2
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
NET: Registered protocol family 1
console [stderr0] disabled
mconsole (version 2) initialized on /root/.uml/1BxIWh/mconsole
Checking host MADV_REMOVE support...OK
futex hash table entries: 256 (order: 0, 6144 bytes)
VFS: Disk quotas dquot_6.6.0
VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
io scheduler noop registered
io scheduler deadline registered (default)
NET: Registered protocol family 17
Initialized stdio console driver
Console initialized on /dev/tty0
console [tty0] enabled
Initializing software serial port version 1
console [mc-1] enabled

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff78b16c4 in memset () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff78b16c4 in memset () from /lib64/libc.so.6
#1  0x00000000601b14f3 in check_partition (hd=<optimized out>,
bdev=<optimized out>) at block/partitions/check.c:165
#2  0x00000000601b0abb in rescan_partitions (disk=0x70800000,
bdev=0x0) at block/partition-generic.c:433
#3  0x00000000600e7783 in __blkdev_get (bdev=0x6f802880,
mode=<optimized out>, for_part=0) at fs/block_dev.c:1213
#4  0x00000000600e7c3b in blkdev_get (bdev=0x0, mode=<optimized out>,
holder=0x0) at fs/block_dev.c:1317
#5  0x00000000601ae7e3 in register_disk (disk=<optimized out>) at
block/genhd.c:556
#6  add_disk (disk=0x6fd94000) at block/genhd.c:618
#7  0x0000000060026270 in ubd_disk_register (major=<optimized out>,
size=<optimized out>, unit=1614123056, disk_out=0x603f6340
<ubd_gendisk>) at arch/um/drivers/ubd_kern.c:835
#8  0x0000000060026b1a in ubd_add (n=0, error_out=0x6fc4de90) at
arch/um/drivers/ubd_kern.c:872
#9  0x0000000060003c23 in ubd_init () at arch/um/drivers/ubd_kern.c:1073
#10 0x00000000600184c4 in do_one_initcall (fn=0x60003b5a <ubd_init>)
at init/main.c:788
#11 0x0000000060001e38 in do_initcall_level (level=<optimized out>) at
init/main.c:853
#12 do_initcalls () at init/main.c:861
#13 do_basic_setup () at init/main.c:880
#14 kernel_init_freeable () at init/main.c:1001
#15 0x000000006027ce2f in kernel_init (unused=<optimized out>) at
init/main.c:931
#16 0x0000000060019a7f in new_thread_handler () at arch/um/kernel/process.c:129
#17 0x0000000000000000 in ?? ()
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
n_tty_open (tty=0x6fcb5c00) at drivers/tty/n_tty.c:1929
1929 ldata->overrun_time = jiffies;
(gdb) bt
#0  n_tty_open (tty=0x6fcb5c00) at drivers/tty/n_tty.c:1929
#1  0x00000000601d1f49 in tty_ldisc_open (tty=0x70804288,
ld=<optimized out>) at drivers/tty/tty_ldisc.c:450
#2  0x00000000601d289a in tty_ldisc_setup (tty=0x6fcb5c00, o_tty=0x0)
at drivers/tty/tty_ldisc.c:735
#3  0x00000000601cc503 in tty_init_dev (driver=0x6fdb3d00, idx=0) at
drivers/tty/tty_io.c:1548
#4  0x00000000601cc906 in tty_open (inode=0x6f8001e0, filp=0x6fd2d900)
at drivers/tty/tty_io.c:2091
#5  0x00000000600bce52 in chrdev_open (inode=0x6f8001e0,
filp=0x6fd2d900) at fs/char_dev.c:388
#6  0x00000000600b74c2 in do_dentry_open (f=0x6fd2d900,
open=0x600bcd15 <chrdev_open>, cred=<optimized out>) at fs/open.c:734
#7  0x00000000600b7690 in vfs_open (path=<optimized out>,
filp=<optimized out>, cred=<optimized out>) at fs/open.c:871
#8  0x00000000600c42ad in do_last (nd=0x6fc4de10, path=0x6fc4ddb0,
file=0x6fd2d900, op=<optimized out>, opened=<optimized out>,
name=<optimized out>) at fs/namei.c:3104
#9  0x00000000600c62ca in path_openat (dfd=<optimized out>,
pathname=<optimized out>, nd=0x6fc4de10, op=0x6fc4df0c,
flags=<optimized out>) at fs/namei.c:3243
#10 0x00000000600c7443 in do_filp_open (dfd=-100, pathname=0x6fe37000,
op=0x6fc4df0c) at fs/namei.c:3290
#11 0x00000000600b860e in do_sys_open (dfd=-100, filename=<optimized
out>, flags=<optimized out>, mode=<optimized out>) at fs/open.c:1014
#12 0x00000000600b86e0 in SYSC_open (mode=<optimized out>,
flags=<optimized out>, filename=<optimized out>) at fs/open.c:1032
#13 SyS_open (filename=<optimized out>, flags=<optimized out>,
mode=<optimized out>) at fs/open.c:1027
#14 0x0000000060001e6b in kernel_init_freeable () at init/main.c:1004
#15 0x000000006027ce2f in kernel_init (unused=<optimized out>) at
init/main.c:931
#16 0x0000000060019a7f in new_thread_handler () at arch/um/kernel/process.c:129
#17 0x0000000000000000 in ?? ()
(gdb) c
Continuing.
EXT4-fs (ubda): mounting ext3 file system using the ext4 subsystem
EXT4-fs (ubda): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext3 filesystem) readonly on device 98:0.
devtmpfs: mounted

Program received signal SIGSEGV, Segmentation fault.
n_tty_open (tty=0x6fd16800) at drivers/tty/n_tty.c:1929
1929 ldata->overrun_time = jiffies;
(gdb)
Continuing.
Virtual console 5 assigned device '/dev/pts/1'

Program received signal SIGSEGV, Segmentation fault.
n_tty_open (tty=0x6fd16000) at drivers/tty/n_tty.c:1929
1929 ldata->overrun_time = jiffies;
(gdb)
Continuing.
Serial line 0 assigned device '/dev/pts/2'

Please press Enter to activate this console.
===========================================================


The first fault happens in check_partition(), then several more happen
in some tty code. I investigated the first fault a little and found
this.

1. The memset is called by this line:
  memset(state->parts, 0, state->limit * sizeof(state->parts[0]));

2. I printk-ed its parameters:
  printk("  %s %p %lu\n", __func__, state->parts, state->limit *
sizeof(state->parts[0]));
they look normal:
  check_partition 0000000070800000 2048

3. Even a 1-byte memset produces segfault too:
  memset(state->parts, 0, 1);

4. The memory is allocated by vzalloc() in allocate_partitions().

5. Writing 1 byte with vwrite() does not fault and returns 0.
  vwrite(state->parts, &some_variable, 1);


I tried changing a kernel version (4.0) and a version of gdb (7.7.1) -
it was all the same.

How do I fix this problem and debug UML without getting scary and
disturbing faults?

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-user mailing list
User-mode-linux-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user

Reply via email to