Fix strace's sockopt-sol_netlink test for kernel >= 5.15.116.1 (#5808)

This commit is contained in:
Olivia Crain 2023-07-10 12:44:31 -05:00 committed by GitHub
parent b17ac09233
commit d228cb50b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 122 additions and 6 deletions

View File

@ -2,7 +2,7 @@
Summary: Tracks system calls that are made by a running process
Name: strace
Version: 5.16
Release: 1%{?dist}
Release: 3%{?dist}
License: GPL-2.0-or-later AND LGPL-2.1-or-later
Vendor: Microsoft Corporation
Distribution: Mariner
@ -11,6 +11,8 @@ URL: https://strace.io/
Source0: https://strace.io/files/%{version}/%{name}-%{version}.tar.xz
# Released upstream in v5.18
Patch0: testfix-landlock-brackets.patch
# Both patches released upstream in v6.4
Patch1: testfix-netlink-list-memberships.patch
BuildRequires: libacl-devel
BuildRequires: libaio-devel
@ -41,11 +43,16 @@ all the arugments and return values from the system calls. This is useful in deb
%files
%defattr(-,root,root)
%license COPYING
%license COPYING LGPL-2.1-or-later bundled/linux/GPL-2.0
%{_bindir}/*
%{_mandir}/man1/*
%changelog
* Mon Jun 10 2023 Olivia Crain <oliviacrain@microsoft.com> - 5.16-3
- Add upstream patch to fix sockopt-sol_netlink test with kernel >= 5.15.116.1
- Modify landlock test patch to properly apply with `git am`
- Package full license texts
* Wed Jun 07 2023 Olivia Crain <oliviacrain@microsoft.com> - 5.16-2
- Add upstream patch to fix landlock_create_ruleset-y test
- Modernize calls to make by using macros

View File

@ -1,6 +1,3 @@
Maintainer note: Kernel patch mentioned below was backported to 5.15, is present in kernel>=5.15.33.1
https://github.com/microsoft/CBL-Mariner-Linux-Kernel/commit/3d4b396a616d0d67bf95d6823ad1197f6247292e
From 22cf83f78c12fe8afdd0b2d8029a037b6084edf2 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Fri, 27 May 2022 16:17:21 +0200
@ -20,7 +17,11 @@ in the test instead.
by the landlock_create_ruleset call and set it to fd_str, which
is then printed.
Signed-off-by: Olivia Crain <olivia@olivia.dev>
Maintainer note: Kernel commit mentioned above was backported to 5.15,
is present in kernel>=5.15.33.1
https://github.com/microsoft/CBL-Mariner-Linux-Kernel/commit/3d4b396a616d0d67bf95d6823ad1197f6247292e
Signed-off-by: Olivia Crain <oliviacrain@microsoft.com>
---
tests/landlock_create_ruleset-y.c | 2 +-
tests/landlock_create_ruleset.c | 33 ++++++++++++++++++++++++++++++-

View File

@ -0,0 +1,108 @@
From 3bbfb541b258baec9eba674b5d8dc30007a61542 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@strace.io>
Date: Wed, 21 Jun 2023 08:00:00 +0000
Subject: [PATCH] net: enhance getsockopt decoding
When getsockopt syscall fails the kernel sometimes updates the optlen
argument, for example, NETLINK_LIST_MEMBERSHIPS updates it even if
optval is not writable.
* src/net.c (SYS_FUNC(getsockopt)): Try to fetch and print optlen
argument on exiting syscall regardless of getsockopt exit status.
Maintainer note: This small feature patch is required to apply the
second patch in this series to fix the test failure.
Signed-off-by: Olivia Crain <oliviacrain@microsoft.com>
---
src/net.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/net.c b/src/net.c
index f68ccb947..7244b5e57 100644
--- a/src/net.c
+++ b/src/net.c
@@ -1038,7 +1038,7 @@ SYS_FUNC(getsockopt)
} else {
ulen = get_tcb_priv_ulong(tcp);
- if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &rlen) < 0) {
+ if (umove(tcp, tcp->u_arg[4], &rlen) < 0) {
/* optval */
printaddr(tcp->u_arg[3]);
tprint_arg_next();
@@ -1047,6 +1047,19 @@ SYS_FUNC(getsockopt)
tprint_indirect_begin();
PRINT_VAL_D(ulen);
tprint_indirect_end();
+ } else if (syserror(tcp)) {
+ /* optval */
+ printaddr(tcp->u_arg[3]);
+ tprint_arg_next();
+
+ /* optlen */
+ tprint_indirect_begin();
+ if (ulen != rlen) {
+ PRINT_VAL_D(ulen);
+ tprint_value_changed();
+ }
+ PRINT_VAL_D(rlen);
+ tprint_indirect_end();
} else {
/* optval */
print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
From f31c2f4494779e5c5f170ad10539bfc2dfafe967 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@strace.io>
Date: Sat, 24 Jun 2023 08:00:00 +0000
Subject: [PATCH] tests: update sockopt-sol_netlink test
Update sockopt-sol_netlink test that started to fail, likely
due to recent linux kernel commit f4e4534850a9 ("net/netlink: fix
NETLINK_LIST_MEMBERSHIPS length report").
* tests/sockopt-sol_netlink.c (main): Always print changing optlen value
on exiting syscall.
Maintainer note: Kernel commit mentioned above was backported to 5.15,
is present in kernel>=5.15.116.1
https://github.com/microsoft/CBL-Mariner-Linux-Kernel/commit/7dc379f8856bd334582c35c7fe28952e8bd8fb5d
Reported-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Olivia Crain <oliviacrain@microsoft.com>
---
tests/sockopt-sol_netlink.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/tests/sockopt-sol_netlink.c b/tests/sockopt-sol_netlink.c
index 82b98adc23..1c33219ac5 100644
--- a/tests/sockopt-sol_netlink.c
+++ b/tests/sockopt-sol_netlink.c
@@ -94,7 +94,10 @@ main(void)
printf("%p", val);
else
printf("[%d]", *val);
- printf(", [%d]) = %s\n", *len, errstr);
+ printf(", [%d", (int) sizeof(*val));
+ if ((int) sizeof(*val) != *len)
+ printf(" => %d", *len);
+ printf("]) = %s\n", errstr);
/* optlen larger than necessary - shortened */
*len = sizeof(*val) + 1;
@@ -150,8 +153,12 @@ main(void)
/* optval EFAULT - print address */
*len = sizeof(*val);
get_sockopt(fd, names[i].val, efault, len);
- printf("getsockopt(%d, SOL_NETLINK, %s, %p, [%d]) = %s\n",
- fd, names[i].str, efault, *len, errstr);
+ printf("getsockopt(%d, SOL_NETLINK, %s, %p",
+ fd, names[i].str, efault);
+ printf(", [%d", (int) sizeof(*val));
+ if ((int) sizeof(*val) != *len)
+ printf(" => %d", *len);
+ printf("]) = %s\n", errstr);
/* optlen EFAULT - print address */
get_sockopt(fd, names[i].val, val, len + 1);