mailing list of musl libc
 help / color / mirror / code / Atom feed
8bf34995b1b7029f89be50053fecc99545824fe4 blob 1425 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include "syscall.h"
#include "pthread_impl.h"

struct ctx {
	int fd;
	const char *filename;
	int amode;
	int p;
};

static int checker(void *p)
{
	struct ctx *c = p;
	int ret;
	if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1)
	    || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
		__syscall(SYS_exit, 1);
	ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
	__syscall(SYS_write, c->p, &ret, sizeof ret);
	return 0;
}

int faccessat(int fd, const char *filename, int amode, int flag)
{
	if (!flag || (flag==AT_EACCESS && getuid()==geteuid() && getgid()==getegid()))
		return syscall(SYS_faccessat, fd, filename, amode, flag);

	if (flag != AT_EACCESS)
		return __syscall_ret(-EINVAL);

	char stack[1024];
	sigset_t set;
	pid_t pid;
	int ret, p[2];

	if (pipe2(p, O_CLOEXEC)) return __syscall_ret(-EBUSY);
	struct ctx c = { .fd = fd, .filename = filename, .amode = amode, .p = p[1] };

	__block_all_sigs(&set);
	
	pid = __clone(checker, stack+sizeof stack, 0, &c);
	__syscall(SYS_close, p[1]);

	if (pid<0 || __syscall(SYS_read, p[0], &ret, sizeof ret) != sizeof(ret))
		ret = -EBUSY;
	__syscall(SYS_close, p[0]);
#ifdef SYS_wait4
	int status;
	__syscall(SYS_wait4, pid, &status, __WCLONE, 0);
#else
	__syscall(SYS_waitid, P_PID, pid, &(siginfo_t){0}, __WCLONE|WEXITED, 0);
#endif

	__restore_sigs(&set);

	return __syscall_ret(ret);
}
debug log:

solving 8bf34995 ...
found 8bf34995 in https://inbox.vuxu.org/musl/20200903112309.102601-8-sorear@fastmail.com/ ||
	https://inbox.vuxu.org/musl/e792658a-fbaa-48bd-8704-7f9d2ec5a4ef@www.fastmail.com/
found 76bbd4c7 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 76bbd4c72a16dbea7cdef397aa12ccb013adaa85	src/unistd/faccessat.c

applying [1/2] https://inbox.vuxu.org/musl/20200903112309.102601-8-sorear@fastmail.com/
diff --git a/src/unistd/faccessat.c b/src/unistd/faccessat.c
index 76bbd4c7..8bf34995 100644

Checking patch src/unistd/faccessat.c...
Applied patch src/unistd/faccessat.c cleanly.

skipping https://inbox.vuxu.org/musl/e792658a-fbaa-48bd-8704-7f9d2ec5a4ef@www.fastmail.com/ for 8bf34995
index at:
100644 8bf34995b1b7029f89be50053fecc99545824fe4	src/unistd/faccessat.c

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

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).