mailing list of musl libc
 help / color / mirror / code / Atom feed
6e11f5072b91ec4052de629256080a7803fdacbb blob 1435 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
 
#include <unistd.h>
#include <errno.h>
#include "syscall.h"
#include "libc.h"
#include "pthread_impl.h"

struct ctx {
	int id, eid, sid;
	int xid, err;
};

static int setxid_syscall(int xid, int id, int eid, int sid)
{
	if (xid == xid_resuid) return __syscall(SYS_setresuid, id, eid, sid);
	if (xid == xid_resgid) return __syscall(SYS_setresgid, id, eid, sid);
	if (xid == xid_reuid) return __syscall(SYS_setreuid, id, eid);
	if (xid == xid_regid) return __syscall(SYS_setregid, id, eid);
	if (xid == xid_uid) return __syscall(SYS_setuid, id);
	if (xid == xid_gid) return __syscall(SYS_setgid, id);
	abort();
}

static void do_setxid(void *p)
{
	struct ctx *c = p;
	if (c->err>0) return;
	int ret = -setxid_syscall(c->xid, c->id, c->eid, c->sid);
	if (ret && !c->err) {
		/* If one thread fails to set ids after another has already
		 * succeeded, forcibly killing the process is the only safe
		 * thing to do. State is inconsistent and dangerous. Use
		 * SIGKILL because it is uncatchable. */
		__block_all_sigs(0);
		__syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL);
	}
	c->err = ret;
}

int __setxid(int xid, int id, int eid, int sid)
{
	/* err is initially nonzero so that failure of the first thread does not
	 * trigger the safety kill above. */
	struct ctx c = { .xid = xid, .id = id, .eid = eid, .sid = sid, .err = -1 };
	__synccall(do_setxid, &c);
	if (c.err) {
		if (c.err>0) errno = c.err;
		return -1;
	}
	return 0;
}
debug log:

solving 6e11f507 ...
found 6e11f507 in https://inbox.vuxu.org/musl/VI1PR0502MB38858E8FC5B89323C105D080E73A0@VI1PR0502MB3885.eurprd05.prod.outlook.com/
found 0239f8af in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 0239f8afa95019ae9aa6dad5d79fcaf4eade139b	src/unistd/setxid.c

applying [1/1] https://inbox.vuxu.org/musl/VI1PR0502MB38858E8FC5B89323C105D080E73A0@VI1PR0502MB3885.eurprd05.prod.outlook.com/
diff --git a/src/unistd/setxid.c b/src/unistd/setxid.c
index 0239f8af..6e11f507 100644

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

index at:
100644 6e11f5072b91ec4052de629256080a7803fdacbb	src/unistd/setxid.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).