aboutsummaryrefslogtreecommitdiffstats
path: root/debian/patches/04_drop-capabilities.dpatch
blob: 8ee8786667849a1f13fa759040b5dfe7c2c1319b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#! /bin/sh /usr/share/dpatch/dpatch-run
## 04_drop-capabilities.dpatch by  <fpeters@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Drop all capabilities but CAP_NET_RAW

@DPATCH@
diff -urNad wireshark-0.99.2~/configure.in wireshark-0.99.2/configure.in
--- wireshark-0.99.2~/configure.in	2006-07-18 21:59:41.000000000 +0200
+++ wireshark-0.99.2/configure.in	2006-07-18 21:59:46.000000000 +0200
@@ -831,6 +831,47 @@
 fi
 
 
+dnl libcap check
+AC_MSG_CHECKING(whether to use libcap to improve security)
+
+AC_ARG_WITH(cap,
+[  --with-cap[[=DIR]]       use libcap (located in directory DIR, if supplied) to improve security.  [[default=yes, if available]]],
+[
+	if test $withval = no
+	then
+		want_cap=no
+	elif test $withval = yes
+	then
+		want_cap=yes
+	else
+		want_cap=yes
+		cap_dir=$withval
+	fi
+],[
+	#
+	# Use libcap if it's present, otherwise don't.
+	#
+	want_cap=ifavailable
+	cap_dir=
+])
+if test "x$want_cap" = "xno" ; then
+        AC_MSG_RESULT(no)
+	cap_message="no (disabled by explicit request)"
+else
+        AC_MSG_RESULT(yes)
+        AC_CHECK_LIB(cap, cap_init, [
+		AC_DEFINE(HAVE_LIBCAP, 1, [
+			Define if libcap is available to restrict process capabilities
+		])
+		LIBS="$LIBS -lcap"
+		cap_message="yes"
+	], [
+		AC_MSG_WARN([libcap check failed])
+		cap_message="no (check failed)"
+	])
+fi
+
+
 dnl Check if wireshark should be installed setuid
 AC_ARG_ENABLE(setuid-install,
 [  --enable-setuid-install install wireshark as setuid. DANGEROUS!!! [default=no]],enable_setuid_install=$enableval,enable_setuid_install=no)
@@ -1448,3 +1489,4 @@
 echo "          Use IPv6 name resolution : $enable_ipv6"
 echo "     Use UCD SNMP/Net-SNMP library : $snmp_libs_message"
 echo "                Use gnutls library : $tls_message"
+echo "                   Use cap library : $cap_message"
diff -urNad wireshark-0.99.2~/gtk/main.c wireshark-0.99.2/gtk/main.c
--- wireshark-0.99.2~/gtk/main.c	2006-07-17 21:56:45.000000000 +0200
+++ wireshark-0.99.2/gtk/main.c	2006-07-18 21:59:46.000000000 +0200
@@ -1718,6 +1718,9 @@
 {
     gchar *capture_msg;
 
+#ifdef HAVE_LIBCAP
+  dropexcesscapabilities();
+#endif
 
 	gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
 
diff -urNad wireshark-0.99.2~/tshark.c wireshark-0.99.2/tshark.c
--- wireshark-0.99.2~/tshark.c	2006-07-17 22:00:06.000000000 +0200
+++ wireshark-0.99.2/tshark.c	2006-07-18 22:01:35.000000000 +0200
@@ -749,6 +749,10 @@
   capture_opts_init(&capture_opts, NULL /* cfile */);
 #endif
 
+#ifdef HAVE_LIBCAP
+  dropexcesscapabilities();
+#endif
+
   timestamp_set_type(TS_RELATIVE);
   timestamp_set_precision(TS_PREC_AUTO);
 
diff -urNad wireshark-0.99.2~/util.c wireshark-0.99.2/util.c
--- wireshark-0.99.2~/util.c	2006-07-17 22:00:05.000000000 +0200
+++ wireshark-0.99.2/util.c	2006-07-18 21:59:46.000000000 +0200
@@ -40,6 +40,10 @@
 #include <epan/address.h>
 #include <epan/addr_resolv.h>
 
+#ifdef HAVE_LIBCAP
+#include <sys/capability.h>
+#endif
+
 #include "util.h"
 
 /*
@@ -180,3 +184,46 @@
 	}
 	return "";
 }
+
+
+#ifdef HAVE_LIBCAP
+void dropexcesscapabilities(void)
+{
+	cap_t cap_d;
+	cap_value_t cap_values[] = {
+		/* capabilities we need to keep */
+		CAP_NET_RAW,
+		CAP_DAC_READ_SEARCH
+	};
+	cap_flag_value_t current_cap;
+
+	cap_d = cap_get_proc();
+	if (!cap_d) {
+		g_warning("Could not get capabilities\n");
+		return;
+	}
+
+	cap_get_flag(cap_d, CAP_NET_RAW, CAP_EFFECTIVE, &current_cap);
+	cap_free(&cap_d);
+	if (current_cap == CAP_CLEAR) {
+		return;
+	}
+
+	cap_d = cap_init();
+	if (!cap_d) {
+		g_warning("Could not alloc cap struct\n");
+		return;
+	}
+
+	cap_clear(cap_d);
+	cap_set_flag(cap_d, CAP_PERMITTED, 2, cap_values, CAP_SET);
+	cap_set_flag(cap_d, CAP_EFFECTIVE, 2, cap_values, CAP_SET);
+
+	if (cap_set_proc(cap_d) != 0) {
+		g_warning("Could not set capabilities: %s\n", strerror(errno));
+		cap_free(&cap_d);
+		return;
+	}
+	cap_free(&cap_d);
+}
+#endif /* HAVE_LIBCAP */
diff -urNad wireshark-0.99.2~/util.h wireshark-0.99.2/util.h
--- wireshark-0.99.2~/util.h	2006-07-17 22:00:06.000000000 +0200
+++ wireshark-0.99.2/util.h	2006-07-18 22:01:52.000000000 +0200
@@ -53,6 +53,15 @@
 const char *get_conn_cfilter(void);
 
 
+#ifdef HAVE_LIBCAP
+/*
+ * Limit the potential impact of undiscovered security vulnerabilities by
+ * dropping all capabilities except the sniffer capability we need to do our
+ * job.
+ */
+void dropexcesscapabilities(void);
+#endif /* HAVE_LIBCAP */
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
#! /bin/sh /usr/share/dpatch/dpatch-run
## 04_drop-capabilities.dpatch by  <fpeters@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Drop all capabilities but CAP_NET_RAW

@DPATCH@
diff -urNad --exclude=CVS --exclude=.svn ./config.h.in /tmp/dpep-work.rT2mW8/ethereal-0.10.12/config.h.in
--- ./config.h.in	2005-07-31 12:50:13.000000000 +0200
+++ /tmp/dpep-work.rT2mW8/ethereal-0.10.12/config.h.in	2005-07-31 12:54:13.000000000 +0200
@@ -55,6 +55,9 @@
 /* Define if krb5.h defines KEYTYPE_ARCFOUR_56 */
 #undef HAVE_KEYTYPE_ARCFOUR_56
 
+/* Define if libcap is available to restrict process capabilities */
+#undef HAVE_LIBCAP
+
 /* Define to use libpcap library */
 #undef HAVE_LIBPCAP
 
diff -urNad --exclude=CVS --exclude=.svn ./configure.in /tmp/dpep-work.rT2mW8/ethereal-0.10.12/configure.in
--- ./configure.in	2005-07-31 12:50:26.000000000 +0200
+++ /tmp/dpep-work.rT2mW8/ethereal-0.10.12/configure.in	2005-07-31 12:54:13.000000000 +0200
@@ -737,6 +737,47 @@
 fi
 
 
+dnl libcap check
+AC_MSG_CHECKING(whether to use libcap to improve security)
+
+AC_ARG_WITH(cap,
+[  --with-cap[[=DIR]]       use libcap (located in directory DIR, if supplied) to improve security.  [[default=yes, if available]]],
+[
+	if test $withval = no
+	then
+		want_cap=no
+	elif test $withval = yes
+	then
+		want_cap=yes
+	else
+		want_cap=yes
+		cap_dir=$withval
+	fi
+],[
+	#
+	# Use libcap if it's present, otherwise don't.
+	#
+	want_cap=ifavailable
+	cap_dir=
+])
+if test "x$want_cap" = "xno" ; then
+        AC_MSG_RESULT(no)
+	cap_message="no (disabled by explicit request)"
+else
+        AC_MSG_RESULT(yes)
+        AC_CHECK_LIB(cap, cap_init, [
+		AC_DEFINE(HAVE_LIBCAP, 1, [
+			Define if libcap is available to restrict process capabilities
+		])
+		LIBS="$LIBS -lcap"
+		cap_message="yes"
+	], [
+		AC_MSG_WARN([libcap check failed])
+		cap_message="no (check failed)"
+	])
+fi
+
+
 dnl Check if wireshark should be installed setuid
 AC_ARG_ENABLE(setuid-install,
 [  --enable-setuid-install install ethereal as setuid. DANGEROUS!!! [default=no]],enable_setuid_install=$enableval,enable_setuid_install=no)
@@ -1322,3 +1363,4 @@
 echo "            Use SSL crypto library : $ssl_message"
 echo "          Use IPv6 name resolution : $enable_ipv6"
 echo "     Use UCD SNMP/Net-SNMP library : $snmp_libs_message"
+echo "                   Use cap library : $cap_message"
diff -urNad --exclude=CVS --exclude=.svn ./gtk/main.c /tmp/dpep-work.rT2mW8/ethereal-0.10.12/gtk/main.c
--- ./gtk/main.c	2005-07-31 12:50:37.000000000 +0200
+++ /tmp/dpep-work.rT2mW8/ethereal-0.10.12/gtk/main.c	2005-07-31 12:54:13.000000000 +0200
@@ -1671,6 +1671,9 @@
   runtime_info_str = g_string_new("Running ");
   get_runtime_version_info(runtime_info_str);
 
+#ifdef HAVE_LIBCAP
+  dropexcesscapabilities();
+#endif
 
   /*** "pre-scan" the command line parameters, if we have "console only" parameters ***/
   /* (e.g. don't start GTK+, if we only have to show the command line help) */
diff -urNad --exclude=CVS --exclude=.svn ./tethereal.c /tmp/dpep-work.rT2mW8/ethereal-0.10.12/tethereal.c
--- ./tethereal.c	2005-07-31 12:49:37.000000000 +0200
+++ /tmp/dpep-work.rT2mW8/ethereal-0.10.12/tethereal.c	2005-07-31 12:54:13.000000000 +0200
@@ -663,6 +663,10 @@
   capture_opts_init(&capture_opts, NULL /* cfile */);
 #endif
 
+#ifdef HAVE_LIBCAP
+  dropexcesscapabilities();
+#endif
+
   set_timestamp_setting(TS_RELATIVE);
 
   /* Register all dissectors; we must do this before checking for the
diff -urNad --exclude=CVS --exclude=.svn ./util.c /tmp/dpep-work.rT2mW8/ethereal-0.10.12/util.c
--- ./util.c	2005-07-31 12:49:42.000000000 +0200
+++ /tmp/dpep-work.rT2mW8/ethereal-0.10.12/util.c	2005-07-31 12:56:35.000000000 +0200
@@ -69,6 +69,10 @@
 #include <windows.h>
 #endif
 
+#ifdef HAVE_LIBCAP
+#include <sys/capability.h>
+#endif
+
 #include "util.h"
 
 /*
@@ -311,3 +315,46 @@
 	}
 	return "";
 }
+
+
+#ifdef HAVE_LIBCAP
+void dropexcesscapabilities(void)
+{
+	cap_t cap_d;
+	cap_value_t cap_values[] = {
+		/* capabilities we need to keep */
+		CAP_NET_RAW,
+		CAP_DAC_READ_SEARCH
+	};
+	cap_flag_value_t current_cap;
+
+	cap_d = cap_get_proc();
+	if (!cap_d) {
+		g_warning("Could not get capabilities\n");
+		return;
+	}
+
+	cap_get_flag(cap_d, CAP_NET_RAW, CAP_EFFECTIVE, &current_cap);
+	cap_free(&cap_d);
+	if (current_cap == CAP_CLEAR) {
+		return;
+	}
+
+	cap_d = cap_init();
+	if (!cap_d) {
+		g_warning("Could not alloc cap struct\n");
+		return;
+	}
+
+	cap_clear(cap_d);
+	cap_set_flag(cap_d, CAP_PERMITTED, 2, cap_values, CAP_SET);
+	cap_set_flag(cap_d, CAP_EFFECTIVE, 2, cap_values, CAP_SET);
+
+	if (cap_set_proc(cap_d) != 0) {
+		g_warning("Could not set capabilities: %s\n", strerror(errno));
+		cap_free(&cap_d);
+		return;
+	}
+	cap_free(&cap_d);
+}
+#endif /* HAVE_LIBCAP */
diff -urNad --exclude=CVS --exclude=.svn ./util.h /tmp/dpep-work.rT2mW8/ethereal-0.10.12/util.h
--- ./util.h	2005-07-31 12:49:42.000000000 +0200
+++ /tmp/dpep-work.rT2mW8/ethereal-0.10.12/util.h	2005-07-31 12:54:13.000000000 +0200
@@ -43,6 +43,15 @@
 /* Create a capture filter for the connection */
 char *get_conn_cfilter(void);
 
+#ifdef HAVE_LIBCAP
+/*
+ * Limit the potential impact of undiscovered security vulnerabilities by
+ * dropping all capabilities except the sniffer capability we need to do our
+ * job.
+ */
+void dropexcesscapabilities(void);
+#endif /* HAVE_LIBCAP */
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */