Dynamic System Calls & System Call Hijacking - demo user program

From: Zoltan Menyhart <Zoltan.Menyhart_AT_bull.net_at_nospam.org>
Date: 2004-04-20 19:09:46
 
#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");
}



-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Tue Apr 20 05:19:00 2004

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:25 EST