Skip to contentSkip to conversation

syscalls/sendmmsg: add new test

PATCH New Steve Muckle 3 participants 4 messages Jul 25, 2019 – Jul 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/sendmmsg: add new test

Test basic functionality of sendmmsg and recvmmsg.

---

Changes since v3:
- drop resending of messages on partially successful sendmmsg()
- drop use of pthreads, do message creation and port management in setup/cleanup

Changes since v2:
- fix race between sender and receiver
- use TST_GET_UNUSED_PORT
- fix checkpatch error (it still complains about the // on the SPDX identifier in sendmmsg_var.h, but other headers in this project use that style)
- add SPDX identifier in sendmmsg01.c

Changes since v1:
- rebased on recent autotools cleanup for libc func checks
- used test_variant to test direct syscalls and libc syscalls
- use tst_syscall instead of ltp_syscall
- check that both messages have been sent, retry sending messages if necessary
- use tst_brk(TBROK... if sendmmsg fails so recv thread is not kept waiting

 configure.ac                                  |   3 +
 include/lapi/socket.h                         |   8 ++
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/sendmmsg/.gitignore |   1 +
 testcases/kernel/syscalls/sendmmsg/Makefile   |   9 ++
 .../kernel/syscalls/sendmmsg/sendmmsg01.c     | 126 ++++++++++++++++++
 .../kernel/syscalls/sendmmsg/sendmmsg_var.h   |  60 +++++++++
 7 files changed, 209 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendmmsg/.gitignore
 create mode 100644 testcases/kernel/syscalls/sendmmsg/Makefile
 create mode 100644 testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
 create mode 100644 testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h
configure.ac +3 -0
index 3dcf282e8..5e4e7f1f9 100644
@@ -82,9 +82,11 @@ AC_CHECK_FUNCS([ \
     pwritev \
     pwritev2 \
     readlinkat \
+    recvmmsg \
     renameat \
     renameat2 \
     sched_getcpu \
+    sendmmsg \
     sigpending \
     splice \
     stime \
@@ -253,6 +255,7 @@ LTP_CHECK_TIME
 LTP_CHECK_TIMERFD
 test "x$with_tirpc" = xyes && LTP_CHECK_TIRPC
 LTP_CHECK_TPACKET_V3
+LTP_CHECK_MMSGHDR
 LTP_CHECK_UNAME_DOMAINNAME
 LTP_CHECK_XFS_QUOTACTL
 LTP_CHECK_X_TABLES
include/lapi/socket.h +8 -0
index 2605443e8..6d9e9fe30 100644
@@ -19,6 +19,7 @@
 #ifndef __LAPI_SOCKET_H__
 #define __LAPI_SOCKET_H__
 
+#include "config.h"
 #include <sys/socket.h>
 
 #ifndef MSG_ZEROCOPY
@@ -69,4 +70,11 @@
 # define SOL_ALG		279
 #endif
 
+#ifndef HAVE_STRUCT_MMSGHDR
+struct mmsghdr {
+	struct msghdr msg_hdr;
+	unsigned int msg_len;
+};
+#endif
+
 #endif /* __LAPI_SOCKET_H__ */
runtest/syscalls +2 -0
index 67dfed661..1e79e41c3 100644
@@ -1117,6 +1117,8 @@ sendfile09_64 sendfile09_64
 sendmsg01 sendmsg01
 sendmsg02 sendmsg02
 
+sendmmsg01 sendmmsg01
+
 sendto01 sendto01
 sendto02 sendto02
 
testcases/kernel/syscalls/sendmmsg/.gitignore new file +1 -0
new file mode 100644
index 000000000..b703ececd
@@ -0,0 +1 @@
+sendmmsg01
testcases/kernel/syscalls/sendmmsg/Makefile new file +9 -0
new file mode 100644
index 000000000..47e063722
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+sendmmsg01: CFLAGS+=-pthread
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/sendmmsg/sendmmsg01.c new file +126 -0

126 lines not on this page · raw message

testcases/kernel/syscalls/sendmmsg/sendmmsg_var.h new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.22.0.709.g102302147b-goog
#1 lore raw

PATCH 1/1 syscalls/sendmmsg: add new test

Hi Steve,

Quoted 3 lines

Test basic functionality of sendmmsg and recvmmsg.

Quoted 6 lines

---

Changes since v3:
- drop resending of messages on partially successful sendmmsg()
- drop use of pthreads, do message creation and port management in setup/cleanup

The only thing left in v4 is duplicate LTP_CHECK_MMSGHDR call.
+ I'd use lapi/socket.h also in cve-2016-7117.c (as Cyril pointed out) in this commit (this change is simple enough).

So I'd be for merging v4 with diff below.

Kind regards,
Petr

configure.ac +0 -1
index 5e4e7f1f9..f7d1afc40 100644
@@ -255,7 +255,6 @@ LTP_CHECK_TIME
 LTP_CHECK_TIMERFD
 test "x$with_tirpc" = xyes && LTP_CHECK_TIRPC
 LTP_CHECK_TPACKET_V3
-LTP_CHECK_MMSGHDR
 LTP_CHECK_UNAME_DOMAINNAME
 LTP_CHECK_XFS_QUOTACTL
 LTP_CHECK_X_TABLES
cve/cve-2016-7117.c +3 -9
index f0f6c22f1..140839712 100644
@@ -30,6 +30,8 @@
  * https://blog.lizzie.io/notes-about-cve-2016-7117.html
  */
 
+#include "config.h"
+
 #include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -44,20 +46,12 @@
 
 /* The bug was present in the kernel before recvmmsg was exposed by glibc */
 #include "lapi/syscalls.h"
-
-#include "config.h"
+#include "lapi/socket.h"
 
 #define MSG "abcdefghijklmnop"
 #define RECV_TIMEOUT 1
 #define ATTEMPTS 0x1FFFFF
 
-#ifndef HAVE_STRUCT_MMSGHDR
-struct mmsghdr {
-	struct msghdr msg_hdr;
-	unsigned int msg_len;
-};
-#endif
-
 static volatile int socket_fds[2];
 static struct mmsghdr msghdrs[2] = {
 	{
#2 lore raw

PATCH 1/1 syscalls/sendmmsg: add new test

Hi!

Quoted 10 lines
Quoted 1 line
Quoted 6 lines

---

Changes since v3:
- drop resending of messages on partially successful sendmmsg()
- drop use of pthreads, do message creation and port management in setup/cleanup

Quoted 5 lines

The only thing left in v4 is duplicate LTP_CHECK_MMSGHDR call.
+ I'd use lapi/socket.h also in cve-2016-7117.c (as Cyril pointed out) in this commit (this change is simple enough).

So I'd be for merging v4 with diff below.

There is also leftover -pthread in CFLAGS in Makefile since we dropped pthreads from the test. Other than that and the minor issues you have pointed it looks good to me as well.

Quoted 50 lines

Kind regards,
Petr

configure.ac +0 -1
index 5e4e7f1f9..f7d1afc40 100644
@@ -255,7 +255,6 @@ LTP_CHECK_TIME
 LTP_CHECK_TIMERFD
 test "x$with_tirpc" = xyes && LTP_CHECK_TIRPC
 LTP_CHECK_TPACKET_V3
-LTP_CHECK_MMSGHDR
 LTP_CHECK_UNAME_DOMAINNAME
 LTP_CHECK_XFS_QUOTACTL
 LTP_CHECK_X_TABLES
cve/cve-2016-7117.c +3 -9
index f0f6c22f1..140839712 100644
@@ -30,6 +30,8 @@
  * https://blog.lizzie.io/notes-about-cve-2016-7117.html
  */
 
+#include "config.h"
+
 #include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -44,20 +46,12 @@
 
 /* The bug was present in the kernel before recvmmsg was exposed by glibc */
 #include "lapi/syscalls.h"
-
-#include "config.h"
+#include "lapi/socket.h"
 
 #define MSG "abcdefghijklmnop"
 #define RECV_TIMEOUT 1
 #define ATTEMPTS 0x1FFFFF
 
-#ifndef HAVE_STRUCT_MMSGHDR
-struct mmsghdr {
-	struct msghdr msg_hdr;
-	unsigned int msg_len;
-};
-#endif
-
 static volatile int socket_fds[2];
 static struct mmsghdr msghdrs[2] = {
 	{
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH 1/1 syscalls/sendmmsg: add new test

Hi Cyril, Steve,

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

Changes since v3:
- drop resending of messages on partially successful sendmmsg()
- drop use of pthreads, do message creation and port management in setup/cleanup

The only thing left in v4 is duplicate LTP_CHECK_MMSGHDR call.
+ I'd use lapi/socket.h also in cve-2016-7117.c (as Cyril pointed out) in this commit (this change is simple enough).

Quoted 5 lines
Quoted 1 line

So I'd be for merging v4 with diff below.

There is also leftover -pthread in CFLAGS in Makefile since we dropped pthreads from the test. Other than that and the minor issues you have pointed it looks good to me as well.

Cyril, thanks for pointing this out. Merged with these fixes and your ack.

Kind regards,
Petr