Bug 15445 - uid_wrapper: test_syscall_swrap.c fails in virtualized environments
Summary: uid_wrapper: test_syscall_swrap.c fails in virtualized environments
Status: NEW
Alias: None
Product: cwrap
Classification: Unclassified
Component: library (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: Andreas Schneider
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-04 10:21 UTC by Simon Josefsson
Modified: 2023-08-04 11:43 UTC (History)
0 users

See Also:


Attachments
tests: Handle unknown syscall call errno. (934 bytes, patch)
2023-08-04 10:21 UTC, Simon Josefsson
no flags Details
tests: Fix unknown syscall check in test_syscall_swrap. (842 bytes, patch)
2023-08-04 11:00 UTC, Simon Josefsson
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Josefsson 2023-08-04 10:21:45 UTC
Created attachment 18029 [details]
tests: Handle unknown syscall call errno.

Hi.

With the 1.3.0 release the test_syscall_swrap.c self-test was added.  It was not part of 1.2.9.  It can fail like this:

1/1 Test #16: test_syscall_swrap ...............***Failed    0.00 sec
[==========] Running 1 test(s).
[ RUN      ] test_uwrap_syscall_swrap
[  ERROR   ] --- 0x1 != 0x26
[   LINE   ] --- /uid_wrapper-1.3.0/tests/test_syscall_swrap.c:37: error: Failure!
[  FAILED  ] test_uwrap_syscall_swrap
[==========] 1 test(s) run.
[  PASSED  ] 0 test(s).
[  FAILED  ] 1 test(s), listed below:
[  FAILED  ] test_uwrap_syscall_swrap

Chaising this down was fun, and boils down to unknown syscalls resulting in different errno values in virtualized environments vs non-virtualized.  You can test it like this:

jas@kaka:~$ cat>foo.c
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <signal.h>
#include <errno.h>

void main (void)
{
	long rc;

	signal(SIGSYS, SIG_IGN);
	rc = syscall(123456789);
	signal(SIGSYS, SIG_DFL);
	printf ("rc %ld errno %d (EPERM %d ENOSYS %d)\n",
		rc, errno, EPERM, ENOSYS);
}
jas@kaka:~$ gcc foo.c
jas@kaka:~$ ./a.out 
rc -1 errno 38 (EPERM 1 ENOSYS 38)
jas@kaka:~$ 

If you run this in a VM it will output this instead:

rc -1 errno 1 (EPERM 1 ENOSYS 38)

Is the errno returned for unknown syscalls even documented anywhere?

I'm attaching a patch that we will use in Debian to work around this problem.  What do you think?

/Simon
Comment 1 Simon Josefsson 2023-08-04 11:00:27 UTC
Created attachment 18030 [details]
tests: Fix unknown syscall check in test_syscall_swrap.
Comment 2 Simon Josefsson 2023-08-04 11:01:09 UTC
Hi again

Unfortunately, I found another virtualization environment (LXC) that seems to behave different compare to podman/QEMU, resulting in this error:

[  ERROR   ] --- 0xffffffffffffffff != 0x3ade68b1

It doesn't seem like checking errno for unknown syscalls is realiable.

Attaching the new patch that simply drops the errno assert.

/Simon
Comment 3 Simon Josefsson 2023-08-04 11:09:33 UTC
Sorry for adding noise here, but I spoke to soon.  This new error:

[ RUN      ] test_uwrap_syscall_swrap
[  ERROR   ] --- 0xffffffffffffffff != 0x3ade68b1
[   LINE   ] --- /tmp/autopkgtest-lxc.jbxvqbhs/downtmp/autopkgtest_tmp/tests/test_syscall_swrap.c:31: error: Failure!

Is different from the original one, and may be due to some other problem in that particular environment.

I'll debug more, but I'm leaning towards the first patch still being okay.

/Simon
Comment 4 Simon Josefsson 2023-08-04 11:43:08 UTC
I have confirmed the second error message was a build environment bug.

Thus I think the first patch should be used:

https://bugzilla.samba.org/attachment.cgi?id=18029

The patch passes the initial Debian Salsa pipeline autopkgtest, and I will upload it to see if it passes debci checks.

/Simon