[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torsocks/master] Add accept as an accepted value through syscall()



commit 3a8d1f2f2002a8d71a0d933aab697d03b3845ab3
Author: David Goulet <dgoulet@xxxxxxxxx>
Date:   Sun Sep 28 13:13:55 2014 -0400

    Add accept as an accepted value through syscall()
    
    This commit adds the accept(2) value to syscall(2) so we can pass it on
    to Tor and not deny it blindly.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
 src/common/compat.h |    5 +++++
 src/lib/syscall.c   |   19 +++++++++++++++++++
 src/lib/torsocks.h  |    1 +
 3 files changed, 25 insertions(+)

diff --git a/src/common/compat.h b/src/common/compat.h
index bda18f0..f572563 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -72,12 +72,16 @@ void tsocks_mutex_unlock(tsocks_mutex_t *m);
 #ifndef __NR_munmap
 #define __NR_munmap -5
 #endif
+#ifndef __NR_accept
+#define __NR_accept -6
+#endif
 
 #define TSOCKS_NR_SOCKET    __NR_socket
 #define TSOCKS_NR_CONNECT   __NR_connect
 #define TSOCKS_NR_CLOSE     __NR_close
 #define TSOCKS_NR_MMAP      __NR_mmap
 #define TSOCKS_NR_MUNMAP    __NR_munmap
+#define TSOCKS_NR_ACCEPT    __NR_accept
 
 #endif /* __linux__ */
 
@@ -95,6 +99,7 @@ void tsocks_mutex_unlock(tsocks_mutex_t *m);
 #define TSOCKS_NR_CLOSE     SYS_close
 #define TSOCKS_NR_MMAP      SYS_mmap
 #define TSOCKS_NR_MUNMAP    SYS_munmap
+#define TSOCKS_NR_ACCEPT    SYS_accept
 
 #endif /* __FreeBSD__, __FreeBSD_kernel__, __darwin__, __NetBSD__ */
 
diff --git a/src/lib/syscall.c b/src/lib/syscall.c
index 9226f86..9de6744 100644
--- a/src/lib/syscall.c
+++ b/src/lib/syscall.c
@@ -68,6 +68,22 @@ static LIBC_CONNECT_RET_TYPE handle_connect(va_list args)
 	return tsocks_connect(sockfd, addr, addrlen);
 }
 
+/*
+ * Handle accept(2) syscall to go through Tor.
+ */
+static LIBC_ACCEPT_RET_TYPE handle_accept(va_list args)
+{
+	int sockfd;
+	struct sockaddr *addr;
+	socklen_t addrlen;
+
+	sockfd = va_arg(args, __typeof__(sockfd));
+	addr = va_arg(args, __typeof__(addr));
+	addrlen = va_arg(args, __typeof__(addrlen));
+
+	return tsocks_accept(sockfd, addr, &addrlen);
+}
+
 #if (defined(__linux__) || defined(__darwin__) || (defined(__FreeBSD_kernel__) && defined(__i386__)))
 /*
  * Handle mmap(2) syscall.
@@ -156,6 +172,9 @@ LIBC_SYSCALL_RET_TYPE tsocks_syscall(long int number, va_list args)
 	case TSOCKS_NR_MUNMAP:
 		ret = handle_munmap(args);
 		break;
+	case TSOCKS_NR_ACCEPT:
+		ret = handle_accept(args);
+		break;
 	default:
 		/*
 		 * Deny call since we have no idea if this call can leak or not data
diff --git a/src/lib/torsocks.h b/src/lib/torsocks.h
index 057a32e..9a99847 100644
--- a/src/lib/torsocks.h
+++ b/src/lib/torsocks.h
@@ -362,6 +362,7 @@ extern TSOCKS_LIBC_DECL(getpeername, LIBC_GETPEERNAME_RET_TYPE,
 
 /* accept(2) */
 extern TSOCKS_LIBC_DECL(accept, LIBC_ACCEPT_RET_TYPE, LIBC_ACCEPT_SIG)
+TSOCKS_DECL(accept, LIBC_ACCEPT_RET_TYPE, LIBC_ACCEPT_SIG)
 #define LIBC_ACCEPT_DECL LIBC_ACCEPT_RET_TYPE \
 		LIBC_ACCEPT_NAME(LIBC_ACCEPT_SIG)
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits