Skip to contentSkip to conversation

syscalls/connect01: bypass bionic connect() implementation

PATCH New Greg Hackmann 3 participants 4 messages Mar 3, 2018 – Mar 6, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/connect01: bypass bionic connect() implementation

The connect01 test segfaults on Android when it gets to the second testcase. bionic's connect() implementation hooks into the netd client library, which in turn expects addr to be a valid pointer.

Work around this by directly calling the kernel connect syscall.

---
 testcases/kernel/syscalls/connect/connect01.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
testcases/kernel/syscalls/connect/connect01.c +17 -0
index 2be83cfbb..e9b9c7945 100644
@@ -116,6 +116,23 @@ int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
 static char *argv0;
 #endif
 
+#ifdef __BIONIC__
+/**
+ * bionic's connect() implementation calls netdClientInitConnect() before
+ * sending the request to the kernel.  We need to bypass this, or the test will
+ * segfault during the addr = (struct sockaddr *)-1 testcase.
+ */
+#include "lapi/syscalls.h"
+
+static int sys_connect(int sockfd, const struct sockaddr *addr,
+		socklen_t addrlen)
+{
+	return ltp_syscall(__NR_connect, sockfd, addr, addrlen);
+}
+
+#define connect(sockfd, addr, addrlen) sys_connect(sockfd, addr, addrlen)
+#endif
+
 int main(int argc, char *argv[])
 {
 	int lc;
Signature · 1 line
2.16.2.395.g2e18187dfd-goog
#1 lore raw

PATCH 1/1 syscalls/connect01: bypass bionic connect() implementation

Hi Greg,

Quoted 29 lines

The connect01 test segfaults on Android when it gets to the second testcase. bionic's connect() implementation hooks into the netd client library, which in turn expects addr to be a valid pointer.

Work around this by directly calling the kernel connect syscall.

---
 testcases/kernel/syscalls/connect/connect01.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
testcases/kernel/syscalls/connect/connect01.c +10 -0
index 2be83cfbb..e9b9c7945 100644
@@ -116,6 +116,23 @@ int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
 static char *argv0;
 #endif
 
+#ifdef __BIONIC__
+/**
+ * bionic's connect() implementation calls netdClientInitConnect() before
+ * sending the request to the kernel.  We need to bypass this, or the test will
+ * segfault during the addr = (struct sockaddr *)-1 testcase.
+ */
+#include "lapi/syscalls.h"
+
+static int sys_connect(int sockfd, const struct sockaddr *addr,
+		socklen_t addrlen)

testcases/kernel/syscalls/connect/connect01.c int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]); · line 138

Quoted 10 lines
testcases/kernel/syscalls/connect/connect01.c +7 -0
+{
+	return ltp_syscall(__NR_connect, sockfd, addr, addrlen);
+}
+
+#define connect(sockfd, addr, addrlen) sys_connect(sockfd, addr, addrlen)
+#endif
+
 int main(int argc, char *argv[])
 {
 	int lc;

Pushed, thanks!

Kind regards,
Petr

#2 lore raw

PATCH 1/1 syscalls/connect01: bypass bionic connect() implementation

Hi!
Maybe it's a good idea to call the raw syscall regardless of the libc implementation since we had cases where tests started to segfault on glibc upgrade or in special conditions where libc had to convert structure layouts between 32bit/64bit userspace/kernel.

Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH 1/1 syscalls/connect01: bypass bionic connect() implementation

Hi,

Quoted 4 lines

Maybe it's a good idea to call the raw syscall regardless of the libc implementation since we had cases where tests started to segfault on glibc upgrade or in special conditions where libc had to convert structure layouts between 32bit/64bit userspace/kernel.

Pushed change where the raw syscall is called regardless of the libc implementation.

Kind regards,
Petr