Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 1 | #include "defs.h" |
| 2 | |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 3 | /* these constants are the same as in <linux/capability.h> */ |
Dmitry V. Levin | bf7fdfa | 2014-12-03 20:39:20 +0000 | [diff] [blame] | 4 | enum { |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 5 | #include "caps0.h" |
Dmitry V. Levin | bf7fdfa | 2014-12-03 20:39:20 +0000 | [diff] [blame] | 6 | }; |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 7 | |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 8 | #include "xlat/cap_mask0.h" |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 9 | |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 10 | /* these constants are CAP_TO_INDEX'ed constants from <linux/capability.h> */ |
| 11 | enum { |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 12 | #include "caps1.h" |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 13 | }; |
| 14 | |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 15 | #include "xlat/cap_mask1.h" |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 16 | |
| 17 | /* these constants are the same as in <linux/capability.h> */ |
Dmitry V. Levin | bf7fdfa | 2014-12-03 20:39:20 +0000 | [diff] [blame] | 18 | enum { |
| 19 | _LINUX_CAPABILITY_VERSION_1 = 0x19980330, |
| 20 | _LINUX_CAPABILITY_VERSION_2 = 0x20071026, |
| 21 | _LINUX_CAPABILITY_VERSION_3 = 0x20080522 |
| 22 | }; |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 23 | |
| 24 | #include "xlat/cap_version.h" |
| 25 | |
Dmitry V. Levin | bf7fdfa | 2014-12-03 20:39:20 +0000 | [diff] [blame] | 26 | typedef struct user_cap_header_struct { |
| 27 | uint32_t version; |
| 28 | int pid; |
| 29 | } *cap_user_header_t; |
| 30 | |
| 31 | typedef struct user_cap_data_struct { |
| 32 | uint32_t effective; |
| 33 | uint32_t permitted; |
| 34 | uint32_t inheritable; |
| 35 | } *cap_user_data_t; |
| 36 | |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 37 | static cap_user_header_t |
| 38 | get_cap_header(struct tcb *tcp, unsigned long addr) |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 39 | { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 40 | static struct user_cap_header_struct header; |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 41 | |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 42 | if (!addr || !verbose(tcp)) |
| 43 | return NULL; |
| 44 | |
| 45 | if (umove(tcp, addr, &header) < 0) |
| 46 | return NULL; |
| 47 | |
| 48 | return &header; |
| 49 | } |
| 50 | |
| 51 | static void |
| 52 | print_cap_header(struct tcb *tcp, unsigned long addr, cap_user_header_t h) |
| 53 | { |
| 54 | if (!addr) { |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 55 | tprints("NULL"); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 56 | return; |
| 57 | } |
| 58 | |
| 59 | if (!h) { |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 60 | tprintf("%#lx", addr); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 61 | return; |
| 62 | } |
| 63 | |
| 64 | tprints("{"); |
| 65 | printxval(cap_version, h->version, |
| 66 | "_LINUX_CAPABILITY_VERSION_???"); |
| 67 | tprintf(", %d}", h->pid); |
| 68 | } |
| 69 | |
| 70 | static void |
| 71 | print_cap_bits(const uint32_t lo, const uint32_t hi) |
| 72 | { |
| 73 | if (lo || !hi) |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 74 | printflags(cap_mask0, lo, "CAP_???"); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 75 | |
| 76 | if (hi) { |
| 77 | if (lo) |
| 78 | tprints("|"); |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 79 | printflags(cap_mask1, hi, "CAP_???"); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | static void |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 84 | print_cap_data(struct tcb *tcp, unsigned long addr, const cap_user_header_t h) |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 85 | { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 86 | struct user_cap_data_struct data[2]; |
| 87 | unsigned int len; |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 88 | |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 89 | if (!addr) { |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 90 | tprints("NULL"); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 91 | return; |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 92 | } |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 93 | |
| 94 | if (!h || !verbose(tcp) || |
| 95 | (exiting(tcp) && syserror(tcp))) { |
| 96 | tprintf("%#lx", addr); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | if (_LINUX_CAPABILITY_VERSION_2 == h->version || |
| 101 | _LINUX_CAPABILITY_VERSION_3 == h->version) |
| 102 | len = 2; |
| 103 | else |
| 104 | len = 1; |
| 105 | |
Denys Vlasenko | 7e69ed9 | 2015-03-21 19:50:53 +0100 | [diff] [blame] | 106 | if (umoven(tcp, addr, len * sizeof(data[0]), data) < 0) { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 107 | tprintf("%#lx", addr); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | tprints("{"); |
| 112 | print_cap_bits(data[0].effective, len > 1 ? data[1].effective : 0); |
| 113 | tprints(", "); |
| 114 | print_cap_bits(data[0].permitted, len > 1 ? data[1].permitted : 0); |
| 115 | tprints(", "); |
| 116 | print_cap_bits(data[0].inheritable, len > 1 ? data[1].inheritable : 0); |
| 117 | tprints("}"); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 120 | SYS_FUNC(capget) |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 121 | { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 122 | cap_user_header_t h; |
| 123 | |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 124 | if (entering(tcp)) { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 125 | h = get_cap_header(tcp, tcp->u_arg[0]); |
| 126 | print_cap_header(tcp, tcp->u_arg[0], h); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 127 | tprints(", "); |
| 128 | } else { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 129 | h = syserror(tcp) ? NULL : get_cap_header(tcp, tcp->u_arg[0]); |
| 130 | print_cap_data(tcp, tcp->u_arg[1], h); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 131 | } |
| 132 | return 0; |
| 133 | } |
| 134 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 135 | SYS_FUNC(capset) |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 136 | { |
| 137 | if (entering(tcp)) { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 138 | cap_user_header_t h = get_cap_header(tcp, tcp->u_arg[0]); |
| 139 | print_cap_header(tcp, tcp->u_arg[0], h); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 140 | tprints(", "); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 141 | print_cap_data(tcp, tcp->u_arg[1], h); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 142 | } |
| 143 | return 0; |
| 144 | } |