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 | { |
Dmitry V. Levin | c70da7c | 2015-07-20 17:50:56 +0000 | [diff] [blame] | 54 | if (!addr || !h) { |
| 55 | printaddr(addr); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 56 | return; |
| 57 | } |
| 58 | |
| 59 | tprints("{"); |
| 60 | printxval(cap_version, h->version, |
| 61 | "_LINUX_CAPABILITY_VERSION_???"); |
| 62 | tprintf(", %d}", h->pid); |
| 63 | } |
| 64 | |
| 65 | static void |
| 66 | print_cap_bits(const uint32_t lo, const uint32_t hi) |
| 67 | { |
| 68 | if (lo || !hi) |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 69 | printflags(cap_mask0, lo, "CAP_???"); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 70 | |
| 71 | if (hi) { |
| 72 | if (lo) |
| 73 | tprints("|"); |
Dmitry V. Levin | 2f0808b | 2015-02-18 23:59:50 +0000 | [diff] [blame] | 74 | printflags(cap_mask1, hi, "CAP_???"); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | static void |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 79 | 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] | 80 | { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 81 | struct user_cap_data_struct data[2]; |
| 82 | unsigned int len; |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 83 | |
Dmitry V. Levin | c70da7c | 2015-07-20 17:50:56 +0000 | [diff] [blame] | 84 | if (!addr || !h) { |
| 85 | printaddr(addr); |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 86 | return; |
| 87 | } |
| 88 | |
| 89 | if (_LINUX_CAPABILITY_VERSION_2 == h->version || |
| 90 | _LINUX_CAPABILITY_VERSION_3 == h->version) |
| 91 | len = 2; |
| 92 | else |
| 93 | len = 1; |
| 94 | |
Dmitry V. Levin | c70da7c | 2015-07-20 17:50:56 +0000 | [diff] [blame] | 95 | if (umoven_or_printaddr(tcp, addr, len * sizeof(data[0]), data)) |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 96 | return; |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 97 | |
| 98 | tprints("{"); |
| 99 | print_cap_bits(data[0].effective, len > 1 ? data[1].effective : 0); |
| 100 | tprints(", "); |
| 101 | print_cap_bits(data[0].permitted, len > 1 ? data[1].permitted : 0); |
| 102 | tprints(", "); |
| 103 | print_cap_bits(data[0].inheritable, len > 1 ? data[1].inheritable : 0); |
| 104 | tprints("}"); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 107 | SYS_FUNC(capget) |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 108 | { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 109 | cap_user_header_t h; |
| 110 | |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 111 | if (entering(tcp)) { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 112 | h = get_cap_header(tcp, tcp->u_arg[0]); |
| 113 | print_cap_header(tcp, tcp->u_arg[0], h); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 114 | tprints(", "); |
| 115 | } else { |
Dmitry V. Levin | 4b9c68b | 2014-12-05 00:21:23 +0000 | [diff] [blame] | 116 | h = syserror(tcp) ? NULL : get_cap_header(tcp, tcp->u_arg[0]); |
| 117 | print_cap_data(tcp, tcp->u_arg[1], h); |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 118 | } |
| 119 | return 0; |
| 120 | } |
| 121 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 122 | SYS_FUNC(capset) |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 123 | { |
Dmitry V. Levin | ff33aac | 2015-07-20 17:54:02 +0000 | [diff] [blame^] | 124 | cap_user_header_t h = get_cap_header(tcp, tcp->u_arg[0]); |
| 125 | print_cap_header(tcp, tcp->u_arg[0], h); |
| 126 | tprints(", "); |
| 127 | print_cap_data(tcp, tcp->u_arg[1], h); |
| 128 | |
| 129 | return RVAL_DECODED; |
Dmitry V. Levin | 5e7987b | 2014-12-03 20:30:15 +0000 | [diff] [blame] | 130 | } |