Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 1999 Ulrich Drepper <drepper@cygnus.com>
3 : : * Copyright (c) 2005 Roland McGrath <roland@redhat.com>
4 : : * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
5 : : * Copyright (c) 2014-2017 The strace developers.
6 : : * All rights reserved.
7 : : *
8 : : * Redistribution and use in source and binary forms, with or without
9 : : * modification, are permitted provided that the following conditions
10 : : * are met:
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.
18 : : *
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.
29 : : */
30 : :
31 : : #include "defs.h"
32 : :
33 : : #include <linux/sysctl.h>
34 : :
35 : : #include "xlat/sysctl_root.h"
36 : : #include "xlat/sysctl_kern.h"
37 : : #include "xlat/sysctl_vm.h"
38 : : #include "xlat/sysctl_net.h"
39 : : #include "xlat/sysctl_net_core.h"
40 : : #include "xlat/sysctl_net_unix.h"
41 : : #include "xlat/sysctl_net_ipv4.h"
42 : : #include "xlat/sysctl_net_ipv4_route.h"
43 : : #include "xlat/sysctl_net_ipv4_conf.h"
44 : : #include "xlat/sysctl_net_ipv6.h"
45 : : #include "xlat/sysctl_net_ipv6_route.h"
46 : :
47 : 0 : SYS_FUNC(sysctl)
48 : : {
49 : : struct __sysctl_args info;
50 : : int *name;
51 : : unsigned long size;
52 : :
53 [ # # ]: 0 : if (umove_or_printaddr(tcp, tcp->u_arg[0], &info))
54 : : return RVAL_DECODED;
55 : :
56 : 0 : size = sizeof(int) * (unsigned long) info.nlen;
57 [ # # ]: 0 : name = (size / sizeof(int) != (unsigned long) info.nlen) ? NULL : malloc(size);
58 [ # # # # ]: 0 : if (name == NULL ||
59 : 0 : umoven(tcp, (unsigned long) info.name, size, name) < 0) {
60 : 0 : free(name);
61 [ # # ]: 0 : if (entering(tcp))
62 : 0 : tprintf("{%p, %d, %p, %p, %p, %lu}",
63 : : info.name, info.nlen, info.oldval,
64 : : info.oldlenp, info.newval, (unsigned long)info.newlen);
65 : : return RVAL_DECODED;
66 : : }
67 : :
68 [ # # ]: 0 : if (entering(tcp)) {
69 : 0 : unsigned int cnt = 0, max_cnt;
70 : :
71 : 0 : tprints("{{");
72 : :
73 [ # # ]: 0 : if (info.nlen == 0)
74 : : goto out;
75 : 0 : printxval(sysctl_root, name[0], "CTL_???");
76 : 0 : ++cnt;
77 : :
78 [ # # ]: 0 : if (info.nlen == 1)
79 : : goto out;
80 [ # # # # ]: 0 : switch (name[0]) {
81 : : case CTL_KERN:
82 : 0 : tprints(", ");
83 : 0 : printxval(sysctl_kern, name[1], "KERN_???");
84 : 0 : ++cnt;
85 : 0 : break;
86 : : case CTL_VM:
87 : 0 : tprints(", ");
88 : 0 : printxval(sysctl_vm, name[1], "VM_???");
89 : 0 : ++cnt;
90 : 0 : break;
91 : : case CTL_NET:
92 : 0 : tprints(", ");
93 : 0 : printxval(sysctl_net, name[1], "NET_???");
94 : 0 : ++cnt;
95 : :
96 [ # # ]: 0 : if (info.nlen == 2)
97 : : goto out;
98 [ # # # # : 0 : switch (name[1]) {
# ]
99 : : case NET_CORE:
100 : 0 : tprints(", ");
101 : 0 : printxval(sysctl_net_core, name[2],
102 : : "NET_CORE_???");
103 : : break;
104 : : case NET_UNIX:
105 : 0 : tprints(", ");
106 : 0 : printxval(sysctl_net_unix, name[2],
107 : : "NET_UNIX_???");
108 : : break;
109 : : case NET_IPV4:
110 : 0 : tprints(", ");
111 : 0 : printxval(sysctl_net_ipv4, name[2],
112 : : "NET_IPV4_???");
113 : :
114 [ # # ]: 0 : if (info.nlen == 3)
115 : : goto out;
116 [ # # # ]: 0 : switch (name[2]) {
117 : : case NET_IPV4_ROUTE:
118 : 0 : tprints(", ");
119 : 0 : printxval(sysctl_net_ipv4_route,
120 : 0 : name[3],
121 : : "NET_IPV4_ROUTE_???");
122 : : break;
123 : : case NET_IPV4_CONF:
124 : 0 : tprints(", ");
125 : 0 : printxval(sysctl_net_ipv4_conf,
126 : 0 : name[3],
127 : : "NET_IPV4_CONF_???");
128 : : break;
129 : : default:
130 : : goto out;
131 : : }
132 : : break;
133 : : case NET_IPV6:
134 : 0 : tprints(", ");
135 : 0 : printxval(sysctl_net_ipv6, name[2],
136 : : "NET_IPV6_???");
137 : :
138 [ # # ]: 0 : if (info.nlen == 3)
139 : : goto out;
140 [ # # ]: 0 : switch (name[2]) {
141 : : case NET_IPV6_ROUTE:
142 : 0 : tprints(", ");
143 : 0 : printxval(sysctl_net_ipv6_route,
144 : 0 : name[3],
145 : : "NET_IPV6_ROUTE_???");
146 : : break;
147 : : default:
148 : : goto out;
149 : : }
150 : : break;
151 : : default:
152 : : goto out;
153 : : }
154 : : break;
155 : : default:
156 : : goto out;
157 : : }
158 : : out:
159 : 0 : max_cnt = info.nlen;
160 [ # # ][ # # ]: 0 : if (abbrev(tcp) && max_cnt > max_strlen)
161 : 0 : max_cnt = max_strlen;
162 [ # # ]: 0 : while (cnt < max_cnt)
163 : 0 : tprintf(", %x", name[cnt++]);
164 [ # # ]: 0 : if (cnt < (unsigned) info.nlen)
165 : 0 : tprints(", ...");
166 : 0 : tprintf("}, %d, ", info.nlen);
167 : : } else {
168 : 0 : size_t oldlen = 0;
169 [ # # ]: 0 : if (info.oldval == NULL) {
170 : 0 : tprints("NULL");
171 [ # # ]: 0 : } else if (umove(tcp, ptr_to_kulong(info.oldlenp), &oldlen) >= 0
172 [ # # ]: 0 : && info.nlen >= 2
173 [ # # ]: 0 : && ((name[0] == CTL_KERN
174 [ # # ]: 0 : && (name[1] == KERN_OSRELEASE
175 : 0 : || name[1] == KERN_OSTYPE
176 : : )))) {
177 : 0 : printpath(tcp, ptr_to_kulong(info.oldval));
178 : : } else {
179 : 0 : tprintf("%p", info.oldval);
180 : : }
181 : 0 : tprintf(", %lu, ", (unsigned long)oldlen);
182 [ # # ]: 0 : if (info.newval == NULL)
183 : 0 : tprints("NULL");
184 [ # # ]: 0 : else if (syserror(tcp))
185 : 0 : tprintf("%p", info.newval);
186 : : else
187 : 0 : printpath(tcp, ptr_to_kulong(info.newval));
188 : 0 : tprintf(", %lu", (unsigned long)info.newlen);
189 : : }
190 : :
191 : 0 : free(name);
192 : 0 : return 0;
193 : : }
|