From: Zoltan Menyhart <Zoltan.Menyhart_AT_bull.net@nospam.org>
To: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org
Subject: Dynamic System Calls & System Call Hijacking - demo user program
Date: Tue, 20 Apr 2004 11:09:46 +0200 [thread overview]
Message-ID: <4084E8DA.D63CCFCE@nospam.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: test.c --]
[-- Type: text/plain, Size: 1329 bytes --]
#include <linux/sys.h> /* For NR_syscalls */
#include <asm/unistd.h> /* For __NR_ni_syscall */
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <asm/fcntl.h> /* For O_RDONLY */
#define MY_SYSCALL "/proc/sys/kernel/dynamic_syscalls/foo"
/*
* Read out my actual system call number from "/proc/...".
*
* On error "-1" is returned and "errno" is set accordingly.
*/
static inline
get_my_syscall_no(void)
{
int fd;
int tmp;
char buff[5]; /* Should be enough :-) */
if ((fd = open(MY_SYSCALL, O_RDONLY)) < 0){
errno = ENOSYS;
return -1;
}
tmp = read(fd, buff, sizeof buff - 1);
close(fd);
if (tmp != sizeof buff - 1){
errno = ENOSYS;
return -1;
}
buff[sizeof buff - 1] = '\0';
tmp = atoi(buff);
if (tmp < __NR_ni_syscall || tmp >= __NR_ni_syscall + NR_syscalls){
errno = ENOSYS;
return -1;
}
return tmp;
}
/*
* Wrapper function for my system call.
*/
long
my_syscall(const int arg, const long arg2, const long arg3, const int arg4,
const int arg5)
{
static int syscall_no = -1;
if (syscall_no == -1)
if ((syscall_no = get_my_syscall_no())== -1)
return -1;
return syscall(syscall_no, arg, arg2, arg3, arg4, arg5);
}
main()
{
if (my_syscall(1, 0, 1, 0, 2) == -1)
perror("my syscall");
if (my_syscall(2, 3, 4, 5, 6) == -1)
perror("my syscall");
}
reply other threads:[~2004-04-20 9:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4084E8DA.D63CCFCE@nospam.org \
--to=zoltan.menyhart_at_bull.net@nospam.org \
--cc=Zoltan.Menyhart@bull.net \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox