mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] implement issetugid(2)
@ 2014-07-12 23:54 Brent Cook
  2014-07-15  0:57 ` Brent Cook
  2014-07-15  2:40 ` Isaac Dunham
  0 siblings, 2 replies; 14+ messages in thread
From: Brent Cook @ 2014-07-12 23:54 UTC (permalink / raw)
  To: musl; +Cc: beck, Brent Cook

From: Brent Cook <brent@boundary.com>

From OpenBSD 2.0 and later, NetBSD, FreeBSD, OS X and Solaris
http://www.openbsd.org/cgi-bin/man.cgi?query=issetugid&sektion=2

While getauxval(AT_SECURE) might have been able to provide comparable
functionality on the libc versions that support it, several Linux libc
versions implement it in a way such that the results cannot be trusted,
since there is no way to tell if it has failed. Worse, the result of '0'
returned on failures effectively causes the security mechanism to fail
'open'.

There is also no simultaneously reliable and portable way for a
library to identify if the C library has a usable version of getauxval,
since the symbol is unversioned. Compile-time checks for usability are
also unfeasible, since static libraries built with a 'good' version can
be linked to a 'bad' version of getauxval.

The fix is to implement the BSD issetugid(2) interface so that a
portable library can use its presence to determine if the underlying C
library has a reliable way of determining the value of AT_SECURE, and by
extension if the library is running with elevated privileges. If the
call fails, it assumes secure mode rather than falling back to an
insecure result.
---
 include/unistd.h       |  3 +++
 src/unistd/issetugid.c | 10 ++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 src/unistd/issetugid.c

diff --git a/include/unistd.h b/include/unistd.h
index bb19cd8..3990c1e 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -109,6 +109,9 @@ uid_t geteuid(void);
 gid_t getgid(void);
 gid_t getegid(void);
 int getgroups(int, gid_t []);
+#if defined(_BSD_SOURCE)
+int issetugid(void);
+#endif
 int setuid(uid_t);
 int setreuid(uid_t, uid_t);
 int seteuid(uid_t);
diff --git a/src/unistd/issetugid.c b/src/unistd/issetugid.c
new file mode 100644
index 0000000..f538626
--- /dev/null
+++ b/src/unistd/issetugid.c
@@ -0,0 +1,10 @@
+#include <sys/auxv.h>
+#include "libc.h"
+
+int issetugid(void)
+{
+	size_t *auxv = libc.auxv;
+	for (; *auxv; auxv+=2)
+		if (*auxv==AT_SECURE) return auxv[1] != 0;
+	return 1;
+}
--
1.9.1



^ permalink raw reply	[flat|nested] 14+ messages in thread
* [PATCH] implement issetugid(2)
@ 2014-07-12 17:55 Brent Cook
  2014-07-12 19:20 ` Rich Felker
  2014-07-12 20:12 ` Isaac Dunham
  0 siblings, 2 replies; 14+ messages in thread
From: Brent Cook @ 2014-07-12 17:55 UTC (permalink / raw)
  To: musl; +Cc: Brent Cook

From OpenBSD 2.0 and later
http://www.openbsd.org/cgi-bin/man.cgi?query=issetugid&sektion=2
---
 include/unistd.h       | 1 +
 src/unistd/issetugid.c | 9 +++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 src/unistd/issetugid.c

diff --git a/include/unistd.h b/include/unistd.h
index bb19cd8..30290c3 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -109,6 +109,7 @@ uid_t geteuid(void);
 gid_t getgid(void);
 gid_t getegid(void);
 int getgroups(int, gid_t []);
+int issetugid(void);
 int setuid(uid_t);
 int setreuid(uid_t, uid_t);
 int seteuid(uid_t);
diff --git a/src/unistd/issetugid.c b/src/unistd/issetugid.c
new file mode 100644
index 0000000..8c81336
--- /dev/null
+++ b/src/unistd/issetugid.c
@@ -0,0 +1,9 @@
+#include <errno.h>
+#include <unistd.h>
+#include <sys/auxv.h>
+
+int issetugid(void)
+{
+	errno = 0;
+	return !(getauxval(AT_SECURE) == 0 && errno != ENOENT);
+}
--
1.9.1



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

end of thread, other threads:[~2014-07-15 15:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-12 23:54 [PATCH] implement issetugid(2) Brent Cook
2014-07-15  0:57 ` Brent Cook
2014-07-15  0:59   ` Brent Cook
2014-07-15  2:06   ` Brent Cook
2014-07-15  2:40 ` Isaac Dunham
2014-07-15  4:31   ` Rich Felker
2014-07-15 15:54   ` Brent Cook
  -- strict thread matches above, loose matches on Subject: below --
2014-07-12 17:55 Brent Cook
2014-07-12 19:20 ` Rich Felker
2014-07-12 22:18   ` Brent Cook
2014-07-12 23:32     ` Isaac Dunham
2014-07-12 20:12 ` Isaac Dunham
2014-07-12 21:23   ` Brent Cook
2014-07-13 10:39     ` Szabolcs Nagy

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).