2 * Copyright (c) 2000 Wichert Akkerman <wakkerma@debian.org>
3 * Copyright (c) 2011 Denys Vlasenko <dvlasenk@redhat.com>
4 * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2014-2017 The strace developers.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* these constants are the same as in <linux/capability.h> */
38 #include "xlat/cap_mask0.h"
40 /* these constants are CAP_TO_INDEX'ed constants from <linux/capability.h> */
45 #include "xlat/cap_mask1.h"
47 /* these constants are the same as in <linux/capability.h> */
49 _LINUX_CAPABILITY_VERSION_1 = 0x19980330,
50 _LINUX_CAPABILITY_VERSION_2 = 0x20071026,
51 _LINUX_CAPABILITY_VERSION_3 = 0x20080522
54 #include "xlat/cap_version.h"
56 struct user_cap_header_struct {
61 struct user_cap_data_struct {
67 static const struct user_cap_header_struct *
68 get_cap_header(struct tcb *const tcp, const kernel_ulong_t addr)
70 static struct user_cap_header_struct header;
72 if (!addr || !verbose(tcp))
75 if (umove(tcp, addr, &header) < 0)
82 print_cap_header(struct tcb *const tcp, const kernel_ulong_t addr,
83 const struct user_cap_header_struct *const h)
91 printxval(cap_version, h->version,
92 "_LINUX_CAPABILITY_VERSION_???");
93 tprintf(", pid=%d}", h->pid);
97 print_cap_bits(const uint32_t lo, const uint32_t hi)
100 printflags(cap_mask0, lo, "CAP_???");
105 printflags(cap_mask1, hi, "CAP_???");
110 print_cap_data(struct tcb *const tcp, const kernel_ulong_t addr,
111 const struct user_cap_header_struct *const h)
113 struct user_cap_data_struct data[2];
121 if (_LINUX_CAPABILITY_VERSION_2 == h->version ||
122 _LINUX_CAPABILITY_VERSION_3 == h->version)
127 if (umoven_or_printaddr(tcp, addr, len * sizeof(data[0]), data))
130 tprints("{effective=");
131 print_cap_bits(data[0].effective, len > 1 ? data[1].effective : 0);
132 tprints(", permitted=");
133 print_cap_bits(data[0].permitted, len > 1 ? data[1].permitted : 0);
134 tprints(", inheritable=");
135 print_cap_bits(data[0].inheritable, len > 1 ? data[1].inheritable : 0);
141 const struct user_cap_header_struct *h;
144 h = get_cap_header(tcp, tcp->u_arg[0]);
145 print_cap_header(tcp, tcp->u_arg[0], h);
148 h = syserror(tcp) ? NULL : get_cap_header(tcp, tcp->u_arg[0]);
149 print_cap_data(tcp, tcp->u_arg[1], h);
156 const struct user_cap_header_struct *const h =
157 get_cap_header(tcp, tcp->u_arg[0]);
158 print_cap_header(tcp, tcp->u_arg[0], h);
160 print_cap_data(tcp, tcp->u_arg[1], h);