system-calls

Magic numbers of the Linux reboot() system call

你离开我真会死。 提交于 2019-11-29 19:31:27
The Linux Programming Interface has an exercise in Chapter 3 that goes like this: When using the Linux-specific reboot() system call to reboot the system, the second argument, magic2, must be specified as one of a set of magic numbers (e.g., LINUX_REBOOT_MAGIC2). What is the significance of these numbers? (Converting them to hexadecimal provides a clue.) The man page tells us magic2 can be one of LINUX_REBOOT_MAGIC2 (672274793), LINUX_REBOOT_MAGIC2A (85072278), LINUX_REBOOT_MAGIC2B (369367448), or LINUX_REBOOT_MAGIC2C (537993216). I failed to decipher their meaning in hex. I also looked at

How do sites like codepad.org and ideone.com sandbox your program?

狂风中的少年 提交于 2019-11-29 18:57:23
I need to compile and run user-submitted scripts on my site, similar to what codepad and ideone do. How can I sandbox these programs so that malicious users don't take down my server? Specifically, I want to lock them inside an empty directory and prevent them from reading or writing anywhere outside of that, from consuming too much memory or CPU, or from doing anything else malicious. I will need to communicate with these programs via pipes (over stdin/stdout) from outside the sandbox. Angus codepad.org has something based on geordi , which runs everything in a chroot (i.e restricted to a

Why cant i sys_write from a register? [duplicate]

 ̄綄美尐妖づ 提交于 2019-11-29 16:14:21
This question already has an answer here: What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code? 1 answer ; NASM push 30 ; '0' mov rax, 4 ; write mov rbx, 1 ; stdout mov rcx, rsp ; ptr to character on stack mov rdx, 1 ; length of string = 1 int 80h The code above does not print anything to stdout. It works when i give it a ptr to a character in section .data . What am i doing wrong? amd64 uses a different method for system calls than int 0x80 , although that might still work with 32-bit libraries installed, etc. Whereas on x86 one would do: mov eax, SYSCALL_NUMBER mov ebx,

How do I use a Linux System call from a Linux Kernel Module

百般思念 提交于 2019-11-29 14:42:45
I am having some difficulty calling a system call from inside a Linux Kernel Module. The system calls have been tested and work properly from a standard c user space program but I can't seem to get the kernel module to compile and run them. In my user program I include the following code and the system call works: #include <linux/unistd.h> #define __NR_sys_mycall 343 extern long int _syscall(long int_sysno,...)__THROW; //and then a simple call is done as such long value = syscall(__NR_sys_mycall); printf("The value is %ld\n",value); But when I try the same thing in my Linux Kernel Module I get

Memory access error sys_rt_sigaction (signal handler)

泄露秘密 提交于 2019-11-29 11:45:04
Following this Interfacing Linux Signals article, i have been trying to use sys_rt_sigaction in amd64 , but always get memory access error when sending the signal. struct sigaction works when using C/C++ function sigaction . What is wrong in sys_rt_sigaction call? C/C++ with ASM code: #include<signal.h> #include<stdio.h> #include<time.h> void handler(int){printf("handler\n");} void restorer(){asm volatile("mov $15,%%rax\nsyscall":::"rax");} struct sigaction act{handler}; timespec ts{10,0}; int main(){ act.sa_flags=0x04000000; act.sa_restorer=&restorer; //* asm volatile("\ mov $13,%%rax\n\ mov

getrandom syscall in C not found

♀尐吖头ヾ 提交于 2019-11-29 10:11:40
The problem was resolved by upgrading the C library. I would like to use the syscall getrandom ( http://man7.org/linux/man-pages/man2/getrandom.2.html ) gcc-5 -std=c11 test.c #include <sys/types.h> #include <sys/stat.h> #include <sys/fcntl.h> #include <errno.h> #include <string.h> #include <signal.h> #include <linux/random.h> #include <sys/syscall.h> int main(void) { void *buf = NULL; size_t l = 5; unsigned int o = 1; int r = syscall(SYS_getrandom, buf, l, o); return 0; } or int main(void) { void *buf = NULL; size_t l = 5; unsigned int o = 1; int r = getrandom(buf, l, o); return 0; } Anyway

Where can I obtain a list of UNIX system calls?

心不动则不痛 提交于 2019-11-29 08:59:31
问题 Where are some lists of system calls on UNIX? This wasn't my original question, but thanks anyway :) 回答1: man 2 syscalls Aside from that, you can look in /usr/include/sys/syscall.h (which on my system merely #includes /usr/include/bits/syscall.h). That's generated at libc build time from kernel syscall list. You can also grep the Linux kernel source for SYSCALL_DEFINE. (I'm not a BSD expert, but I think the equivalent in FreeBSD is SYSCALL_MODULE) 回答2: Read The Fine Manual. For system calls,

OsDev syscall/sysret and sysenter/sysexit instructions enabling

拈花ヽ惹草 提交于 2019-11-29 08:59:21
I am building an 32 bit OS in assembly. I have setup the IDT and I am handling program interruptus through int instruction. How can I enable the syscall and sysenter instructions and how do I handle them/return? Is true that syscall instruction isn't supported in 32 bit by Intel processors so I can't use it? Is true that sysret instruction isn't safe? Do somewhere exist a tutorial for that? EDIT : My main question is how to enable the syscall and sysenter instructions! (No duplication) See the OSdev wiki for details on sysenter , including a note about how to avoid a security/safety problem.

Using interrupt 0x80 on 64-bit Linux [duplicate]

对着背影说爱祢 提交于 2019-11-29 07:28:11
This question already has an answer here: What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code? 1 answer I have a simple 64-bit assembly program which is intended to print an 'O' and 'K' followed by a newline. However, the 'K' is never printed. One of the goals of the programs is to print the value in the lower bits of the rax register as ASCII letter. The program is specifically for 64-bit Linux, written for educational purposes, so there is no need to use C-style system calls. I suspect that the problem either lies with mov QWORD [rsp], rax or mov rcx, rsp . Currently, the

In Linux, on entry of a sys call, what is the value in %eax? (not orig_eax)

不想你离开。 提交于 2019-11-29 07:10:56
When a syscall returns, I get the syscall return value in %eax, however on entry I am getting -38, which is 0xFFFFFFDA in hex. This is for both write/read. What is this number? Can it be used to safely differentiate an entry from an exit? The -38 in eax on syscall entry is apparently ENOSYS (Function not implemented), and is put there by syscall_trace_entry in arch/x86/kernel/entry_32.S. I suppose it's safe to assume that it will always be there on syscall entry, however it can also be there on syscall exit , if the syscall returns ENOSYS. Personally, I have always just kept track of whether I