aboutsummaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2015-02-10 23:49:31 -0600
committerBrent Cook <bcook@openbsd.org>2015-03-31 09:25:21 -0500
commitfe3f7fc6365bfaac3418a72256b8c11603e80cbf (patch)
treeac6ee47f5ecb73a5645bb4bdbe2dc97ff8aa02fd /crypto
parent20101fd6b33d712e45f74c5297f79ea4225c183c (diff)
downloadportable-fe3f7fc6365bfaac3418a72256b8c11603e80cbf.tar.gz
portable-fe3f7fc6365bfaac3418a72256b8c11603e80cbf.tar.bz2
portable-fe3f7fc6365bfaac3418a72256b8c11603e80cbf.zip
Add experimental AIX support.
This includes a WIP failsafe issetugid for now, while research continues on the proper way to do this in a race-free fashion in AIX.
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Makefile.am7
-rw-r--r--crypto/compat/arc4random.h5
-rw-r--r--crypto/compat/issetugid_aix.c107
3 files changed, 118 insertions, 1 deletions
diff --git a/crypto/Makefile.am b/crypto/Makefile.am
index e350cda..83bf0c6 100644
--- a/crypto/Makefile.am
+++ b/crypto/Makefile.am
@@ -69,6 +69,9 @@ if !HAVE_ARC4RANDOM_BUF
69libcompat_la_SOURCES += compat/arc4random.c 69libcompat_la_SOURCES += compat/arc4random.c
70 70
71if !HAVE_GETENTROPY 71if !HAVE_GETENTROPY
72if HOST_AIX
73libcompat_la_SOURCES += compat/getentropy_aix.c
74endif
72if HOST_FREEBSD 75if HOST_FREEBSD
73libcompat_la_SOURCES += compat/getentropy_freebsd.c 76libcompat_la_SOURCES += compat/getentropy_freebsd.c
74endif 77endif
@@ -95,6 +98,9 @@ endif
95endif 98endif
96 99
97if !HAVE_ISSETUGID 100if !HAVE_ISSETUGID
101if HOST_AIX
102libcompat_la_SOURCES += compat/issetugid_aix.c
103endif
98if HOST_LINUX 104if HOST_LINUX
99libcompat_la_SOURCES += compat/issetugid_linux.c 105libcompat_la_SOURCES += compat/issetugid_linux.c
100endif 106endif
@@ -111,6 +117,7 @@ endif
111 117
112noinst_HEADERS = 118noinst_HEADERS =
113noinst_HEADERS += compat/arc4random.h 119noinst_HEADERS += compat/arc4random.h
120noinst_HEADERS += compat/arc4random_aix.h
114noinst_HEADERS += compat/arc4random_freebsd.h 121noinst_HEADERS += compat/arc4random_freebsd.h
115noinst_HEADERS += compat/arc4random_hpux.h 122noinst_HEADERS += compat/arc4random_hpux.h
116noinst_HEADERS += compat/arc4random_linux.h 123noinst_HEADERS += compat/arc4random_linux.h
diff --git a/crypto/compat/arc4random.h b/crypto/compat/arc4random.h
index ce1bbea..762aec2 100644
--- a/crypto/compat/arc4random.h
+++ b/crypto/compat/arc4random.h
@@ -3,7 +3,10 @@
3 3
4#include <sys/param.h> 4#include <sys/param.h>
5 5
6#if defined(__FreeBSD__) 6#if defined(_AIX)
7#include "arc4random_aix.h"
8
9#elif defined(__FreeBSD__)
7#include "arc4random_freebsd.h" 10#include "arc4random_freebsd.h"
8 11
9#elif defined(__hpux) 12#elif defined(__hpux)
diff --git a/crypto/compat/issetugid_aix.c b/crypto/compat/issetugid_aix.c
new file mode 100644
index 0000000..16f0a6d
--- /dev/null
+++ b/crypto/compat/issetugid_aix.c
@@ -0,0 +1,107 @@
1/* $OpenBSD: $ */
2
3/*
4 * Copyright (c) 2015 Michael Felt <aixtools@gmail.com>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20#include <sys/id.h>
21#include <sys/priv.h>
22
23#include <stdio.h>
24#include <unistd.h>
25
26/*
27 * AIX does not have issetugid().
28 * This experimental implementation uses getpriv() and get*id().
29 * First, try getpriv() and check equality of pv_priv values
30 * When these values are equal, using get*id() including login uid.
31 *
32 */
33int issetugid(void)
34{
35 /*
36 * Return fail-safe while we evaluate primitives in AIX. There does
37 * not yet appear to be a single atomic test to tell if privileges of
38 * the process changed from that of the user who is in control of the
39 * environment.
40 */
41 return (1);
42
43#define PEPRIV(a,b) a.pv_priv[b]
44 /*
45 * effective priv is what I can do now
46 * inherited priv is what the caller gave or could have given
47 * basically when inherited == 0 and effective != 0 then
48 * some kind of priv escalation has occurred
49 * when 'demoted' -- inherited != 0 but effective == 0
50 * there is also a change, so, will report 1 as well - to be safe
51 * PROBABLY there needs more study re: how RBAC subtley affects
52 * the priv_t values - for now, they are either zero - nothing added
53 * or non-zero - something added
54 */
55 priv_t effective,inherited;
56 int luid;
57 int euid, ruid;
58
59 getpriv(PRIV_EFFECTIVE, &effective, sizeof(priv_t));
60 getpriv(PRIV_INHERITED, &inherited, sizeof(priv_t));
61
62 if (PEPRIV(effective,0) | PEPRIV(effective,1)) { /* have something */
63 if ((PEPRIV(inherited,0) | PEPRIV(inherited,1)) == 0) /* had nothing - classic u+s bit */
64 return (1);
65 } else {
66 /*
67 * effective priv elevation is NULL/NONE
68 * was there something and removed via setuid()?
69 */
70 if (PEPRIV(inherited,0) | PEPRIV(inherited,1))
71 return (1);
72 }
73
74 /*
75 * if we get this far, then "no" differences in process priv noted
76 * compare the different uid
77 * the comparision of login id with effective says "TRUE" when different.
78 * this may not work as expected when using sudo for elevation
79 * again, looking at RBAC affects on priv may be more truthful
80 *
81 * ruid - real uid
82 * euid - effictive uid
83 * luid - login uid
84 */
85
86 /*
87 * if these differ (not common on AIX), return changed
88 */
89 ruid = getuid();
90 euid = geteuid();
91 if (euid != ruid)
92 return (1);
93
94 if (getgid() != getegid())
95 return (1);
96
97 /*
98 * luid == login id, su/sudo do not/cannot change this afaik
99 * perhaps this is "too strict", but same as in
100 * issetugid_win.c - err on the safe side for now
101 */
102 luid = getuidx(ID_LOGIN);
103 if (euid != luid)
104 return (1);
105
106 return (0);
107}