public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags
@ 2022-02-26 22:56 Stefano Brivio
  2022-02-26 22:56 ` [PATCH 1/7] passt: Explicitly check return value of chdir() Stefano Brivio
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 1039 bytes --]

This series fixes issues and warnings I spotted in Martin's build logs
for OpenSUSE on armv6l and armv7l (patches 1/7 to 3/7).

I couldn't find (yet) a convenient way to add armv6l and armv7l OpenSUSE
builds to the tests using qemu TCG (suggestions welcome!) so I tried
things out on a Raspberry Pi Zero and a Raspberry Pi 4 for the moment
being -- patches 4/7 to 7/7 fix the other issues I hit there.

Stefano Brivio (7):
  passt: Explicitly check return value of chdir()
  udp: Explicitly initialise sin6_scope_id and sin_zero in
    sockaddr_in{,6}
  seccomp.sh: Handle syscall number defines in the (x + y) form
  tap: Cast ETH_MAX_MTU to signed in comparisons
  Makefile: Fix up AUDIT_ARCH for armv6l, armv7l
  passt: Don't warn on failed madvise()
  seccomp: Adjust list of allowed syscalls for armv6l, armv7l

 Makefile   |  1 +
 passt.c    | 15 +++++++++------
 pasta.c    |  3 ++-
 seccomp.sh |  3 +++
 tap.c      |  4 ++--
 udp.c      |  2 ++
 util.c     |  3 ++-
 7 files changed, 21 insertions(+), 10 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/7] passt: Explicitly check return value of chdir()
  2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
@ 2022-02-26 22:56 ` Stefano Brivio
  2022-02-26 22:56 ` [PATCH 2/7] udp: Explicitly initialise sin6_scope_id and sin_zero in sockaddr_in{,6} Stefano Brivio
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 773 bytes --]

...it doesn't actually matter as we're checking errno at the very
end, but, depending on build flags, chdir() might be declared with
warn_unused_result and the compiler issues a warning.

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 passt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/passt.c b/passt.c
index 3d18d1f..038d50a 100644
--- a/passt.c
+++ b/passt.c
@@ -260,7 +260,9 @@ static int sandbox(struct ctx *c)
 	mount("", "/", "", MS_UNBINDABLE | MS_REC, NULL);
 	mount("", TMPDIR, "tmpfs", MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_RDONLY,
 	      "nr_inodes=2,nr_blocks=0");
-	chdir(TMPDIR);
+	if (chdir(TMPDIR))
+		return -errno;
+
 	syscall(SYS_pivot_root, ".", ".");
 	umount2(".", MNT_DETACH | UMOUNT_NOFOLLOW);
 
-- 
@@ -260,7 +260,9 @@ static int sandbox(struct ctx *c)
 	mount("", "/", "", MS_UNBINDABLE | MS_REC, NULL);
 	mount("", TMPDIR, "tmpfs", MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_RDONLY,
 	      "nr_inodes=2,nr_blocks=0");
-	chdir(TMPDIR);
+	if (chdir(TMPDIR))
+		return -errno;
+
 	syscall(SYS_pivot_root, ".", ".");
 	umount2(".", MNT_DETACH | UMOUNT_NOFOLLOW);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/7] udp: Explicitly initialise sin6_scope_id and sin_zero in sockaddr_in{,6}
  2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
  2022-02-26 22:56 ` [PATCH 1/7] passt: Explicitly check return value of chdir() Stefano Brivio
@ 2022-02-26 22:56 ` Stefano Brivio
  2022-02-26 22:56 ` [PATCH 3/7] seccomp.sh: Handle syscall number defines in the (x + y) form Stefano Brivio
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

Not functionally needed, but gcc versions 7 to 9 (at least) will
issue a warning otherwise.

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 udp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/udp.c b/udp.c
index d4f3714..ccce005 100644
--- a/udp.c
+++ b/udp.c
@@ -640,6 +640,7 @@ static void udp_sock_handler_splice(struct ctx *c, union epoll_ref ref,
 			.sin6_family = AF_INET6,
 			.sin6_addr = IN6ADDR_LOOPBACK_INIT,
 			.sin6_port = htons(send_dst),
+			.sin6_scope_id = 0,
 		});
 	} else {
 		*((struct sockaddr_in *)&udp_splice_namebuf) =
@@ -647,6 +648,7 @@ static void udp_sock_handler_splice(struct ctx *c, union epoll_ref ref,
 			.sin_family = AF_INET,
 			.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
 			.sin_port = htons(send_dst),
+			.sin_zero = { 0 },
 		});
 	}
 
-- 
@@ -640,6 +640,7 @@ static void udp_sock_handler_splice(struct ctx *c, union epoll_ref ref,
 			.sin6_family = AF_INET6,
 			.sin6_addr = IN6ADDR_LOOPBACK_INIT,
 			.sin6_port = htons(send_dst),
+			.sin6_scope_id = 0,
 		});
 	} else {
 		*((struct sockaddr_in *)&udp_splice_namebuf) =
@@ -647,6 +648,7 @@ static void udp_sock_handler_splice(struct ctx *c, union epoll_ref ref,
 			.sin_family = AF_INET,
 			.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
 			.sin_port = htons(send_dst),
+			.sin_zero = { 0 },
 		});
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/7] seccomp.sh: Handle syscall number defines in the (x + y) form
  2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
  2022-02-26 22:56 ` [PATCH 1/7] passt: Explicitly check return value of chdir() Stefano Brivio
  2022-02-26 22:56 ` [PATCH 2/7] udp: Explicitly initialise sin6_scope_id and sin_zero in sockaddr_in{,6} Stefano Brivio
@ 2022-02-26 22:56 ` Stefano Brivio
  2022-02-26 22:56 ` [PATCH 4/7] tap: Cast ETH_MAX_MTU to signed in comparisons Stefano Brivio
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 679 bytes --]

This is the case at least for current glibc headers on armv6l and
armv7l.

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 seccomp.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/seccomp.sh b/seccomp.sh
index f5ee98e..6ac59a1 100755
--- a/seccomp.sh
+++ b/seccomp.sh
@@ -109,6 +109,9 @@ syscall_nr() {
 	__in="$(printf "#include <asm-generic/unistd.h>\n#include <sys/syscall.h>\n__NR_%s" ${1})"
 	__out="$(echo "${__in}" | cc -E -xc - -o - | tail -1)"
 	[ "${__out}" = "__NR_$1" ] && return 1
+
+	# Output might be in the form "(x + y)" (seen on armv6l, armv7l)
+	__out="$(eval echo $((${__out})))"
 	echo "${__out}"
 }
 
-- 
@@ -109,6 +109,9 @@ syscall_nr() {
 	__in="$(printf "#include <asm-generic/unistd.h>\n#include <sys/syscall.h>\n__NR_%s" ${1})"
 	__out="$(echo "${__in}" | cc -E -xc - -o - | tail -1)"
 	[ "${__out}" = "__NR_$1" ] && return 1
+
+	# Output might be in the form "(x + y)" (seen on armv6l, armv7l)
+	__out="$(eval echo $((${__out})))"
 	echo "${__out}"
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/7] tap: Cast ETH_MAX_MTU to signed in comparisons
  2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
                   ` (2 preceding siblings ...)
  2022-02-26 22:56 ` [PATCH 3/7] seccomp.sh: Handle syscall number defines in the (x + y) form Stefano Brivio
@ 2022-02-26 22:56 ` Stefano Brivio
  2022-02-26 22:56 ` [PATCH 5/7] Makefile: Fix up AUDIT_ARCH for armv6l, armv7l Stefano Brivio
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

At least gcc 8.3 and 10.2 emit a warning on armv6l and armv7l.

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tap.c b/tap.c
index 9e6ece9..29fcd51 100644
--- a/tap.c
+++ b/tap.c
@@ -658,7 +658,7 @@ redo:
 		/* Complete the partial read above before discarding a malformed
 		 * frame, otherwise the stream will be inconsistent.
 		 */
-		if (len < (ssize_t)sizeof(*eh) || len > ETH_MAX_MTU)
+		if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU)
 			goto next;
 
 		pcap(p, len);
@@ -718,7 +718,7 @@ restart:
 	while ((len = read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n)) > 0) {
 		struct ethhdr *eh = (struct ethhdr *)(pkt_buf + n);
 
-		if (len < (ssize_t)sizeof(*eh) || len > ETH_MAX_MTU) {
+		if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU) {
 			n += len;
 			continue;
 		}
-- 
@@ -658,7 +658,7 @@ redo:
 		/* Complete the partial read above before discarding a malformed
 		 * frame, otherwise the stream will be inconsistent.
 		 */
-		if (len < (ssize_t)sizeof(*eh) || len > ETH_MAX_MTU)
+		if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU)
 			goto next;
 
 		pcap(p, len);
@@ -718,7 +718,7 @@ restart:
 	while ((len = read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n)) > 0) {
 		struct ethhdr *eh = (struct ethhdr *)(pkt_buf + n);
 
-		if (len < (ssize_t)sizeof(*eh) || len > ETH_MAX_MTU) {
+		if (len < (ssize_t)sizeof(*eh) || len > (ssize_t)ETH_MAX_MTU) {
 			n += len;
 			continue;
 		}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/7] Makefile: Fix up AUDIT_ARCH for armv6l, armv7l
  2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
                   ` (3 preceding siblings ...)
  2022-02-26 22:56 ` [PATCH 4/7] tap: Cast ETH_MAX_MTU to signed in comparisons Stefano Brivio
@ 2022-02-26 22:56 ` Stefano Brivio
  2022-02-26 22:56 ` [PATCH 6/7] passt: Don't warn on failed madvise() Stefano Brivio
  2022-02-26 22:56 ` [PATCH 7/7] seccomp: Adjust list of allowed syscalls for armv6l, armv7l Stefano Brivio
  6 siblings, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 680 bytes --]

There's a single AUDIT_ARCH_ARM define available (and big-endian
shouldn't be a concern with those).

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Makefile b/Makefile
index 28ef316..031b684 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@ RLIMIT_STACK_VAL := 1024
 endif
 
 AUDIT_ARCH := $(shell uname -m | tr [a-z] [A-Z])
+AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/^ARM.*/ARM/')
 AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/I[456]86/I386/')
 AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPC64/PPC/')
 AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPCLE/PPC64LE/')
-- 
@@ -15,6 +15,7 @@ RLIMIT_STACK_VAL := 1024
 endif
 
 AUDIT_ARCH := $(shell uname -m | tr [a-z] [A-Z])
+AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/^ARM.*/ARM/')
 AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/I[456]86/I386/')
 AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPC64/PPC/')
 AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPCLE/PPC64LE/')
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/7] passt: Don't warn on failed madvise()
  2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
                   ` (4 preceding siblings ...)
  2022-02-26 22:56 ` [PATCH 5/7] Makefile: Fix up AUDIT_ARCH for armv6l, armv7l Stefano Brivio
@ 2022-02-26 22:56 ` Stefano Brivio
  2022-02-26 22:56 ` [PATCH 7/7] seccomp: Adjust list of allowed syscalls for armv6l, armv7l Stefano Brivio
  6 siblings, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 624 bytes --]

A kernel might not be configured with CONFIG_TRANSPARENT_HUGEPAGE,
especially on embedded systems. Ignore the error, it doesn't affect
functionality.

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 passt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/passt.c b/passt.c
index 038d50a..22934a2 100644
--- a/passt.c
+++ b/passt.c
@@ -339,8 +339,7 @@ int main(int argc, char **argv)
 		exit(EXIT_FAILURE);
 	}
 
-	if (madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE))
-		perror("madvise");
+	madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE);
 
 	__openlog(log_name, 0, LOG_DAEMON);
 
-- 
@@ -339,8 +339,7 @@ int main(int argc, char **argv)
 		exit(EXIT_FAILURE);
 	}
 
-	if (madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE))
-		perror("madvise");
+	madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE);
 
 	__openlog(log_name, 0, LOG_DAEMON);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 7/7] seccomp: Adjust list of allowed syscalls for armv6l, armv7l
  2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
                   ` (5 preceding siblings ...)
  2022-02-26 22:56 ` [PATCH 6/7] passt: Don't warn on failed madvise() Stefano Brivio
@ 2022-02-26 22:56 ` Stefano Brivio
  6 siblings, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2022-02-26 22:56 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 2318 bytes --]

It looks like glibc commonly implements clock_gettime(2) with
clock_gettime64(), and uses recv() instead of recvfrom(), send()
instead of sendto(), and sigreturn() instead of rt_sigreturn() on
armv6l and armv7l.

Adjust the list of system calls for armv6l and armv7l accordingly.

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 passt.c | 8 +++++---
 pasta.c | 3 ++-
 util.c  | 3 ++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/passt.c b/passt.c
index 22934a2..e7dd108 100644
--- a/passt.c
+++ b/passt.c
@@ -297,9 +297,11 @@ void exit_handler(int signal)
  *
  * #syscalls read write writev
  * #syscalls socket bind connect getsockopt setsockopt s390x:socketcall close
- * #syscalls recvfrom sendto shutdown ppc64le:recv ppc64le:send
- * #syscalls accept4|accept listen
- * #syscalls epoll_ctl epoll_wait|epoll_pwait epoll_pwait clock_gettime
+ * #syscalls recvfrom sendto shutdown
+ * #syscalls armv6l:recv armv7l:recv ppc64le:recv
+ * #syscalls armv6l:send armv7l:send ppc64le:send
+ * #syscalls accept4|accept listen epoll_ctl epoll_wait|epoll_pwait epoll_pwait
+ * #syscalls clock_gettime armv6l:clock_gettime64 armv7l:clock_gettime64
  */
 int main(int argc, char **argv)
 {
diff --git a/pasta.c b/pasta.c
index e45cc92..96866c6 100644
--- a/pasta.c
+++ b/pasta.c
@@ -12,7 +12,8 @@
  * Author: Stefano Brivio <sbrivio(a)redhat.com>
  *
  * #syscalls:pasta clone waitid exit exit_group rt_sigprocmask
- * #syscalls:pasta rt_sigreturn|sigreturn ppc64:sigreturn s390x:sigreturn
+ * #syscalls:pasta rt_sigreturn|sigreturn armv6l:sigreturn armv7l:sigreturn
+ * #syscalls:pasta ppc64:sigreturn s390x:sigreturn
  */
 
 #include <sched.h>
diff --git a/util.c b/util.c
index e9fca3b..90b5ab8 100644
--- a/util.c
+++ b/util.c
@@ -441,7 +441,8 @@ char *line_read(char *buf, size_t len, int fd)
  * @map:	Bitmap where numbers of ports in listening state will be set
  * @exclude:	Bitmap of ports to exclude from setting (and clear)
  *
- * #syscalls:pasta lseek ppc64le:_llseek ppc64:_llseek
+ * #syscalls:pasta lseek
+ * #syscalls:pasta ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
  */
 void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, int ns,
 			uint8_t *map, uint8_t *exclude)
-- 
@@ -441,7 +441,8 @@ char *line_read(char *buf, size_t len, int fd)
  * @map:	Bitmap where numbers of ports in listening state will be set
  * @exclude:	Bitmap of ports to exclude from setting (and clear)
  *
- * #syscalls:pasta lseek ppc64le:_llseek ppc64:_llseek
+ * #syscalls:pasta lseek
+ * #syscalls:pasta ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
  */
 void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, int ns,
 			uint8_t *map, uint8_t *exclude)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-26 22:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-26 22:56 [PATCH 0/7] Fixes for armv6l, armv7l, and warnings on some gcc flags Stefano Brivio
2022-02-26 22:56 ` [PATCH 1/7] passt: Explicitly check return value of chdir() Stefano Brivio
2022-02-26 22:56 ` [PATCH 2/7] udp: Explicitly initialise sin6_scope_id and sin_zero in sockaddr_in{,6} Stefano Brivio
2022-02-26 22:56 ` [PATCH 3/7] seccomp.sh: Handle syscall number defines in the (x + y) form Stefano Brivio
2022-02-26 22:56 ` [PATCH 4/7] tap: Cast ETH_MAX_MTU to signed in comparisons Stefano Brivio
2022-02-26 22:56 ` [PATCH 5/7] Makefile: Fix up AUDIT_ARCH for armv6l, armv7l Stefano Brivio
2022-02-26 22:56 ` [PATCH 6/7] passt: Don't warn on failed madvise() Stefano Brivio
2022-02-26 22:56 ` [PATCH 7/7] seccomp: Adjust list of allowed syscalls for armv6l, armv7l Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).