1 |
commit: 45ecdfc0d977755e3f15ba10a6b4fdb93581357b |
2 |
Author: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jun 27 19:50:31 2015 +0000 |
4 |
Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Jun 27 19:50:31 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=45ecdfc0 |
7 |
|
8 |
Update kdbus patch, rename for clarity |
9 |
|
10 |
0000_README | 2 +- |
11 |
...kdbus-4.1-rc1.patch => 5015_kdbus-6-27-15.patch | 1765 ++++++-------------- |
12 |
2 files changed, 504 insertions(+), 1263 deletions(-) |
13 |
|
14 |
diff --git a/0000_README b/0000_README |
15 |
index d33ec2f..dd82b40 100644 |
16 |
--- a/0000_README |
17 |
+++ b/0000_README |
18 |
@@ -83,6 +83,6 @@ Patch: 5010_enable-additional-cpu-optimizations-for-gcc-4.9.patch |
19 |
From: https://github.com/graysky2/kernel_gcc_patch/ |
20 |
Desc: Kernel patch enables gcc >= v4.9 optimizations for additional CPUs. |
21 |
|
22 |
-Patch: 5015_kdbus-4.1-rc1.patch |
23 |
+Patch: 5015_kdbus-6-27-15.patch |
24 |
From: https://lkml.org |
25 |
Desc: Kernel-level IPC implementation |
26 |
|
27 |
diff --git a/5015_kdbus-4.1-rc1.patch b/5015_kdbus-6-27-15.patch |
28 |
similarity index 96% |
29 |
rename from 5015_kdbus-4.1-rc1.patch |
30 |
rename to 5015_kdbus-6-27-15.patch |
31 |
index a5169bd..bc17abe 100644 |
32 |
--- a/5015_kdbus-4.1-rc1.patch |
33 |
+++ b/5015_kdbus-6-27-15.patch |
34 |
@@ -1,15 +1,15 @@ |
35 |
diff --git a/Documentation/Makefile b/Documentation/Makefile |
36 |
-index 6883a1b..5e3fde6 100644 |
37 |
+index bc05482..e2127a7 100644 |
38 |
--- a/Documentation/Makefile |
39 |
+++ b/Documentation/Makefile |
40 |
@@ -1,4 +1,4 @@ |
41 |
- subdir-y := accounting arm auxdisplay blackfin connector \ |
42 |
+ subdir-y := accounting auxdisplay blackfin connector \ |
43 |
- filesystems filesystems ia64 laptops mic misc-devices \ |
44 |
+ filesystems filesystems ia64 kdbus laptops mic misc-devices \ |
45 |
networking pcmcia prctl ptp spi timers vDSO video4linux \ |
46 |
watchdog |
47 |
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt |
48 |
-index 8136e1f..54e091e 100644 |
49 |
+index 51f4221..ec7c81b 100644 |
50 |
--- a/Documentation/ioctl/ioctl-number.txt |
51 |
+++ b/Documentation/ioctl/ioctl-number.txt |
52 |
@@ -292,6 +292,7 @@ Code Seq#(hex) Include File Comments |
53 |
@@ -2262,7 +2262,7 @@ index 0000000..8c2a90e |
54 |
+</refentry> |
55 |
diff --git a/Documentation/kdbus/kdbus.item.xml b/Documentation/kdbus/kdbus.item.xml |
56 |
new file mode 100644 |
57 |
-index 0000000..09f8b90 |
58 |
+index 0000000..ee09dfa |
59 |
--- /dev/null |
60 |
+++ b/Documentation/kdbus/kdbus.item.xml |
61 |
@@ -0,0 +1,839 @@ |
62 |
@@ -2337,13 +2337,13 @@ index 0000000..09f8b90 |
63 |
+#define KDBUS_ALIGN8(val) (((val) + 7) & ~7) |
64 |
+ |
65 |
+#define KDBUS_ITEM_NEXT(item) \ |
66 |
-+ (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size)) |
67 |
++ (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size)) |
68 |
+ |
69 |
+#define KDBUS_ITEM_FOREACH(item, head, first) \ |
70 |
-+ for (item = (head)->first; \ |
71 |
++ for ((item) = (head)->first; \ |
72 |
+ ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) && \ |
73 |
+ ((uint8_t *)(item) >= (uint8_t *)(head)); \ |
74 |
-+ item = KDBUS_ITEM_NEXT(item)) |
75 |
++ (item) = KDBUS_ITEM_NEXT(item)) |
76 |
+ ]]></programlisting> |
77 |
+ </refsect2> |
78 |
+ </refsect1> |
79 |
@@ -7450,10 +7450,10 @@ index 0000000..52565ea |
80 |
+ </template> |
81 |
+</stylesheet> |
82 |
diff --git a/MAINTAINERS b/MAINTAINERS |
83 |
-index 6239a30..e924246 100644 |
84 |
+index d8afd29..02f7668 100644 |
85 |
--- a/MAINTAINERS |
86 |
+++ b/MAINTAINERS |
87 |
-@@ -5503,6 +5503,19 @@ S: Maintained |
88 |
+@@ -5585,6 +5585,19 @@ S: Maintained |
89 |
F: Documentation/kbuild/kconfig-language.txt |
90 |
F: scripts/kconfig/ |
91 |
|
92 |
@@ -7474,10 +7474,10 @@ index 6239a30..e924246 100644 |
93 |
M: Vivek Goyal <vgoyal@××××××.com> |
94 |
M: Haren Myneni <hbabu@××××××.com> |
95 |
diff --git a/Makefile b/Makefile |
96 |
-index 1100ff3..08c9818 100644 |
97 |
+index f5c8983..a1c8d57 100644 |
98 |
--- a/Makefile |
99 |
+++ b/Makefile |
100 |
-@@ -1350,6 +1350,7 @@ $(help-board-dirs): help-%: |
101 |
+@@ -1343,6 +1343,7 @@ $(help-board-dirs): help-%: |
102 |
%docs: scripts_basic FORCE |
103 |
$(Q)$(MAKE) $(build)=scripts build_docproc |
104 |
$(Q)$(MAKE) $(build)=Documentation/DocBook $@ |
105 |
@@ -7486,10 +7486,10 @@ index 1100ff3..08c9818 100644 |
106 |
else # KBUILD_EXTMOD |
107 |
|
108 |
diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild |
109 |
-index 68ceb97..ddc413e 100644 |
110 |
+index 1a0006a..4842a98 100644 |
111 |
--- a/include/uapi/linux/Kbuild |
112 |
+++ b/include/uapi/linux/Kbuild |
113 |
-@@ -214,6 +214,7 @@ header-y += ixjuser.h |
114 |
+@@ -215,6 +215,7 @@ header-y += ixjuser.h |
115 |
header-y += jffs2.h |
116 |
header-y += joystick.h |
117 |
header-y += kcmp.h |
118 |
@@ -8483,10 +8483,10 @@ index 0000000..00a6e14 |
119 |
+ |
120 |
+#endif /* _UAPI_KDBUS_H_ */ |
121 |
diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h |
122 |
-index 7d664ea..1cf05c0 100644 |
123 |
+index 7b1425a..ce2ac5a 100644 |
124 |
--- a/include/uapi/linux/magic.h |
125 |
+++ b/include/uapi/linux/magic.h |
126 |
-@@ -74,4 +74,6 @@ |
127 |
+@@ -76,4 +76,6 @@ |
128 |
#define BTRFS_TEST_MAGIC 0x73727279 |
129 |
#define NSFS_MAGIC 0x6e736673 |
130 |
|
131 |
@@ -8494,7 +8494,7 @@ index 7d664ea..1cf05c0 100644 |
132 |
+ |
133 |
#endif /* __LINUX_MAGIC_H__ */ |
134 |
diff --git a/init/Kconfig b/init/Kconfig |
135 |
-index f5dbc6d..6bda631 100644 |
136 |
+index dc24dec..9388071 100644 |
137 |
--- a/init/Kconfig |
138 |
+++ b/init/Kconfig |
139 |
@@ -261,6 +261,19 @@ config POSIX_MQUEUE_SYSCTL |
140 |
@@ -8557,10 +8557,10 @@ index 0000000..7ee9271 |
141 |
+obj-$(CONFIG_KDBUS) += kdbus.o |
142 |
diff --git a/ipc/kdbus/bus.c b/ipc/kdbus/bus.c |
143 |
new file mode 100644 |
144 |
-index 0000000..9d0679e |
145 |
+index 0000000..bbdf0f2 |
146 |
--- /dev/null |
147 |
+++ b/ipc/kdbus/bus.c |
148 |
-@@ -0,0 +1,560 @@ |
149 |
+@@ -0,0 +1,542 @@ |
150 |
+/* |
151 |
+ * Copyright (C) 2013-2015 Kay Sievers |
152 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
153 |
@@ -8848,8 +8848,6 @@ index 0000000..9d0679e |
154 |
+ continue; |
155 |
+ |
156 |
+ if (conn_src) { |
157 |
-+ u64 attach_flags; |
158 |
-+ |
159 |
+ /* |
160 |
+ * Anyone can send broadcasts, as they have no |
161 |
+ * destination. But a receiver needs TALK access to |
162 |
@@ -8858,19 +8856,12 @@ index 0000000..9d0679e |
163 |
+ if (!kdbus_conn_policy_talk(conn_dst, NULL, conn_src)) |
164 |
+ continue; |
165 |
+ |
166 |
-+ attach_flags = kdbus_meta_calc_attach_flags(conn_src, |
167 |
-+ conn_dst); |
168 |
-+ |
169 |
-+ /* |
170 |
-+ * Keep sending messages even if we cannot acquire the |
171 |
-+ * requested metadata. It's up to the receiver to drop |
172 |
-+ * messages that lack expected metadata. |
173 |
-+ */ |
174 |
-+ if (!conn_src->faked_meta) |
175 |
-+ kdbus_meta_proc_collect(kmsg->proc_meta, |
176 |
-+ attach_flags); |
177 |
-+ kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, conn_src, |
178 |
-+ attach_flags); |
179 |
++ ret = kdbus_kmsg_collect_metadata(kmsg, conn_src, |
180 |
++ conn_dst); |
181 |
++ if (ret < 0) { |
182 |
++ kdbus_conn_lost_message(conn_dst); |
183 |
++ continue; |
184 |
++ } |
185 |
+ } else { |
186 |
+ /* |
187 |
+ * Check if there is a policy db that prevents the |
188 |
@@ -8916,22 +8907,13 @@ index 0000000..9d0679e |
189 |
+ |
190 |
+ down_read(&bus->conn_rwlock); |
191 |
+ list_for_each_entry(conn_dst, &bus->monitors_list, monitor_entry) { |
192 |
-+ /* |
193 |
-+ * Collect metadata requested by the destination connection. |
194 |
-+ * Ignore errors, as receivers need to check metadata |
195 |
-+ * availability, anyway. So it's still better to send messages |
196 |
-+ * that lack data, than to skip it entirely. |
197 |
-+ */ |
198 |
+ if (conn_src) { |
199 |
-+ u64 attach_flags; |
200 |
-+ |
201 |
-+ attach_flags = kdbus_meta_calc_attach_flags(conn_src, |
202 |
-+ conn_dst); |
203 |
-+ if (!conn_src->faked_meta) |
204 |
-+ kdbus_meta_proc_collect(kmsg->proc_meta, |
205 |
-+ attach_flags); |
206 |
-+ kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, conn_src, |
207 |
-+ attach_flags); |
208 |
++ ret = kdbus_kmsg_collect_metadata(kmsg, conn_src, |
209 |
++ conn_dst); |
210 |
++ if (ret < 0) { |
211 |
++ kdbus_conn_lost_message(conn_dst); |
212 |
++ continue; |
213 |
++ } |
214 |
+ } |
215 |
+ |
216 |
+ ret = kdbus_conn_entry_insert(conn_src, conn_dst, kmsg, NULL); |
217 |
@@ -8946,7 +8928,7 @@ index 0000000..9d0679e |
218 |
+ * @domain: domain to operate on |
219 |
+ * @argp: command payload |
220 |
+ * |
221 |
-+ * Return: Newly created bus on success, ERR_PTR on failure. |
222 |
++ * Return: NULL or newly created bus on success, ERR_PTR on failure. |
223 |
+ */ |
224 |
+struct kdbus_bus *kdbus_cmd_bus_make(struct kdbus_domain *domain, |
225 |
+ void __user *argp) |
226 |
@@ -9040,7 +9022,7 @@ index 0000000..9d0679e |
227 |
+ * @conn: connection to operate on |
228 |
+ * @argp: command payload |
229 |
+ * |
230 |
-+ * Return: 0 on success, negative error code on failure. |
231 |
++ * Return: >=0 on success, negative error code on failure. |
232 |
+ */ |
233 |
+int kdbus_cmd_bus_creator_info(struct kdbus_conn *conn, void __user *argp) |
234 |
+{ |
235 |
@@ -9230,10 +9212,10 @@ index 0000000..5bea5ef |
236 |
+#endif |
237 |
diff --git a/ipc/kdbus/connection.c b/ipc/kdbus/connection.c |
238 |
new file mode 100644 |
239 |
-index 0000000..ab476fa |
240 |
+index 0000000..9993753 |
241 |
--- /dev/null |
242 |
+++ b/ipc/kdbus/connection.c |
243 |
-@@ -0,0 +1,2214 @@ |
244 |
+@@ -0,0 +1,2178 @@ |
245 |
+/* |
246 |
+ * Copyright (C) 2013-2015 Kay Sievers |
247 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
248 |
@@ -9668,7 +9650,7 @@ index 0000000..ab476fa |
249 |
+ * directly, and won't cause any notifications. |
250 |
+ */ |
251 |
+ if (!kdbus_conn_is_monitor(conn)) { |
252 |
-+ ret = kdbus_notify_id_change(conn->ep->bus, KDBUS_ITEM_ID_ADD, |
253 |
++ ret = kdbus_notify_id_change(bus, KDBUS_ITEM_ID_ADD, |
254 |
+ conn->id, conn->flags); |
255 |
+ if (ret < 0) |
256 |
+ goto exit_disconnect; |
257 |
@@ -9795,17 +9777,16 @@ index 0000000..ab476fa |
258 |
+ hash_for_each(bus->conn_hash, i, c, hentry) { |
259 |
+ mutex_lock(&c->lock); |
260 |
+ list_for_each_entry_safe(r, r_tmp, &c->reply_list, entry) { |
261 |
-+ if (r->reply_src == conn) { |
262 |
-+ if (r->sync) { |
263 |
-+ kdbus_sync_reply_wakeup(r, -EPIPE); |
264 |
-+ kdbus_reply_unlink(r); |
265 |
-+ continue; |
266 |
-+ } |
267 |
++ if (r->reply_src != conn) |
268 |
++ continue; |
269 |
+ |
270 |
++ if (r->sync) |
271 |
++ kdbus_sync_reply_wakeup(r, -EPIPE); |
272 |
++ else |
273 |
+ /* send a 'connection dead' notification */ |
274 |
+ kdbus_notify_reply_dead(bus, c->id, r->cookie); |
275 |
-+ kdbus_reply_unlink(r); |
276 |
-+ } |
277 |
++ |
278 |
++ kdbus_reply_unlink(r); |
279 |
+ } |
280 |
+ mutex_unlock(&c->lock); |
281 |
+ } |
282 |
@@ -9989,7 +9970,7 @@ index 0000000..ab476fa |
283 |
+ * |
284 |
+ * kdbus is reliable. That means, we try hard to never lose messages. However, |
285 |
+ * memory is limited, so we cannot rely on transmissions to never fail. |
286 |
-+ * Therefore, we use quota-limits to let callers know if there unicast message |
287 |
++ * Therefore, we use quota-limits to let callers know if their unicast message |
288 |
+ * cannot be transmitted to a peer. This works fine for unicasts, but for |
289 |
+ * broadcasts we cannot make the caller handle the transmission failure. |
290 |
+ * Instead, we must let the destination know that it couldn't receive a |
291 |
@@ -10011,8 +9992,6 @@ index 0000000..ab476fa |
292 |
+ const struct kdbus_kmsg *kmsg, |
293 |
+ struct kdbus_user *user) |
294 |
+{ |
295 |
-+ struct kdbus_queue_entry *entry; |
296 |
-+ |
297 |
+ /* The remote connection was disconnected */ |
298 |
+ if (!kdbus_conn_active(conn_dst)) |
299 |
+ return ERR_PTR(-ECONNRESET); |
300 |
@@ -10029,11 +10008,7 @@ index 0000000..ab476fa |
301 |
+ kmsg->res && kmsg->res->fds_count > 0) |
302 |
+ return ERR_PTR(-ECOMM); |
303 |
+ |
304 |
-+ entry = kdbus_queue_entry_new(conn_dst, kmsg, user); |
305 |
-+ if (IS_ERR(entry)) |
306 |
-+ return entry; |
307 |
-+ |
308 |
-+ return entry; |
309 |
++ return kdbus_queue_entry_new(conn_dst, kmsg, user); |
310 |
+} |
311 |
+ |
312 |
+/* |
313 |
@@ -10334,7 +10309,6 @@ index 0000000..ab476fa |
314 |
+ struct kdbus_reply *reply, *wake = NULL; |
315 |
+ struct kdbus_conn *dst = NULL; |
316 |
+ struct kdbus_bus *bus = src->ep->bus; |
317 |
-+ u64 attach; |
318 |
+ int ret; |
319 |
+ |
320 |
+ if (WARN_ON(kmsg->msg.dst_id == KDBUS_DST_ID_BROADCAST) || |
321 |
@@ -10367,15 +10341,7 @@ index 0000000..ab476fa |
322 |
+ |
323 |
+ /* attach metadata */ |
324 |
+ |
325 |
-+ attach = kdbus_meta_calc_attach_flags(src, dst); |
326 |
-+ |
327 |
-+ if (!src->faked_meta) { |
328 |
-+ ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach); |
329 |
-+ if (ret < 0) |
330 |
-+ goto exit; |
331 |
-+ } |
332 |
-+ |
333 |
-+ ret = kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach); |
334 |
++ ret = kdbus_kmsg_collect_metadata(kmsg, src, dst); |
335 |
+ if (ret < 0) |
336 |
+ goto exit; |
337 |
+ |
338 |
@@ -10403,7 +10369,6 @@ index 0000000..ab476fa |
339 |
+ struct kdbus_reply *wait = NULL; |
340 |
+ struct kdbus_conn *dst = NULL; |
341 |
+ struct kdbus_bus *bus = src->ep->bus; |
342 |
-+ u64 attach; |
343 |
+ int ret; |
344 |
+ |
345 |
+ if (WARN_ON(kmsg->msg.dst_id == KDBUS_DST_ID_BROADCAST) || |
346 |
@@ -10454,15 +10419,7 @@ index 0000000..ab476fa |
347 |
+ |
348 |
+ /* attach metadata */ |
349 |
+ |
350 |
-+ attach = kdbus_meta_calc_attach_flags(src, dst); |
351 |
-+ |
352 |
-+ if (!src->faked_meta) { |
353 |
-+ ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach); |
354 |
-+ if (ret < 0) |
355 |
-+ goto exit; |
356 |
-+ } |
357 |
-+ |
358 |
-+ ret = kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach); |
359 |
++ ret = kdbus_kmsg_collect_metadata(kmsg, src, dst); |
360 |
+ if (ret < 0) |
361 |
+ goto exit; |
362 |
+ |
363 |
@@ -10493,7 +10450,6 @@ index 0000000..ab476fa |
364 |
+ struct kdbus_conn *dst = NULL; |
365 |
+ struct kdbus_bus *bus = src->ep->bus; |
366 |
+ bool is_signal = (kmsg->msg.flags & KDBUS_MSG_SIGNAL); |
367 |
-+ u64 attach; |
368 |
+ int ret = 0; |
369 |
+ |
370 |
+ if (WARN_ON(kmsg->msg.dst_id == KDBUS_DST_ID_BROADCAST) || |
371 |
@@ -10532,16 +10488,8 @@ index 0000000..ab476fa |
372 |
+ |
373 |
+ /* attach metadata */ |
374 |
+ |
375 |
-+ attach = kdbus_meta_calc_attach_flags(src, dst); |
376 |
-+ |
377 |
-+ if (!src->faked_meta) { |
378 |
-+ ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach); |
379 |
-+ if (ret < 0 && !is_signal) |
380 |
-+ goto exit; |
381 |
-+ } |
382 |
-+ |
383 |
-+ ret = kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach); |
384 |
-+ if (ret < 0 && !is_signal) |
385 |
++ ret = kdbus_kmsg_collect_metadata(kmsg, src, dst); |
386 |
++ if (ret < 0) |
387 |
+ goto exit; |
388 |
+ |
389 |
+ /* send message */ |
390 |
@@ -10824,10 +10772,8 @@ index 0000000..ab476fa |
391 |
+ * to a peer if, and only if, that peer can see the name this |
392 |
+ * notification is for. |
393 |
+ * |
394 |
-+ * KDBUS_ITEM_ID_{ADD,REMOVE}: As new peers cannot have names, and all |
395 |
-+ * names are dropped before a peer is removed, those notifications |
396 |
-+ * cannot be seen on custom endpoints. Thus, we only pass them |
397 |
-+ * through on default endpoints. |
398 |
++ * KDBUS_ITEM_ID_{ADD,REMOVE}: Notifications for ID changes are |
399 |
++ * broadcast to everyone, to allow tracking peers. |
400 |
+ */ |
401 |
+ |
402 |
+ switch (kmsg->notify_type) { |
403 |
@@ -10839,7 +10785,7 @@ index 0000000..ab476fa |
404 |
+ |
405 |
+ case KDBUS_ITEM_ID_ADD: |
406 |
+ case KDBUS_ITEM_ID_REMOVE: |
407 |
-+ return !conn->ep->user; |
408 |
++ return true; |
409 |
+ |
410 |
+ default: |
411 |
+ WARN(1, "Invalid type for notification broadcast: %llu\n", |
412 |
@@ -10854,7 +10800,7 @@ index 0000000..ab476fa |
413 |
+ * @privileged: Whether the caller is privileged |
414 |
+ * @argp: Command payload |
415 |
+ * |
416 |
-+ * Return: Newly created connection on success, ERR_PTR on failure. |
417 |
++ * Return: NULL or newly created connection on success, ERR_PTR on failure. |
418 |
+ */ |
419 |
+struct kdbus_conn *kdbus_cmd_hello(struct kdbus_ep *ep, bool privileged, |
420 |
+ void __user *argp) |
421 |
@@ -10941,7 +10887,7 @@ index 0000000..ab476fa |
422 |
+ * |
423 |
+ * The caller must not hold any active reference to @conn or this will deadlock. |
424 |
+ * |
425 |
-+ * Return: 0 on success, negative error code on failure. |
426 |
++ * Return: >=0 on success, negative error code on failure. |
427 |
+ */ |
428 |
+int kdbus_cmd_byebye_unlocked(struct kdbus_conn *conn, void __user *argp) |
429 |
+{ |
430 |
@@ -10973,7 +10919,7 @@ index 0000000..ab476fa |
431 |
+ * @conn: connection to operate on |
432 |
+ * @argp: command payload |
433 |
+ * |
434 |
-+ * Return: 0 on success, negative error code on failure. |
435 |
++ * Return: >=0 on success, negative error code on failure. |
436 |
+ */ |
437 |
+int kdbus_cmd_conn_info(struct kdbus_conn *conn, void __user *argp) |
438 |
+{ |
439 |
@@ -11103,7 +11049,7 @@ index 0000000..ab476fa |
440 |
+ * @conn: connection to operate on |
441 |
+ * @argp: command payload |
442 |
+ * |
443 |
-+ * Return: 0 on success, negative error code on failure. |
444 |
++ * Return: >=0 on success, negative error code on failure. |
445 |
+ */ |
446 |
+int kdbus_cmd_update(struct kdbus_conn *conn, void __user *argp) |
447 |
+{ |
448 |
@@ -11200,7 +11146,7 @@ index 0000000..ab476fa |
449 |
+ * @f: file this command was called on |
450 |
+ * @argp: command payload |
451 |
+ * |
452 |
-+ * Return: 0 on success, negative error code on failure. |
453 |
++ * Return: >=0 on success, negative error code on failure. |
454 |
+ */ |
455 |
+int kdbus_cmd_send(struct kdbus_conn *conn, struct file *f, void __user *argp) |
456 |
+{ |
457 |
@@ -11296,7 +11242,7 @@ index 0000000..ab476fa |
458 |
+ * @conn: connection to operate on |
459 |
+ * @argp: command payload |
460 |
+ * |
461 |
-+ * Return: 0 on success, negative error code on failure. |
462 |
++ * Return: >=0 on success, negative error code on failure. |
463 |
+ */ |
464 |
+int kdbus_cmd_recv(struct kdbus_conn *conn, void __user *argp) |
465 |
+{ |
466 |
@@ -11419,7 +11365,7 @@ index 0000000..ab476fa |
467 |
+ * @conn: connection to operate on |
468 |
+ * @argp: command payload |
469 |
+ * |
470 |
-+ * Return: 0 on success, negative error code on failure. |
471 |
++ * Return: >=0 on success, negative error code on failure. |
472 |
+ */ |
473 |
+int kdbus_cmd_free(struct kdbus_conn *conn, void __user *argp) |
474 |
+{ |
475 |
@@ -12098,7 +12044,7 @@ index 0000000..447a2bd |
476 |
+#endif |
477 |
diff --git a/ipc/kdbus/endpoint.c b/ipc/kdbus/endpoint.c |
478 |
new file mode 100644 |
479 |
-index 0000000..174d274 |
480 |
+index 0000000..9a95a5e |
481 |
--- /dev/null |
482 |
+++ b/ipc/kdbus/endpoint.c |
483 |
@@ -0,0 +1,275 @@ |
484 |
@@ -12292,7 +12238,7 @@ index 0000000..174d274 |
485 |
+ * @bus: bus to operate on |
486 |
+ * @argp: command payload |
487 |
+ * |
488 |
-+ * Return: Newly created endpoint on success, ERR_PTR on failure. |
489 |
++ * Return: NULL or newly created endpoint on success, ERR_PTR on failure. |
490 |
+ */ |
491 |
+struct kdbus_ep *kdbus_cmd_ep_make(struct kdbus_bus *bus, void __user *argp) |
492 |
+{ |
493 |
@@ -12351,7 +12297,7 @@ index 0000000..174d274 |
494 |
+ * @ep: endpoint to operate on |
495 |
+ * @argp: command payload |
496 |
+ * |
497 |
-+ * Return: Newly created endpoint on success, ERR_PTR on failure. |
498 |
++ * Return: >=0 on success, negative error code on failure. |
499 |
+ */ |
500 |
+int kdbus_cmd_ep_update(struct kdbus_ep *ep, void __user *argp) |
501 |
+{ |
502 |
@@ -13002,10 +12948,10 @@ index 0000000..62f7d6a |
503 |
+#endif |
504 |
diff --git a/ipc/kdbus/handle.c b/ipc/kdbus/handle.c |
505 |
new file mode 100644 |
506 |
-index 0000000..f72dbe5 |
507 |
+index 0000000..0752799 |
508 |
--- /dev/null |
509 |
+++ b/ipc/kdbus/handle.c |
510 |
-@@ -0,0 +1,617 @@ |
511 |
+@@ -0,0 +1,702 @@ |
512 |
+/* |
513 |
+ * Copyright (C) 2013-2015 Kay Sievers |
514 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
515 |
@@ -13026,6 +12972,7 @@ index 0000000..f72dbe5 |
516 |
+#include <linux/init.h> |
517 |
+#include <linux/kdev_t.h> |
518 |
+#include <linux/module.h> |
519 |
++#include <linux/mutex.h> |
520 |
+#include <linux/poll.h> |
521 |
+#include <linux/rwsem.h> |
522 |
+#include <linux/sched.h> |
523 |
@@ -13079,10 +13026,6 @@ index 0000000..f72dbe5 |
524 |
+ if (!KDBUS_ITEMS_END(item, args->items, args->items_size)) |
525 |
+ return -EINVAL; |
526 |
+ |
527 |
-+ for (i = 0; i < args->argc; ++i) |
528 |
-+ if (args->argv[i].mandatory && !args->argv[i].item) |
529 |
-+ return -EINVAL; |
530 |
-+ |
531 |
+ return 0; |
532 |
+} |
533 |
+ |
534 |
@@ -13157,11 +13100,32 @@ index 0000000..f72dbe5 |
535 |
+int __kdbus_args_parse(struct kdbus_args *args, void __user *argp, |
536 |
+ size_t type_size, size_t items_offset, void **out) |
537 |
+{ |
538 |
-+ int ret; |
539 |
++ u64 user_size; |
540 |
++ int ret, i; |
541 |
++ |
542 |
++ ret = kdbus_copy_from_user(&user_size, argp, sizeof(user_size)); |
543 |
++ if (ret < 0) |
544 |
++ return ret; |
545 |
++ |
546 |
++ if (user_size < type_size) |
547 |
++ return -EINVAL; |
548 |
++ if (user_size > KDBUS_CMD_MAX_SIZE) |
549 |
++ return -EMSGSIZE; |
550 |
++ |
551 |
++ if (user_size <= sizeof(args->cmd_buf)) { |
552 |
++ if (copy_from_user(args->cmd_buf, argp, user_size)) |
553 |
++ return -EFAULT; |
554 |
++ args->cmd = (void*)args->cmd_buf; |
555 |
++ } else { |
556 |
++ args->cmd = memdup_user(argp, user_size); |
557 |
++ if (IS_ERR(args->cmd)) |
558 |
++ return PTR_ERR(args->cmd); |
559 |
++ } |
560 |
+ |
561 |
-+ args->cmd = kdbus_memdup_user(argp, type_size, KDBUS_CMD_MAX_SIZE); |
562 |
-+ if (IS_ERR(args->cmd)) |
563 |
-+ return PTR_ERR(args->cmd); |
564 |
++ if (args->cmd->size != user_size) { |
565 |
++ ret = -EINVAL; |
566 |
++ goto error; |
567 |
++ } |
568 |
+ |
569 |
+ args->cmd->return_flags = 0; |
570 |
+ args->user = argp; |
571 |
@@ -13181,6 +13145,15 @@ index 0000000..f72dbe5 |
572 |
+ if (ret < 0) |
573 |
+ goto error; |
574 |
+ |
575 |
++ /* mandatory items must be given (but not on negotiation) */ |
576 |
++ if (!(args->cmd->flags & KDBUS_FLAG_NEGOTIATE)) { |
577 |
++ for (i = 0; i < args->argc; ++i) |
578 |
++ if (args->argv[i].mandatory && !args->argv[i].item) { |
579 |
++ ret = -EINVAL; |
580 |
++ goto error; |
581 |
++ } |
582 |
++ } |
583 |
++ |
584 |
+ *out = args->cmd; |
585 |
+ return !!(args->cmd->flags & KDBUS_FLAG_NEGOTIATE); |
586 |
+ |
587 |
@@ -13209,7 +13182,8 @@ index 0000000..f72dbe5 |
588 |
+ if (put_user(args->cmd->return_flags, |
589 |
+ &args->user->return_flags)) |
590 |
+ ret = -EFAULT; |
591 |
-+ kfree(args->cmd); |
592 |
++ if (args->cmd != (void*)args->cmd_buf) |
593 |
++ kfree(args->cmd); |
594 |
+ args->cmd = NULL; |
595 |
+ } |
596 |
+ |
597 |
@@ -13232,7 +13206,7 @@ index 0000000..f72dbe5 |
598 |
+ |
599 |
+/** |
600 |
+ * struct kdbus_handle - handle to the kdbus system |
601 |
-+ * @rwlock: handle lock |
602 |
++ * @lock: handle lock |
603 |
+ * @type: type of this handle (KDBUS_HANDLE_*) |
604 |
+ * @bus_owner: bus this handle owns |
605 |
+ * @ep_owner: endpoint this handle owns |
606 |
@@ -13240,7 +13214,7 @@ index 0000000..f72dbe5 |
607 |
+ * @privileged: Flag to mark a handle as privileged |
608 |
+ */ |
609 |
+struct kdbus_handle { |
610 |
-+ struct rw_semaphore rwlock; |
611 |
++ struct mutex lock; |
612 |
+ |
613 |
+ enum kdbus_handle_type type; |
614 |
+ union { |
615 |
@@ -13268,7 +13242,7 @@ index 0000000..f72dbe5 |
616 |
+ goto exit; |
617 |
+ } |
618 |
+ |
619 |
-+ init_rwsem(&handle->rwlock); |
620 |
++ mutex_init(&handle->lock); |
621 |
+ handle->type = KDBUS_HANDLE_NONE; |
622 |
+ |
623 |
+ if (node->type == KDBUS_NODE_ENDPOINT) { |
624 |
@@ -13358,8 +13332,8 @@ index 0000000..f72dbe5 |
625 |
+ break; |
626 |
+ } |
627 |
+ |
628 |
-+ handle->type = KDBUS_HANDLE_BUS_OWNER; |
629 |
+ handle->bus_owner = bus; |
630 |
++ ret = KDBUS_HANDLE_BUS_OWNER; |
631 |
+ break; |
632 |
+ } |
633 |
+ |
634 |
@@ -13399,8 +13373,8 @@ index 0000000..f72dbe5 |
635 |
+ break; |
636 |
+ } |
637 |
+ |
638 |
-+ handle->type = KDBUS_HANDLE_EP_OWNER; |
639 |
+ handle->ep_owner = ep; |
640 |
++ ret = KDBUS_HANDLE_EP_OWNER; |
641 |
+ break; |
642 |
+ |
643 |
+ case KDBUS_CMD_HELLO: |
644 |
@@ -13410,8 +13384,8 @@ index 0000000..f72dbe5 |
645 |
+ break; |
646 |
+ } |
647 |
+ |
648 |
-+ handle->type = KDBUS_HANDLE_CONNECTED; |
649 |
+ handle->conn = conn; |
650 |
++ ret = KDBUS_HANDLE_CONNECTED; |
651 |
+ break; |
652 |
+ |
653 |
+ default: |
654 |
@@ -13525,19 +13499,41 @@ index 0000000..f72dbe5 |
655 |
+ case KDBUS_CMD_BUS_MAKE: |
656 |
+ case KDBUS_CMD_ENDPOINT_MAKE: |
657 |
+ case KDBUS_CMD_HELLO: |
658 |
-+ /* bail out early if already typed */ |
659 |
-+ if (handle->type != KDBUS_HANDLE_NONE) |
660 |
-+ break; |
661 |
-+ |
662 |
-+ down_write(&handle->rwlock); |
663 |
++ mutex_lock(&handle->lock); |
664 |
+ if (handle->type == KDBUS_HANDLE_NONE) { |
665 |
+ if (node->type == KDBUS_NODE_CONTROL) |
666 |
+ ret = kdbus_handle_ioctl_control(file, cmd, |
667 |
+ argp); |
668 |
+ else if (node->type == KDBUS_NODE_ENDPOINT) |
669 |
+ ret = kdbus_handle_ioctl_ep(file, cmd, argp); |
670 |
++ |
671 |
++ if (ret > 0) { |
672 |
++ /* |
673 |
++ * The data given via open() is not sufficient |
674 |
++ * to setup a kdbus handle. Hence, we require |
675 |
++ * the user to perform a setup ioctl. This setup |
676 |
++ * can only be performed once and defines the |
677 |
++ * type of the handle. The different setup |
678 |
++ * ioctls are locked against each other so they |
679 |
++ * cannot race. Once the handle type is set, |
680 |
++ * the type-dependent ioctls are enabled. To |
681 |
++ * improve performance, we don't lock those via |
682 |
++ * handle->lock. Instead, we issue a |
683 |
++ * write-barrier before performing the |
684 |
++ * type-change, which pairs with smp_rmb() in |
685 |
++ * all handlers that access the type field. This |
686 |
++ * guarantees the handle is fully setup, if |
687 |
++ * handle->type is set. If handle->type is |
688 |
++ * unset, you must not make any assumptions |
689 |
++ * without taking handle->lock. |
690 |
++ * Note that handle->type is only set once. It |
691 |
++ * will never change afterwards. |
692 |
++ */ |
693 |
++ smp_wmb(); |
694 |
++ handle->type = ret; |
695 |
++ } |
696 |
+ } |
697 |
-+ up_write(&handle->rwlock); |
698 |
++ mutex_unlock(&handle->lock); |
699 |
+ break; |
700 |
+ |
701 |
+ case KDBUS_CMD_ENDPOINT_UPDATE: |
702 |
@@ -13552,14 +13548,30 @@ index 0000000..f72dbe5 |
703 |
+ case KDBUS_CMD_MATCH_REMOVE: |
704 |
+ case KDBUS_CMD_SEND: |
705 |
+ case KDBUS_CMD_RECV: |
706 |
-+ case KDBUS_CMD_FREE: |
707 |
-+ down_read(&handle->rwlock); |
708 |
-+ if (handle->type == KDBUS_HANDLE_EP_OWNER) |
709 |
++ case KDBUS_CMD_FREE: { |
710 |
++ enum kdbus_handle_type type; |
711 |
++ |
712 |
++ /* |
713 |
++ * This read-barrier pairs with smp_wmb() of the handle setup. |
714 |
++ * it guarantees the handle is fully written, in case the |
715 |
++ * type has been set. It allows us to access the handle without |
716 |
++ * taking handle->lock, given the guarantee that the type is |
717 |
++ * only ever set once, and stays constant afterwards. |
718 |
++ * Furthermore, the handle object itself is not modified in any |
719 |
++ * way after the type is set. That is, the type-field is the |
720 |
++ * last field that is written on any handle. If it has not been |
721 |
++ * set, we must not access the handle here. |
722 |
++ */ |
723 |
++ type = handle->type; |
724 |
++ smp_rmb(); |
725 |
++ |
726 |
++ if (type == KDBUS_HANDLE_EP_OWNER) |
727 |
+ ret = kdbus_handle_ioctl_ep_owner(file, cmd, argp); |
728 |
-+ else if (handle->type == KDBUS_HANDLE_CONNECTED) |
729 |
++ else if (type == KDBUS_HANDLE_CONNECTED) |
730 |
+ ret = kdbus_handle_ioctl_connected(file, cmd, argp); |
731 |
-+ up_read(&handle->rwlock); |
732 |
++ |
733 |
+ break; |
734 |
++ } |
735 |
+ default: |
736 |
+ ret = -ENOTTY; |
737 |
+ break; |
738 |
@@ -13572,42 +13584,61 @@ index 0000000..f72dbe5 |
739 |
+ struct poll_table_struct *wait) |
740 |
+{ |
741 |
+ struct kdbus_handle *handle = file->private_data; |
742 |
++ enum kdbus_handle_type type; |
743 |
+ unsigned int mask = POLLOUT | POLLWRNORM; |
744 |
-+ int ret; |
745 |
+ |
746 |
-+ /* Only a connected endpoint can read/write data */ |
747 |
-+ down_read(&handle->rwlock); |
748 |
-+ if (handle->type != KDBUS_HANDLE_CONNECTED) { |
749 |
-+ up_read(&handle->rwlock); |
750 |
-+ return POLLERR | POLLHUP; |
751 |
-+ } |
752 |
-+ up_read(&handle->rwlock); |
753 |
++ /* |
754 |
++ * This pairs with smp_wmb() during handle setup. It guarantees that |
755 |
++ * _iff_ the handle type is set, handle->conn is valid. Furthermore, |
756 |
++ * _iff_ the type is set, the handle object is constant and never |
757 |
++ * changed again. If it's not set, we must not access the handle but |
758 |
++ * bail out. We also must assume no setup has taken place, yet. |
759 |
++ */ |
760 |
++ type = handle->type; |
761 |
++ smp_rmb(); |
762 |
+ |
763 |
-+ ret = kdbus_conn_acquire(handle->conn); |
764 |
-+ if (ret < 0) |
765 |
++ /* Only a connected endpoint can read/write data */ |
766 |
++ if (type != KDBUS_HANDLE_CONNECTED) |
767 |
+ return POLLERR | POLLHUP; |
768 |
+ |
769 |
+ poll_wait(file, &handle->conn->wait, wait); |
770 |
+ |
771 |
++ /* |
772 |
++ * Verify the connection hasn't been deactivated _after_ adding the |
773 |
++ * wait-queue. This guarantees, that if the connection is deactivated |
774 |
++ * after we checked it, the waitqueue is signaled and we're called |
775 |
++ * again. |
776 |
++ */ |
777 |
++ if (!kdbus_conn_active(handle->conn)) |
778 |
++ return POLLERR | POLLHUP; |
779 |
++ |
780 |
+ if (!list_empty(&handle->conn->queue.msg_list) || |
781 |
+ atomic_read(&handle->conn->lost_count) > 0) |
782 |
+ mask |= POLLIN | POLLRDNORM; |
783 |
+ |
784 |
-+ kdbus_conn_release(handle->conn); |
785 |
-+ |
786 |
+ return mask; |
787 |
+} |
788 |
+ |
789 |
+static int kdbus_handle_mmap(struct file *file, struct vm_area_struct *vma) |
790 |
+{ |
791 |
+ struct kdbus_handle *handle = file->private_data; |
792 |
++ enum kdbus_handle_type type; |
793 |
+ int ret = -EBADFD; |
794 |
+ |
795 |
-+ if (down_read_trylock(&handle->rwlock)) { |
796 |
-+ if (handle->type == KDBUS_HANDLE_CONNECTED) |
797 |
-+ ret = kdbus_pool_mmap(handle->conn->pool, vma); |
798 |
-+ up_read(&handle->rwlock); |
799 |
-+ } |
800 |
++ /* |
801 |
++ * This pairs with smp_wmb() during handle setup. It guarantees that |
802 |
++ * _iff_ the handle type is set, handle->conn is valid. Furthermore, |
803 |
++ * _iff_ the type is set, the handle object is constant and never |
804 |
++ * changed again. If it's not set, we must not access the handle but |
805 |
++ * bail out. We also must assume no setup has taken place, yet. |
806 |
++ */ |
807 |
++ type = handle->type; |
808 |
++ smp_rmb(); |
809 |
++ |
810 |
++ /* Only connected handles have a pool we can map */ |
811 |
++ if (type == KDBUS_HANDLE_CONNECTED) |
812 |
++ ret = kdbus_pool_mmap(handle->conn->pool, vma); |
813 |
++ |
814 |
+ return ret; |
815 |
+} |
816 |
+ |
817 |
@@ -13625,10 +13656,10 @@ index 0000000..f72dbe5 |
818 |
+}; |
819 |
diff --git a/ipc/kdbus/handle.h b/ipc/kdbus/handle.h |
820 |
new file mode 100644 |
821 |
-index 0000000..93a372d |
822 |
+index 0000000..13c59d9 |
823 |
--- /dev/null |
824 |
+++ b/ipc/kdbus/handle.h |
825 |
-@@ -0,0 +1,85 @@ |
826 |
+@@ -0,0 +1,90 @@ |
827 |
+/* |
828 |
+ * Copyright (C) 2013-2015 Kay Sievers |
829 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
830 |
@@ -13676,6 +13707,7 @@ index 0000000..93a372d |
831 |
+ * @argv: array of items this command supports |
832 |
+ * @user: set by parser to user-space location of current command |
833 |
+ * @cmd: set by parser to kernel copy of command payload |
834 |
++ * @cmd_buf: 512 bytes inline buf to avoid kmalloc() on small cmds |
835 |
+ * @items: points to item array in @cmd |
836 |
+ * @items_size: size of @items in bytes |
837 |
+ * |
838 |
@@ -13683,6 +13715,9 @@ index 0000000..93a372d |
839 |
+ * The ioctl handler has to pre-fill the flags and allowed items before passing |
840 |
+ * the object to kdbus_args_parse(). The parser will copy the command payload |
841 |
+ * into kernel-space and verify the correctness of the data. |
842 |
++ * |
843 |
++ * We use a 512 bytes buffer for small command payloads, to be allocated on |
844 |
++ * stack on syscall entrance. |
845 |
+ */ |
846 |
+struct kdbus_args { |
847 |
+ u64 allowed_flags; |
848 |
@@ -13691,6 +13726,7 @@ index 0000000..93a372d |
849 |
+ |
850 |
+ struct kdbus_cmd __user *user; |
851 |
+ struct kdbus_cmd *cmd; |
852 |
++ u8 cmd_buf[512]; |
853 |
+ |
854 |
+ struct kdbus_item *items; |
855 |
+ size_t items_size; |
856 |
@@ -13716,10 +13752,10 @@ index 0000000..93a372d |
857 |
+#endif |
858 |
diff --git a/ipc/kdbus/item.c b/ipc/kdbus/item.c |
859 |
new file mode 100644 |
860 |
-index 0000000..745ad54 |
861 |
+index 0000000..1ee72c2 |
862 |
--- /dev/null |
863 |
+++ b/ipc/kdbus/item.c |
864 |
-@@ -0,0 +1,339 @@ |
865 |
+@@ -0,0 +1,333 @@ |
866 |
+/* |
867 |
+ * Copyright (C) 2013-2015 Kay Sievers |
868 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
869 |
@@ -13818,12 +13854,6 @@ index 0000000..745ad54 |
870 |
+ break; |
871 |
+ |
872 |
+ case KDBUS_ITEM_PAYLOAD_VEC: |
873 |
-+ if (payload_size != sizeof(struct kdbus_vec)) |
874 |
-+ return -EINVAL; |
875 |
-+ if (item->vec.size == 0 || item->vec.size > SIZE_MAX) |
876 |
-+ return -EINVAL; |
877 |
-+ break; |
878 |
-+ |
879 |
+ case KDBUS_ITEM_PAYLOAD_OFF: |
880 |
+ if (payload_size != sizeof(struct kdbus_vec)) |
881 |
+ return -EINVAL; |
882 |
@@ -14061,7 +14091,7 @@ index 0000000..745ad54 |
883 |
+} |
884 |
diff --git a/ipc/kdbus/item.h b/ipc/kdbus/item.h |
885 |
new file mode 100644 |
886 |
-index 0000000..eeefd8b |
887 |
+index 0000000..bca63b4 |
888 |
--- /dev/null |
889 |
+++ b/ipc/kdbus/item.h |
890 |
@@ -0,0 +1,64 @@ |
891 |
@@ -14088,17 +14118,17 @@ index 0000000..eeefd8b |
892 |
+#include "util.h" |
893 |
+ |
894 |
+/* generic access and iterators over a stream of items */ |
895 |
-+#define KDBUS_ITEM_NEXT(_i) (typeof(_i))(((u8 *)_i) + KDBUS_ALIGN8((_i)->size)) |
896 |
-+#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*_h), _is)) |
897 |
++#define KDBUS_ITEM_NEXT(_i) (typeof(_i))((u8 *)(_i) + KDBUS_ALIGN8((_i)->size)) |
898 |
++#define KDBUS_ITEMS_SIZE(_h, _is) ((_h)->size - offsetof(typeof(*(_h)), _is)) |
899 |
+#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data) |
900 |
+#define KDBUS_ITEM_SIZE(_s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (_s)) |
901 |
+#define KDBUS_ITEM_PAYLOAD_SIZE(_i) ((_i)->size - KDBUS_ITEM_HEADER_SIZE) |
902 |
+ |
903 |
+#define KDBUS_ITEMS_FOREACH(_i, _is, _s) \ |
904 |
-+ for (_i = _is; \ |
905 |
++ for ((_i) = (_is); \ |
906 |
+ ((u8 *)(_i) < (u8 *)(_is) + (_s)) && \ |
907 |
+ ((u8 *)(_i) >= (u8 *)(_is)); \ |
908 |
-+ _i = KDBUS_ITEM_NEXT(_i)) |
909 |
++ (_i) = KDBUS_ITEM_NEXT(_i)) |
910 |
+ |
911 |
+#define KDBUS_ITEM_VALID(_i, _is, _s) \ |
912 |
+ ((_i)->size >= KDBUS_ITEM_HEADER_SIZE && \ |
913 |
@@ -14107,7 +14137,7 @@ index 0000000..eeefd8b |
914 |
+ (u8 *)(_i) >= (u8 *)(_is)) |
915 |
+ |
916 |
+#define KDBUS_ITEMS_END(_i, _is, _s) \ |
917 |
-+ ((u8 *)_i == ((u8 *)(_is) + KDBUS_ALIGN8(_s))) |
918 |
++ ((u8 *)(_i) == ((u8 *)(_is) + KDBUS_ALIGN8(_s))) |
919 |
+ |
920 |
+/** |
921 |
+ * struct kdbus_item_header - Describes the fix part of an item |
922 |
@@ -14201,10 +14231,10 @@ index 0000000..6450f58 |
923 |
+#endif |
924 |
diff --git a/ipc/kdbus/main.c b/ipc/kdbus/main.c |
925 |
new file mode 100644 |
926 |
-index 0000000..785f529 |
927 |
+index 0000000..1ad4dc8 |
928 |
--- /dev/null |
929 |
+++ b/ipc/kdbus/main.c |
930 |
-@@ -0,0 +1,125 @@ |
931 |
+@@ -0,0 +1,114 @@ |
932 |
+/* |
933 |
+ * Copyright (C) 2013-2015 Kay Sievers |
934 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
935 |
@@ -14222,7 +14252,6 @@ index 0000000..785f529 |
936 |
+#include <linux/fs.h> |
937 |
+#include <linux/init.h> |
938 |
+#include <linux/module.h> |
939 |
-+#include <linux/moduleparam.h> |
940 |
+ |
941 |
+#include "util.h" |
942 |
+#include "fs.h" |
943 |
@@ -14286,17 +14315,6 @@ index 0000000..785f529 |
944 |
+/* kdbus mount-point /sys/fs/kdbus */ |
945 |
+static struct kobject *kdbus_dir; |
946 |
+ |
947 |
-+/* global module option to apply a mask to exported metadata */ |
948 |
-+unsigned long long kdbus_meta_attach_mask = KDBUS_ATTACH_TIMESTAMP | |
949 |
-+ KDBUS_ATTACH_CREDS | |
950 |
-+ KDBUS_ATTACH_PIDS | |
951 |
-+ KDBUS_ATTACH_AUXGROUPS | |
952 |
-+ KDBUS_ATTACH_NAMES | |
953 |
-+ KDBUS_ATTACH_SECLABEL | |
954 |
-+ KDBUS_ATTACH_CONN_DESCRIPTION; |
955 |
-+MODULE_PARM_DESC(attach_flags_mask, "Attach-flags mask for exported metadata"); |
956 |
-+module_param_named(attach_flags_mask, kdbus_meta_attach_mask, ullong, 0644); |
957 |
-+ |
958 |
+static int __init kdbus_init(void) |
959 |
+{ |
960 |
+ int ret; |
961 |
@@ -14323,6 +14341,7 @@ index 0000000..785f529 |
962 |
+{ |
963 |
+ kdbus_fs_exit(); |
964 |
+ kobject_put(kdbus_dir); |
965 |
++ ida_destroy(&kdbus_node_ida); |
966 |
+} |
967 |
+ |
968 |
+module_init(kdbus_init); |
969 |
@@ -14332,7 +14351,7 @@ index 0000000..785f529 |
970 |
+MODULE_ALIAS_FS(KBUILD_MODNAME "fs"); |
971 |
diff --git a/ipc/kdbus/match.c b/ipc/kdbus/match.c |
972 |
new file mode 100644 |
973 |
-index 0000000..30cec1c |
974 |
+index 0000000..cc083b4 |
975 |
--- /dev/null |
976 |
+++ b/ipc/kdbus/match.c |
977 |
@@ -0,0 +1,559 @@ |
978 |
@@ -14706,7 +14725,7 @@ index 0000000..30cec1c |
979 |
+ * are used to match messages from userspace, while the others apply to |
980 |
+ * kernel-generated notifications. |
981 |
+ * |
982 |
-+ * Return: 0 on success, negative error code on failure. |
983 |
++ * Return: >=0 on success, negative error code on failure. |
984 |
+ */ |
985 |
+int kdbus_cmd_match_add(struct kdbus_conn *conn, void __user *argp) |
986 |
+{ |
987 |
@@ -14866,7 +14885,7 @@ index 0000000..30cec1c |
988 |
+ * @conn: connection to operate on |
989 |
+ * @argp: command payload |
990 |
+ * |
991 |
-+ * Return: 0 on success, negative error code on failure. |
992 |
++ * Return: >=0 on success, negative error code on failure. |
993 |
+ */ |
994 |
+int kdbus_cmd_match_remove(struct kdbus_conn *conn, void __user *argp) |
995 |
+{ |
996 |
@@ -14938,10 +14957,10 @@ index 0000000..ea42929 |
997 |
+#endif |
998 |
diff --git a/ipc/kdbus/message.c b/ipc/kdbus/message.c |
999 |
new file mode 100644 |
1000 |
-index 0000000..8096075 |
1001 |
+index 0000000..066e816 |
1002 |
--- /dev/null |
1003 |
+++ b/ipc/kdbus/message.c |
1004 |
-@@ -0,0 +1,616 @@ |
1005 |
+@@ -0,0 +1,640 @@ |
1006 |
+/* |
1007 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1008 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1009 |
@@ -15558,12 +15577,36 @@ index 0000000..8096075 |
1010 |
+ kdbus_kmsg_free(m); |
1011 |
+ return ERR_PTR(ret); |
1012 |
+} |
1013 |
++ |
1014 |
++/** |
1015 |
++ * kdbus_kmsg_collect_metadata() - collect metadata |
1016 |
++ * @kmsg: message to collect metadata on |
1017 |
++ * @src: source connection of message |
1018 |
++ * @dst: destination connection of message |
1019 |
++ * |
1020 |
++ * Return: 0 on success, negative error code on failure. |
1021 |
++ */ |
1022 |
++int kdbus_kmsg_collect_metadata(struct kdbus_kmsg *kmsg, struct kdbus_conn *src, |
1023 |
++ struct kdbus_conn *dst) |
1024 |
++{ |
1025 |
++ u64 attach; |
1026 |
++ int ret; |
1027 |
++ |
1028 |
++ attach = kdbus_meta_calc_attach_flags(src, dst); |
1029 |
++ if (!src->faked_meta) { |
1030 |
++ ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach); |
1031 |
++ if (ret < 0) |
1032 |
++ return ret; |
1033 |
++ } |
1034 |
++ |
1035 |
++ return kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach); |
1036 |
++} |
1037 |
diff --git a/ipc/kdbus/message.h b/ipc/kdbus/message.h |
1038 |
new file mode 100644 |
1039 |
-index 0000000..af47758 |
1040 |
+index 0000000..cdaa65c |
1041 |
--- /dev/null |
1042 |
+++ b/ipc/kdbus/message.h |
1043 |
-@@ -0,0 +1,133 @@ |
1044 |
+@@ -0,0 +1,135 @@ |
1045 |
+/* |
1046 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1047 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1048 |
@@ -15695,14 +15738,16 @@ index 0000000..af47758 |
1049 |
+struct kdbus_kmsg *kdbus_kmsg_new_from_cmd(struct kdbus_conn *conn, |
1050 |
+ struct kdbus_cmd_send *cmd_send); |
1051 |
+void kdbus_kmsg_free(struct kdbus_kmsg *kmsg); |
1052 |
++int kdbus_kmsg_collect_metadata(struct kdbus_kmsg *kmsg, struct kdbus_conn *src, |
1053 |
++ struct kdbus_conn *dst); |
1054 |
+ |
1055 |
+#endif |
1056 |
diff --git a/ipc/kdbus/metadata.c b/ipc/kdbus/metadata.c |
1057 |
new file mode 100644 |
1058 |
-index 0000000..3adc6c2 |
1059 |
+index 0000000..c36b9cc |
1060 |
--- /dev/null |
1061 |
+++ b/ipc/kdbus/metadata.c |
1062 |
-@@ -0,0 +1,1159 @@ |
1063 |
+@@ -0,0 +1,1184 @@ |
1064 |
+/* |
1065 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1066 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1067 |
@@ -15734,7 +15779,6 @@ index 0000000..3adc6c2 |
1068 |
+#include <linux/uidgid.h> |
1069 |
+#include <linux/uio.h> |
1070 |
+#include <linux/user_namespace.h> |
1071 |
-+#include <linux/version.h> |
1072 |
+ |
1073 |
+#include "bus.h" |
1074 |
+#include "connection.h" |
1075 |
@@ -15769,8 +15813,7 @@ index 0000000..3adc6c2 |
1076 |
+ * @root_path: Root-FS path |
1077 |
+ * @cmdline: Command-line |
1078 |
+ * @cgroup: Full cgroup path |
1079 |
-+ * @caps: Capabilities |
1080 |
-+ * @caps_namespace: User-namespace of @caps |
1081 |
++ * @cred: Credentials |
1082 |
+ * @seclabel: Seclabel |
1083 |
+ * @audit_loginuid: Audit login-UID |
1084 |
+ * @audit_sessionid: Audit session-ID |
1085 |
@@ -15810,14 +15853,7 @@ index 0000000..3adc6c2 |
1086 |
+ char *cgroup; |
1087 |
+ |
1088 |
+ /* KDBUS_ITEM_CAPS */ |
1089 |
-+ struct caps { |
1090 |
-+ /* binary compatible to kdbus_caps */ |
1091 |
-+ u32 last_cap; |
1092 |
-+ struct { |
1093 |
-+ u32 caps[_KERNEL_CAPABILITY_U32S]; |
1094 |
-+ } set[4]; |
1095 |
-+ } caps; |
1096 |
-+ struct user_namespace *caps_namespace; |
1097 |
++ const struct cred *cred; |
1098 |
+ |
1099 |
+ /* KDBUS_ITEM_SECLABEL */ |
1100 |
+ char *seclabel; |
1101 |
@@ -15855,6 +15891,14 @@ index 0000000..3adc6c2 |
1102 |
+ char *conn_description; |
1103 |
+}; |
1104 |
+ |
1105 |
++/* fixed size equivalent of "kdbus_caps" */ |
1106 |
++struct kdbus_meta_caps { |
1107 |
++ u32 last_cap; |
1108 |
++ struct { |
1109 |
++ u32 caps[_KERNEL_CAPABILITY_U32S]; |
1110 |
++ } set[4]; |
1111 |
++}; |
1112 |
++ |
1113 |
+/** |
1114 |
+ * kdbus_meta_proc_new() - Create process metadata object |
1115 |
+ * |
1116 |
@@ -15881,7 +15925,8 @@ index 0000000..3adc6c2 |
1117 |
+ |
1118 |
+ path_put(&mp->exe_path); |
1119 |
+ path_put(&mp->root_path); |
1120 |
-+ put_user_ns(mp->caps_namespace); |
1121 |
++ if (mp->cred) |
1122 |
++ put_cred(mp->cred); |
1123 |
+ put_pid(mp->ppid); |
1124 |
+ put_pid(mp->tgid); |
1125 |
+ put_pid(mp->pid); |
1126 |
@@ -15951,25 +15996,23 @@ index 0000000..3adc6c2 |
1127 |
+ |
1128 |
+static int kdbus_meta_proc_collect_auxgroups(struct kdbus_meta_proc *mp) |
1129 |
+{ |
1130 |
-+ struct group_info *info; |
1131 |
++ const struct group_info *info; |
1132 |
+ size_t i; |
1133 |
+ |
1134 |
-+ info = get_current_groups(); |
1135 |
++ /* no need to lock/ref, current creds cannot change */ |
1136 |
++ info = current_cred()->group_info; |
1137 |
+ |
1138 |
+ if (info->ngroups > 0) { |
1139 |
+ mp->auxgrps = kmalloc_array(info->ngroups, sizeof(kgid_t), |
1140 |
+ GFP_KERNEL); |
1141 |
-+ if (!mp->auxgrps) { |
1142 |
-+ put_group_info(info); |
1143 |
++ if (!mp->auxgrps) |
1144 |
+ return -ENOMEM; |
1145 |
-+ } |
1146 |
+ |
1147 |
+ for (i = 0; i < info->ngroups; i++) |
1148 |
+ mp->auxgrps[i] = GROUP_AT(info, i); |
1149 |
+ } |
1150 |
+ |
1151 |
+ mp->n_auxgrps = info->ngroups; |
1152 |
-+ put_group_info(info); |
1153 |
+ mp->valid |= KDBUS_ATTACH_AUXGROUPS; |
1154 |
+ |
1155 |
+ return 0; |
1156 |
@@ -15989,42 +16032,29 @@ index 0000000..3adc6c2 |
1157 |
+ |
1158 |
+static void kdbus_meta_proc_collect_exe(struct kdbus_meta_proc *mp) |
1159 |
+{ |
1160 |
-+ struct mm_struct *mm; |
1161 |
++ struct file *exe_file; |
1162 |
+ |
1163 |
-+ mm = get_task_mm(current); |
1164 |
-+ if (!mm) |
1165 |
-+ return; |
1166 |
-+ |
1167 |
-+ down_read(&mm->mmap_sem); |
1168 |
-+ if (mm->exe_file) { |
1169 |
-+ mp->exe_path = mm->exe_file->f_path; |
1170 |
++ rcu_read_lock(); |
1171 |
++ exe_file = rcu_dereference(current->mm->exe_file); |
1172 |
++ if (exe_file) { |
1173 |
++ mp->exe_path = exe_file->f_path; |
1174 |
+ path_get(&mp->exe_path); |
1175 |
+ get_fs_root(current->fs, &mp->root_path); |
1176 |
+ mp->valid |= KDBUS_ATTACH_EXE; |
1177 |
+ } |
1178 |
-+ up_read(&mm->mmap_sem); |
1179 |
-+ |
1180 |
-+ mmput(mm); |
1181 |
++ rcu_read_unlock(); |
1182 |
+} |
1183 |
+ |
1184 |
+static int kdbus_meta_proc_collect_cmdline(struct kdbus_meta_proc *mp) |
1185 |
+{ |
1186 |
-+ struct mm_struct *mm; |
1187 |
++ struct mm_struct *mm = current->mm; |
1188 |
+ char *cmdline; |
1189 |
+ |
1190 |
-+ mm = get_task_mm(current); |
1191 |
-+ if (!mm) |
1192 |
-+ return 0; |
1193 |
-+ |
1194 |
-+ if (!mm->arg_end) { |
1195 |
-+ mmput(mm); |
1196 |
++ if (!mm->arg_end) |
1197 |
+ return 0; |
1198 |
-+ } |
1199 |
+ |
1200 |
+ cmdline = strndup_user((const char __user *)mm->arg_start, |
1201 |
+ mm->arg_end - mm->arg_start); |
1202 |
-+ mmput(mm); |
1203 |
-+ |
1204 |
+ if (IS_ERR(cmdline)) |
1205 |
+ return PTR_ERR(cmdline); |
1206 |
+ |
1207 |
@@ -16062,25 +16092,7 @@ index 0000000..3adc6c2 |
1208 |
+ |
1209 |
+static void kdbus_meta_proc_collect_caps(struct kdbus_meta_proc *mp) |
1210 |
+{ |
1211 |
-+ const struct cred *c = current_cred(); |
1212 |
-+ int i; |
1213 |
-+ |
1214 |
-+ /* ABI: "last_cap" equals /proc/sys/kernel/cap_last_cap */ |
1215 |
-+ mp->caps.last_cap = CAP_LAST_CAP; |
1216 |
-+ mp->caps_namespace = get_user_ns(current_user_ns()); |
1217 |
-+ |
1218 |
-+ CAP_FOR_EACH_U32(i) { |
1219 |
-+ mp->caps.set[0].caps[i] = c->cap_inheritable.cap[i]; |
1220 |
-+ mp->caps.set[1].caps[i] = c->cap_permitted.cap[i]; |
1221 |
-+ mp->caps.set[2].caps[i] = c->cap_effective.cap[i]; |
1222 |
-+ mp->caps.set[3].caps[i] = c->cap_bset.cap[i]; |
1223 |
-+ } |
1224 |
-+ |
1225 |
-+ /* clear unused bits */ |
1226 |
-+ for (i = 0; i < 4; i++) |
1227 |
-+ mp->caps.set[i].caps[CAP_TO_INDEX(CAP_LAST_CAP)] &= |
1228 |
-+ CAP_LAST_U32_VALID_MASK; |
1229 |
-+ |
1230 |
++ mp->cred = get_current_cred(); |
1231 |
+ mp->valid |= KDBUS_ATTACH_CAPS; |
1232 |
+} |
1233 |
+ |
1234 |
@@ -16543,7 +16555,6 @@ index 0000000..3adc6c2 |
1235 |
+ } |
1236 |
+ |
1237 |
+ *mask &= valid; |
1238 |
-+ *mask &= kdbus_meta_attach_mask; |
1239 |
+ |
1240 |
+ if (!*mask) |
1241 |
+ goto exit; |
1242 |
@@ -16589,7 +16600,7 @@ index 0000000..3adc6c2 |
1243 |
+ size += KDBUS_ITEM_SIZE(strlen(mp->cgroup) + 1); |
1244 |
+ |
1245 |
+ if (mp && (*mask & KDBUS_ATTACH_CAPS)) |
1246 |
-+ size += KDBUS_ITEM_SIZE(sizeof(mp->caps)); |
1247 |
++ size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_meta_caps)); |
1248 |
+ |
1249 |
+ if (mp && (*mask & KDBUS_ATTACH_SECLABEL)) |
1250 |
+ size += KDBUS_ITEM_SIZE(strlen(mp->seclabel) + 1); |
1251 |
@@ -16626,6 +16637,69 @@ index 0000000..3adc6c2 |
1252 |
+ return 2 + !!kdbus_kvec_pad(kvec++, size); |
1253 |
+} |
1254 |
+ |
1255 |
++static void kdbus_meta_export_caps(struct kdbus_meta_caps *out, |
1256 |
++ struct kdbus_meta_proc *mp) |
1257 |
++{ |
1258 |
++ struct user_namespace *iter; |
1259 |
++ const struct cred *cred = mp->cred; |
1260 |
++ bool parent = false, owner = false; |
1261 |
++ int i; |
1262 |
++ |
1263 |
++ /* |
1264 |
++ * This translates the effective capabilities of 'cred' into the current |
1265 |
++ * user-namespace. If the current user-namespace is a child-namespace of |
1266 |
++ * the user-namespace of 'cred', the mask can be copied verbatim. If |
1267 |
++ * not, the mask is cleared. |
1268 |
++ * There's one exception: If 'cred' is the owner of any user-namespace |
1269 |
++ * in the path between the current user-namespace and the user-namespace |
1270 |
++ * of 'cred', then it has all effective capabilities set. This means, |
1271 |
++ * the user who created a user-namespace always has all effective |
1272 |
++ * capabilities in any child namespaces. Note that this is based on the |
1273 |
++ * uid of the namespace creator, not the task hierarchy. |
1274 |
++ */ |
1275 |
++ for (iter = current_user_ns(); iter; iter = iter->parent) { |
1276 |
++ if (iter == cred->user_ns) { |
1277 |
++ parent = true; |
1278 |
++ break; |
1279 |
++ } |
1280 |
++ |
1281 |
++ if (iter == &init_user_ns) |
1282 |
++ break; |
1283 |
++ |
1284 |
++ if ((iter->parent == cred->user_ns) && |
1285 |
++ uid_eq(iter->owner, cred->euid)) { |
1286 |
++ owner = true; |
1287 |
++ break; |
1288 |
++ } |
1289 |
++ } |
1290 |
++ |
1291 |
++ out->last_cap = CAP_LAST_CAP; |
1292 |
++ |
1293 |
++ CAP_FOR_EACH_U32(i) { |
1294 |
++ if (parent) { |
1295 |
++ out->set[0].caps[i] = cred->cap_inheritable.cap[i]; |
1296 |
++ out->set[1].caps[i] = cred->cap_permitted.cap[i]; |
1297 |
++ out->set[2].caps[i] = cred->cap_effective.cap[i]; |
1298 |
++ out->set[3].caps[i] = cred->cap_bset.cap[i]; |
1299 |
++ } else if (owner) { |
1300 |
++ out->set[0].caps[i] = 0U; |
1301 |
++ out->set[1].caps[i] = ~0U; |
1302 |
++ out->set[2].caps[i] = ~0U; |
1303 |
++ out->set[3].caps[i] = ~0U; |
1304 |
++ } else { |
1305 |
++ out->set[0].caps[i] = 0U; |
1306 |
++ out->set[1].caps[i] = 0U; |
1307 |
++ out->set[2].caps[i] = 0U; |
1308 |
++ out->set[3].caps[i] = 0U; |
1309 |
++ } |
1310 |
++ } |
1311 |
++ |
1312 |
++ /* clear unused bits */ |
1313 |
++ for (i = 0; i < 4; i++) |
1314 |
++ out->set[i].caps[CAP_TO_INDEX(CAP_LAST_CAP)] &= |
1315 |
++ CAP_LAST_U32_VALID_MASK; |
1316 |
++} |
1317 |
++ |
1318 |
+/* This is equivalent to from_kuid_munged(), but maps INVALID_UID to itself */ |
1319 |
+static uid_t kdbus_from_kuid_keep(kuid_t uid) |
1320 |
+{ |
1321 |
@@ -16684,14 +16758,6 @@ index 0000000..3adc6c2 |
1322 |
+ |
1323 |
+ hdr = &item_hdr[0]; |
1324 |
+ |
1325 |
-+ /* |
1326 |
-+ * TODO: We currently have no sane way of translating a set of caps |
1327 |
-+ * between different user namespaces. Until that changes, we have |
1328 |
-+ * to drop such items. |
1329 |
-+ */ |
1330 |
-+ if (mp && mp->caps_namespace != user_ns) |
1331 |
-+ mask &= ~KDBUS_ATTACH_CAPS; |
1332 |
-+ |
1333 |
+ if (mask == 0) { |
1334 |
+ *real_size = 0; |
1335 |
+ return 0; |
1336 |
@@ -16797,10 +16863,14 @@ index 0000000..3adc6c2 |
1337 |
+ KDBUS_ITEM_CGROUP, mp->cgroup, |
1338 |
+ strlen(mp->cgroup) + 1, &size); |
1339 |
+ |
1340 |
-+ if (mp && (mask & KDBUS_ATTACH_CAPS)) |
1341 |
++ if (mp && (mask & KDBUS_ATTACH_CAPS)) { |
1342 |
++ struct kdbus_meta_caps caps = {}; |
1343 |
++ |
1344 |
++ kdbus_meta_export_caps(&caps, mp); |
1345 |
+ cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, |
1346 |
-+ KDBUS_ITEM_CAPS, &mp->caps, |
1347 |
-+ sizeof(mp->caps), &size); |
1348 |
++ KDBUS_ITEM_CAPS, &caps, |
1349 |
++ sizeof(caps), &size); |
1350 |
++ } |
1351 |
+ |
1352 |
+ if (mp && (mask & KDBUS_ATTACH_SECLABEL)) |
1353 |
+ cnt += kdbus_meta_push_kvec(kvec + cnt, hdr++, |
1354 |
@@ -16864,10 +16934,10 @@ index 0000000..3adc6c2 |
1355 |
+} |
1356 |
diff --git a/ipc/kdbus/metadata.h b/ipc/kdbus/metadata.h |
1357 |
new file mode 100644 |
1358 |
-index 0000000..42c942b |
1359 |
+index 0000000..79b6ac3 |
1360 |
--- /dev/null |
1361 |
+++ b/ipc/kdbus/metadata.h |
1362 |
-@@ -0,0 +1,57 @@ |
1363 |
+@@ -0,0 +1,55 @@ |
1364 |
+/* |
1365 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1366 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1367 |
@@ -16894,8 +16964,6 @@ index 0000000..42c942b |
1368 |
+struct kdbus_meta_proc; |
1369 |
+struct kdbus_meta_conn; |
1370 |
+ |
1371 |
-+extern unsigned long long kdbus_meta_attach_mask; |
1372 |
-+ |
1373 |
+struct kdbus_meta_proc *kdbus_meta_proc_new(void); |
1374 |
+struct kdbus_meta_proc *kdbus_meta_proc_ref(struct kdbus_meta_proc *mp); |
1375 |
+struct kdbus_meta_proc *kdbus_meta_proc_unref(struct kdbus_meta_proc *mp); |
1376 |
@@ -16927,10 +16995,10 @@ index 0000000..42c942b |
1377 |
+#endif |
1378 |
diff --git a/ipc/kdbus/names.c b/ipc/kdbus/names.c |
1379 |
new file mode 100644 |
1380 |
-index 0000000..657008e |
1381 |
+index 0000000..d77ee08 |
1382 |
--- /dev/null |
1383 |
+++ b/ipc/kdbus/names.c |
1384 |
-@@ -0,0 +1,772 @@ |
1385 |
+@@ -0,0 +1,770 @@ |
1386 |
+/* |
1387 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1388 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1389 |
@@ -17402,7 +17470,7 @@ index 0000000..657008e |
1390 |
+ * @conn: connection to operate on |
1391 |
+ * @argp: command payload |
1392 |
+ * |
1393 |
-+ * Return: 0 on success, negative error code on failure. |
1394 |
++ * Return: >=0 on success, negative error code on failure. |
1395 |
+ */ |
1396 |
+int kdbus_cmd_name_acquire(struct kdbus_conn *conn, void __user *argp) |
1397 |
+{ |
1398 |
@@ -17447,8 +17515,6 @@ index 0000000..657008e |
1399 |
+ |
1400 |
+ ret = kdbus_name_acquire(conn->ep->bus->name_registry, conn, item_name, |
1401 |
+ cmd->flags, &cmd->return_flags); |
1402 |
-+ if (ret < 0) |
1403 |
-+ goto exit_dec; |
1404 |
+ |
1405 |
+exit_dec: |
1406 |
+ atomic_dec(&conn->name_count); |
1407 |
@@ -17461,7 +17527,7 @@ index 0000000..657008e |
1408 |
+ * @conn: connection to operate on |
1409 |
+ * @argp: command payload |
1410 |
+ * |
1411 |
-+ * Return: 0 on success, negative error code on failure. |
1412 |
++ * Return: >=0 on success, negative error code on failure. |
1413 |
+ */ |
1414 |
+int kdbus_cmd_name_release(struct kdbus_conn *conn, void __user *argp) |
1415 |
+{ |
1416 |
@@ -17632,7 +17698,7 @@ index 0000000..657008e |
1417 |
+ * @conn: connection to operate on |
1418 |
+ * @argp: command payload |
1419 |
+ * |
1420 |
-+ * Return: 0 on success, negative error code on failure. |
1421 |
++ * Return: >=0 on success, negative error code on failure. |
1422 |
+ */ |
1423 |
+int kdbus_cmd_list(struct kdbus_conn *conn, void __user *argp) |
1424 |
+{ |
1425 |
@@ -17785,10 +17851,10 @@ index 0000000..3dd2589 |
1426 |
+#endif |
1427 |
diff --git a/ipc/kdbus/node.c b/ipc/kdbus/node.c |
1428 |
new file mode 100644 |
1429 |
-index 0000000..520df00 |
1430 |
+index 0000000..0d65c65 |
1431 |
--- /dev/null |
1432 |
+++ b/ipc/kdbus/node.c |
1433 |
-@@ -0,0 +1,910 @@ |
1434 |
+@@ -0,0 +1,897 @@ |
1435 |
+/* |
1436 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1437 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1438 |
@@ -17969,7 +18035,7 @@ index 0000000..520df00 |
1439 |
+ * accessed by other callers to properly initialize |
1440 |
+ * filesystem nodes. |
1441 |
+ * |
1442 |
-+ * * node->id: This is an unsigned 32bit integer allocated by an IDR. It is |
1443 |
++ * * node->id: This is an unsigned 32bit integer allocated by an IDA. It is |
1444 |
+ * always kept as small as possible during allocation and is |
1445 |
+ * globally unique across all nodes allocated by this module. 0 |
1446 |
+ * is reserved as "not assigned" and is the default. |
1447 |
@@ -18024,8 +18090,7 @@ index 0000000..520df00 |
1448 |
+#define KDBUS_NODE_NEW (KDBUS_NODE_BIAS - 4) |
1449 |
+ |
1450 |
+/* global unique ID mapping for kdbus nodes */ |
1451 |
-+static DEFINE_IDR(kdbus_node_idr); |
1452 |
-+static DECLARE_RWSEM(kdbus_node_idr_lock); |
1453 |
++DEFINE_IDA(kdbus_node_ida); |
1454 |
+ |
1455 |
+/** |
1456 |
+ * kdbus_node_name_hash() - hash a name |
1457 |
@@ -18128,15 +18193,11 @@ index 0000000..520df00 |
1458 |
+ node->hash = kdbus_node_name_hash(name); |
1459 |
+ } |
1460 |
+ |
1461 |
-+ down_write(&kdbus_node_idr_lock); |
1462 |
-+ ret = idr_alloc(&kdbus_node_idr, node, 1, 0, GFP_KERNEL); |
1463 |
-+ if (ret >= 0) |
1464 |
-+ node->id = ret; |
1465 |
-+ up_write(&kdbus_node_idr_lock); |
1466 |
-+ |
1467 |
++ ret = ida_simple_get(&kdbus_node_ida, 1, 0, GFP_KERNEL); |
1468 |
+ if (ret < 0) |
1469 |
+ return ret; |
1470 |
+ |
1471 |
++ node->id = ret; |
1472 |
+ ret = 0; |
1473 |
+ |
1474 |
+ if (parent) { |
1475 |
@@ -18231,16 +18292,8 @@ index 0000000..520df00 |
1476 |
+ |
1477 |
+ if (node->free_cb) |
1478 |
+ node->free_cb(node); |
1479 |
-+ |
1480 |
-+ down_write(&kdbus_node_idr_lock); |
1481 |
+ if (safe.id > 0) |
1482 |
-+ idr_remove(&kdbus_node_idr, safe.id); |
1483 |
-+ /* drop caches after last node to not leak memory on unload */ |
1484 |
-+ if (idr_is_empty(&kdbus_node_idr)) { |
1485 |
-+ idr_destroy(&kdbus_node_idr); |
1486 |
-+ idr_init(&kdbus_node_idr); |
1487 |
-+ } |
1488 |
-+ up_write(&kdbus_node_idr_lock); |
1489 |
++ ida_simple_remove(&kdbus_node_ida, safe.id); |
1490 |
+ |
1491 |
+ kfree(safe.name); |
1492 |
+ |
1493 |
@@ -18701,10 +18754,10 @@ index 0000000..520df00 |
1494 |
+} |
1495 |
diff --git a/ipc/kdbus/node.h b/ipc/kdbus/node.h |
1496 |
new file mode 100644 |
1497 |
-index 0000000..be125ce |
1498 |
+index 0000000..970e02b |
1499 |
--- /dev/null |
1500 |
+++ b/ipc/kdbus/node.h |
1501 |
-@@ -0,0 +1,84 @@ |
1502 |
+@@ -0,0 +1,86 @@ |
1503 |
+/* |
1504 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1505 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1506 |
@@ -18765,6 +18818,8 @@ index 0000000..be125ce |
1507 |
+ |
1508 |
+#define kdbus_node_from_rb(_node) rb_entry((_node), struct kdbus_node, rb) |
1509 |
+ |
1510 |
++extern struct ida kdbus_node_ida; |
1511 |
++ |
1512 |
+void kdbus_node_init(struct kdbus_node *node, unsigned int type); |
1513 |
+ |
1514 |
+int kdbus_node_link(struct kdbus_node *node, struct kdbus_node *parent, |
1515 |
@@ -19633,7 +19688,7 @@ index 0000000..15dd7bc |
1516 |
+#endif |
1517 |
diff --git a/ipc/kdbus/pool.c b/ipc/kdbus/pool.c |
1518 |
new file mode 100644 |
1519 |
-index 0000000..139bb77 |
1520 |
+index 0000000..45dcdea |
1521 |
--- /dev/null |
1522 |
+++ b/ipc/kdbus/pool.c |
1523 |
@@ -0,0 +1,728 @@ |
1524 |
@@ -20314,7 +20369,7 @@ index 0000000..139bb77 |
1525 |
+ } |
1526 |
+ |
1527 |
+ kaddr = (char __force __user *)kmap(page) + page_off; |
1528 |
-+ n_read = f_src->f_op->read(f_src, kaddr, copy_len, &off_src); |
1529 |
++ n_read = __vfs_read(f_src, kaddr, copy_len, &off_src); |
1530 |
+ kunmap(page); |
1531 |
+ mark_page_accessed(page); |
1532 |
+ flush_dcache_page(page); |
1533 |
@@ -20419,7 +20474,7 @@ index 0000000..a903821 |
1534 |
+#endif |
1535 |
diff --git a/ipc/kdbus/queue.c b/ipc/kdbus/queue.c |
1536 |
new file mode 100644 |
1537 |
-index 0000000..a449464 |
1538 |
+index 0000000..25bb3ad |
1539 |
--- /dev/null |
1540 |
+++ b/ipc/kdbus/queue.c |
1541 |
@@ -0,0 +1,678 @@ |
1542 |
@@ -21062,7 +21117,7 @@ index 0000000..a449464 |
1543 |
+ lockdep_assert_held(&src->lock); |
1544 |
+ lockdep_assert_held(&dst->lock); |
1545 |
+ |
1546 |
-+ if (WARN_ON(IS_ERR(e->user)) || WARN_ON(list_empty(&e->entry))) |
1547 |
++ if (WARN_ON(list_empty(&e->entry))) |
1548 |
+ return -EINVAL; |
1549 |
+ if (src == dst) |
1550 |
+ return 0; |
1551 |
@@ -21201,10 +21256,10 @@ index 0000000..7f2db96 |
1552 |
+#endif /* __KDBUS_QUEUE_H */ |
1553 |
diff --git a/ipc/kdbus/reply.c b/ipc/kdbus/reply.c |
1554 |
new file mode 100644 |
1555 |
-index 0000000..008dca8 |
1556 |
+index 0000000..e6791d8 |
1557 |
--- /dev/null |
1558 |
+++ b/ipc/kdbus/reply.c |
1559 |
-@@ -0,0 +1,257 @@ |
1560 |
+@@ -0,0 +1,252 @@ |
1561 |
+#include <linux/init.h> |
1562 |
+#include <linux/mm.h> |
1563 |
+#include <linux/module.h> |
1564 |
@@ -21244,7 +21299,7 @@ index 0000000..008dca8 |
1565 |
+ bool sync) |
1566 |
+{ |
1567 |
+ struct kdbus_reply *r; |
1568 |
-+ int ret = 0; |
1569 |
++ int ret; |
1570 |
+ |
1571 |
+ if (atomic_inc_return(&reply_dst->request_count) > |
1572 |
+ KDBUS_CONN_MAX_REQUESTS_PENDING) { |
1573 |
@@ -21271,13 +21326,11 @@ index 0000000..008dca8 |
1574 |
+ r->waiting = true; |
1575 |
+ } |
1576 |
+ |
1577 |
-+exit_dec_request_count: |
1578 |
-+ if (ret < 0) { |
1579 |
-+ atomic_dec(&reply_dst->request_count); |
1580 |
-+ return ERR_PTR(ret); |
1581 |
-+ } |
1582 |
-+ |
1583 |
+ return r; |
1584 |
++ |
1585 |
++exit_dec_request_count: |
1586 |
++ atomic_dec(&reply_dst->request_count); |
1587 |
++ return ERR_PTR(ret); |
1588 |
+} |
1589 |
+ |
1590 |
+static void __kdbus_reply_free(struct kref *kref) |
1591 |
@@ -21347,8 +21400,7 @@ index 0000000..008dca8 |
1592 |
+ * @reply: The reply object |
1593 |
+ * @err: Error code to set on the remote side |
1594 |
+ * |
1595 |
-+ * Remove the synchronous reply object from its connection reply_list, and |
1596 |
-+ * wake up remote peer (method origin) with the appropriate synchronous reply |
1597 |
++ * Wake up remote peer (method origin) with the appropriate synchronous reply |
1598 |
+ * code. |
1599 |
+ */ |
1600 |
+void kdbus_sync_reply_wakeup(struct kdbus_reply *reply, int err) |
1601 |
@@ -21379,17 +21431,15 @@ index 0000000..008dca8 |
1602 |
+ struct kdbus_conn *reply_dst, |
1603 |
+ u64 cookie) |
1604 |
+{ |
1605 |
-+ struct kdbus_reply *r, *reply = NULL; |
1606 |
++ struct kdbus_reply *r; |
1607 |
+ |
1608 |
+ list_for_each_entry(r, &reply_dst->reply_list, entry) { |
1609 |
+ if (r->cookie == cookie && |
1610 |
-+ (!replying || r->reply_src == replying)) { |
1611 |
-+ reply = r; |
1612 |
-+ break; |
1613 |
-+ } |
1614 |
++ (!replying || r->reply_src == replying)) |
1615 |
++ return r; |
1616 |
+ } |
1617 |
+ |
1618 |
-+ return reply; |
1619 |
++ return NULL; |
1620 |
+} |
1621 |
+ |
1622 |
+/** |
1623 |
@@ -21538,10 +21588,10 @@ index 0000000..68d5232 |
1624 |
+#endif /* __KDBUS_REPLY_H */ |
1625 |
diff --git a/ipc/kdbus/util.c b/ipc/kdbus/util.c |
1626 |
new file mode 100644 |
1627 |
-index 0000000..eaa806a |
1628 |
+index 0000000..72b1883 |
1629 |
--- /dev/null |
1630 |
+++ b/ipc/kdbus/util.c |
1631 |
-@@ -0,0 +1,201 @@ |
1632 |
+@@ -0,0 +1,156 @@ |
1633 |
+/* |
1634 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1635 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1636 |
@@ -21594,51 +21644,6 @@ index 0000000..eaa806a |
1637 |
+} |
1638 |
+ |
1639 |
+/** |
1640 |
-+ * kdbus_memdup_user() - copy dynamically sized object from user-space |
1641 |
-+ * @user_ptr: user-provided source buffer |
1642 |
-+ * @sz_min: minimum object size |
1643 |
-+ * @sz_max: maximum object size |
1644 |
-+ * |
1645 |
-+ * This copies a dynamically sized object from user-space into kernel-space. We |
1646 |
-+ * require the object to have a 64bit size field at offset 0. We read it out |
1647 |
-+ * first, allocate a suitably sized buffer and then copy all data. |
1648 |
-+ * |
1649 |
-+ * The @sz_min and @sz_max parameters define possible min and max object sizes |
1650 |
-+ * so user-space cannot trigger un-bound kernel-space allocations. |
1651 |
-+ * |
1652 |
-+ * The same alignment-restrictions as described in kdbus_copy_from_user() apply. |
1653 |
-+ * |
1654 |
-+ * Return: pointer to dynamically allocated copy, or ERR_PTR() on failure. |
1655 |
-+ */ |
1656 |
-+void *kdbus_memdup_user(void __user *user_ptr, size_t sz_min, size_t sz_max) |
1657 |
-+{ |
1658 |
-+ void *ptr; |
1659 |
-+ u64 size; |
1660 |
-+ int ret; |
1661 |
-+ |
1662 |
-+ ret = kdbus_copy_from_user(&size, user_ptr, sizeof(size)); |
1663 |
-+ if (ret < 0) |
1664 |
-+ return ERR_PTR(ret); |
1665 |
-+ |
1666 |
-+ if (size < sz_min) |
1667 |
-+ return ERR_PTR(-EINVAL); |
1668 |
-+ |
1669 |
-+ if (size > sz_max) |
1670 |
-+ return ERR_PTR(-EMSGSIZE); |
1671 |
-+ |
1672 |
-+ ptr = memdup_user(user_ptr, size); |
1673 |
-+ if (IS_ERR(ptr)) |
1674 |
-+ return ptr; |
1675 |
-+ |
1676 |
-+ if (*(u64 *)ptr != size) { |
1677 |
-+ kfree(ptr); |
1678 |
-+ return ERR_PTR(-EINVAL); |
1679 |
-+ } |
1680 |
-+ |
1681 |
-+ return ptr; |
1682 |
-+} |
1683 |
-+ |
1684 |
-+/** |
1685 |
+ * kdbus_verify_uid_prefix() - verify UID prefix of a user-supplied name |
1686 |
+ * @name: user-supplied name to verify |
1687 |
+ * @user_ns: user-namespace to act in |
1688 |
@@ -21745,10 +21750,10 @@ index 0000000..eaa806a |
1689 |
+} |
1690 |
diff --git a/ipc/kdbus/util.h b/ipc/kdbus/util.h |
1691 |
new file mode 100644 |
1692 |
-index 0000000..740b198 |
1693 |
+index 0000000..5297166 |
1694 |
--- /dev/null |
1695 |
+++ b/ipc/kdbus/util.h |
1696 |
-@@ -0,0 +1,74 @@ |
1697 |
+@@ -0,0 +1,73 @@ |
1698 |
+/* |
1699 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1700 |
+ * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@×××××××××××××××.org> |
1701 |
@@ -21791,7 +21796,7 @@ index 0000000..740b198 |
1702 |
+({ \ |
1703 |
+ u64 __user *_sz = \ |
1704 |
+ (void __user *)((u8 __user *)(_b) + offsetof(_t, _m)); \ |
1705 |
-+ copy_to_user(_sz, _s, sizeof(((_t *)0)->_m)); \ |
1706 |
++ copy_to_user(_sz, _s, FIELD_SIZEOF(_t, _m)); \ |
1707 |
+}) |
1708 |
+ |
1709 |
+/** |
1710 |
@@ -21815,7 +21820,6 @@ index 0000000..740b198 |
1711 |
+int kdbus_sanitize_attach_flags(u64 flags, u64 *attach_flags); |
1712 |
+ |
1713 |
+int kdbus_copy_from_user(void *dest, void __user *user_ptr, size_t size); |
1714 |
-+void *kdbus_memdup_user(void __user *user_ptr, size_t sz_min, size_t sz_max); |
1715 |
+ |
1716 |
+struct kvec; |
1717 |
+ |
1718 |
@@ -21876,7 +21880,7 @@ index 0000000..137f842 |
1719 |
+HOSTLOADLIBES_kdbus-workers := -lrt |
1720 |
diff --git a/samples/kdbus/kdbus-api.h b/samples/kdbus/kdbus-api.h |
1721 |
new file mode 100644 |
1722 |
-index 0000000..5ed5907 |
1723 |
+index 0000000..7f3abae |
1724 |
--- /dev/null |
1725 |
+++ b/samples/kdbus/kdbus-api.h |
1726 |
@@ -0,0 +1,114 @@ |
1727 |
@@ -21890,12 +21894,12 @@ index 0000000..5ed5907 |
1728 |
+#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data) |
1729 |
+#define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE) |
1730 |
+#define KDBUS_ITEM_NEXT(item) \ |
1731 |
-+ (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size)) |
1732 |
++ (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size)) |
1733 |
+#define KDBUS_FOREACH(iter, first, _size) \ |
1734 |
-+ for (iter = (first); \ |
1735 |
++ for ((iter) = (first); \ |
1736 |
+ ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) && \ |
1737 |
+ ((uint8_t *)(iter) >= (uint8_t *)(first)); \ |
1738 |
-+ iter = (void*)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size))) |
1739 |
++ (iter) = (void *)((uint8_t *)(iter) + KDBUS_ALIGN8((iter)->size))) |
1740 |
+ |
1741 |
+static inline int kdbus_cmd_bus_make(int control_fd, struct kdbus_cmd *cmd) |
1742 |
+{ |
1743 |
@@ -21996,10 +22000,10 @@ index 0000000..5ed5907 |
1744 |
+#endif /* KDBUS_API_H */ |
1745 |
diff --git a/samples/kdbus/kdbus-workers.c b/samples/kdbus/kdbus-workers.c |
1746 |
new file mode 100644 |
1747 |
-index 0000000..d331e01 |
1748 |
+index 0000000..c3ba958 |
1749 |
--- /dev/null |
1750 |
+++ b/samples/kdbus/kdbus-workers.c |
1751 |
-@@ -0,0 +1,1326 @@ |
1752 |
+@@ -0,0 +1,1345 @@ |
1753 |
+/* |
1754 |
+ * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@×××××.com> |
1755 |
+ * |
1756 |
@@ -22059,6 +22063,12 @@ index 0000000..d331e01 |
1757 |
+ * top-down, but requires some forward-declarations. Just ignore those. |
1758 |
+ */ |
1759 |
+ |
1760 |
++#include <stdio.h> |
1761 |
++#include <stdlib.h> |
1762 |
++ |
1763 |
++/* glibc < 2.7 does not ship sys/signalfd.h */ |
1764 |
++#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 7 |
1765 |
++ |
1766 |
+#include <ctype.h> |
1767 |
+#include <errno.h> |
1768 |
+#include <fcntl.h> |
1769 |
@@ -22067,8 +22077,6 @@ index 0000000..d331e01 |
1770 |
+#include <stdbool.h> |
1771 |
+#include <stddef.h> |
1772 |
+#include <stdint.h> |
1773 |
-+#include <stdio.h> |
1774 |
-+#include <stdlib.h> |
1775 |
+#include <string.h> |
1776 |
+#include <sys/mman.h> |
1777 |
+#include <sys/poll.h> |
1778 |
@@ -23326,13 +23334,28 @@ index 0000000..d331e01 |
1779 |
+ |
1780 |
+ return fd; |
1781 |
+} |
1782 |
-diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile |
1783 |
-index 4e51122..7b51cce 100644 |
1784 |
---- a/tools/testing/selftests/Makefile |
1785 |
-+++ b/tools/testing/selftests/Makefile |
1786 |
-@@ -5,6 +5,7 @@ TARGETS += exec |
1787 |
- TARGETS += firmware |
1788 |
- TARGETS += ftrace |
1789 |
++ |
1790 |
++#else |
1791 |
++ |
1792 |
++#warning "Skipping compilation due to unsupported libc version" |
1793 |
++ |
1794 |
++int main(int argc, char **argv) |
1795 |
++{ |
1796 |
++ fprintf(stderr, |
1797 |
++ "Compilation of %s was skipped due to unsupported libc.\n", |
1798 |
++ argv[0]); |
1799 |
++ |
1800 |
++ return EXIT_FAILURE; |
1801 |
++} |
1802 |
++ |
1803 |
++#endif /* libc sanity check */ |
1804 |
+diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile |
1805 |
+index 95abddc..b57100c 100644 |
1806 |
+--- a/tools/testing/selftests/Makefile |
1807 |
++++ b/tools/testing/selftests/Makefile |
1808 |
+@@ -5,6 +5,7 @@ TARGETS += exec |
1809 |
+ TARGETS += firmware |
1810 |
+ TARGETS += ftrace |
1811 |
TARGETS += kcmp |
1812 |
+TARGETS += kdbus |
1813 |
TARGETS += memfd |
1814 |
@@ -23347,10 +23370,10 @@ index 0000000..d3ef42f |
1815 |
+kdbus-test |
1816 |
diff --git a/tools/testing/selftests/kdbus/Makefile b/tools/testing/selftests/kdbus/Makefile |
1817 |
new file mode 100644 |
1818 |
-index 0000000..de8242f |
1819 |
+index 0000000..8f36cb5 |
1820 |
--- /dev/null |
1821 |
+++ b/tools/testing/selftests/kdbus/Makefile |
1822 |
-@@ -0,0 +1,48 @@ |
1823 |
+@@ -0,0 +1,49 @@ |
1824 |
+CFLAGS += -I../../../../usr/include/ |
1825 |
+CFLAGS += -I../../../../samples/kdbus/ |
1826 |
+CFLAGS += -I../../../../include/uapi/ |
1827 |
@@ -23364,7 +23387,6 @@ index 0000000..de8242f |
1828 |
+ kdbus-test.o \ |
1829 |
+ kdbus-test.o \ |
1830 |
+ test-activator.o \ |
1831 |
-+ test-attach-flags.o \ |
1832 |
+ test-benchmark.o \ |
1833 |
+ test-bus.o \ |
1834 |
+ test-chat.o \ |
1835 |
@@ -23388,12 +23410,14 @@ index 0000000..de8242f |
1836 |
+ |
1837 |
+include ../lib.mk |
1838 |
+ |
1839 |
-+%.o: %.c |
1840 |
++%.o: %.c kdbus-enum.h kdbus-test.h kdbus-util.h |
1841 |
+ $(CC) $(CFLAGS) -c $< -o $@ |
1842 |
+ |
1843 |
+kdbus-test: $(OBJS) |
1844 |
+ $(CC) $(CFLAGS) $^ $(LDLIBS) -o $@ |
1845 |
+ |
1846 |
++TEST_PROGS := kdbus-test |
1847 |
++ |
1848 |
+run_tests: |
1849 |
+ ./kdbus-test --tap |
1850 |
+ |
1851 |
@@ -23501,10 +23525,10 @@ index 0000000..4f1e579 |
1852 |
+LOOKUP(PAYLOAD); |
1853 |
diff --git a/tools/testing/selftests/kdbus/kdbus-enum.h b/tools/testing/selftests/kdbus/kdbus-enum.h |
1854 |
new file mode 100644 |
1855 |
-index 0000000..a67cec3 |
1856 |
+index 0000000..ed28cca |
1857 |
--- /dev/null |
1858 |
+++ b/tools/testing/selftests/kdbus/kdbus-enum.h |
1859 |
-@@ -0,0 +1,14 @@ |
1860 |
+@@ -0,0 +1,15 @@ |
1861 |
+/* |
1862 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1863 |
+ * |
1864 |
@@ -23513,6 +23537,7 @@ index 0000000..a67cec3 |
1865 |
+ * Free Software Foundation; either version 2.1 of the License, or (at |
1866 |
+ * your option) any later version. |
1867 |
+ */ |
1868 |
++ |
1869 |
+#pragma once |
1870 |
+ |
1871 |
+const char *enum_CMD(long long id); |
1872 |
@@ -23521,10 +23546,10 @@ index 0000000..a67cec3 |
1873 |
+const char *enum_PAYLOAD(long long id); |
1874 |
diff --git a/tools/testing/selftests/kdbus/kdbus-test.c b/tools/testing/selftests/kdbus/kdbus-test.c |
1875 |
new file mode 100644 |
1876 |
-index 0000000..a43674c |
1877 |
+index 0000000..294e82a |
1878 |
--- /dev/null |
1879 |
+++ b/tools/testing/selftests/kdbus/kdbus-test.c |
1880 |
-@@ -0,0 +1,923 @@ |
1881 |
+@@ -0,0 +1,900 @@ |
1882 |
+#include <errno.h> |
1883 |
+#include <stdio.h> |
1884 |
+#include <string.h> |
1885 |
@@ -23575,7 +23600,6 @@ index 0000000..a43674c |
1886 |
+ char *root; |
1887 |
+ char *test; |
1888 |
+ char *busname; |
1889 |
-+ char *mask_param_path; |
1890 |
+}; |
1891 |
+ |
1892 |
+static const struct kdbus_test tests[] = { |
1893 |
@@ -23801,13 +23825,6 @@ index 0000000..a43674c |
1894 |
+ .func = kdbus_test_benchmark_uds, |
1895 |
+ .flags = TEST_CREATE_BUS, |
1896 |
+ }, |
1897 |
-+ { |
1898 |
-+ /* Last test */ |
1899 |
-+ .name = "attach-flags", |
1900 |
-+ .desc = "attach flags mask", |
1901 |
-+ .func = kdbus_test_attach_flags, |
1902 |
-+ .flags = 0, |
1903 |
-+ }, |
1904 |
+}; |
1905 |
+ |
1906 |
+#define N_TESTS ((int) (sizeof(tests) / sizeof(tests[0]))) |
1907 |
@@ -23850,7 +23867,6 @@ index 0000000..a43674c |
1908 |
+ |
1909 |
+ env->root = args->root; |
1910 |
+ env->module = args->module; |
1911 |
-+ env->mask_param_path = args->mask_param_path; |
1912 |
+ |
1913 |
+ return 0; |
1914 |
+} |
1915 |
@@ -24281,8 +24297,7 @@ index 0000000..a43674c |
1916 |
+{ |
1917 |
+ int ret; |
1918 |
+ bool namespaces; |
1919 |
-+ uint64_t kdbus_param_mask; |
1920 |
-+ static char fspath[4096], parampath[4096]; |
1921 |
++ static char fspath[4096]; |
1922 |
+ |
1923 |
+ namespaces = (kdbus_args->mntns || kdbus_args->pidns || |
1924 |
+ kdbus_args->userns); |
1925 |
@@ -24318,19 +24333,6 @@ index 0000000..a43674c |
1926 |
+ kdbus_args->root = fspath; |
1927 |
+ } |
1928 |
+ |
1929 |
-+ snprintf(parampath, sizeof(parampath), |
1930 |
-+ "/sys/module/%s/parameters/attach_flags_mask", |
1931 |
-+ kdbus_args->module); |
1932 |
-+ kdbus_args->mask_param_path = parampath; |
1933 |
-+ |
1934 |
-+ ret = kdbus_sysfs_get_parameter_mask(kdbus_args->mask_param_path, |
1935 |
-+ &kdbus_param_mask); |
1936 |
-+ if (ret < 0) |
1937 |
-+ return TEST_ERR; |
1938 |
-+ |
1939 |
-+ printf("# Starting tests with an attach_flags_mask=0x%llx\n", |
1940 |
-+ (unsigned long long)kdbus_param_mask); |
1941 |
-+ |
1942 |
+ /* Start tests */ |
1943 |
+ if (namespaces) |
1944 |
+ ret = run_tests_in_namespaces(kdbus_args); |
1945 |
@@ -24450,10 +24452,10 @@ index 0000000..a43674c |
1946 |
+} |
1947 |
diff --git a/tools/testing/selftests/kdbus/kdbus-test.h b/tools/testing/selftests/kdbus/kdbus-test.h |
1948 |
new file mode 100644 |
1949 |
-index 0000000..6473318 |
1950 |
+index 0000000..a5c6ae8 |
1951 |
--- /dev/null |
1952 |
+++ b/tools/testing/selftests/kdbus/kdbus-test.h |
1953 |
-@@ -0,0 +1,85 @@ |
1954 |
+@@ -0,0 +1,83 @@ |
1955 |
+#ifndef _TEST_KDBUS_H_ |
1956 |
+#define _TEST_KDBUS_H_ |
1957 |
+ |
1958 |
@@ -24461,7 +24463,6 @@ index 0000000..6473318 |
1959 |
+ char *buspath; |
1960 |
+ const char *root; |
1961 |
+ const char *module; |
1962 |
-+ const char *mask_param_path; |
1963 |
+ int control_fd; |
1964 |
+ struct kdbus_conn *conn; |
1965 |
+}; |
1966 |
@@ -24500,7 +24501,6 @@ index 0000000..6473318 |
1967 |
+ ASSERT_EXIT_VAL(cond, EXIT_FAILURE) |
1968 |
+ |
1969 |
+int kdbus_test_activator(struct kdbus_test_env *env); |
1970 |
-+int kdbus_test_attach_flags(struct kdbus_test_env *env); |
1971 |
+int kdbus_test_benchmark(struct kdbus_test_env *env); |
1972 |
+int kdbus_test_benchmark_nomemfds(struct kdbus_test_env *env); |
1973 |
+int kdbus_test_benchmark_uds(struct kdbus_test_env *env); |
1974 |
@@ -24541,10 +24541,10 @@ index 0000000..6473318 |
1975 |
+#endif /* _TEST_KDBUS_H_ */ |
1976 |
diff --git a/tools/testing/selftests/kdbus/kdbus-util.c b/tools/testing/selftests/kdbus/kdbus-util.c |
1977 |
new file mode 100644 |
1978 |
-index 0000000..4b376ec |
1979 |
+index 0000000..29a0cb1 |
1980 |
--- /dev/null |
1981 |
+++ b/tools/testing/selftests/kdbus/kdbus-util.c |
1982 |
-@@ -0,0 +1,1615 @@ |
1983 |
+@@ -0,0 +1,1617 @@ |
1984 |
+/* |
1985 |
+ * Copyright (C) 2013-2015 Daniel Mack |
1986 |
+ * Copyright (C) 2013-2015 Kay Sievers |
1987 |
@@ -24955,11 +24955,9 @@ index 0000000..4b376ec |
1988 |
+{ |
1989 |
+ int ret, fd; |
1990 |
+ |
1991 |
-+ ret = syscall(__NR_memfd_create, name, MFD_ALLOW_SEALING); |
1992 |
-+ if (ret < 0) |
1993 |
-+ return ret; |
1994 |
-+ |
1995 |
-+ fd = ret; |
1996 |
++ fd = syscall(__NR_memfd_create, name, MFD_ALLOW_SEALING); |
1997 |
++ if (fd < 0) |
1998 |
++ return fd; |
1999 |
+ |
2000 |
+ ret = ftruncate(fd, size); |
2001 |
+ if (ret < 0) { |
2002 |
@@ -25001,8 +24999,8 @@ index 0000000..4b376ec |
2003 |
+ uint64_t cmd_flags, |
2004 |
+ int cancel_fd) |
2005 |
+{ |
2006 |
-+ struct kdbus_cmd_send *cmd; |
2007 |
-+ struct kdbus_msg *msg; |
2008 |
++ struct kdbus_cmd_send *cmd = NULL; |
2009 |
++ struct kdbus_msg *msg = NULL; |
2010 |
+ const char ref1[1024 * 128 + 3] = "0123456789_0"; |
2011 |
+ const char ref2[] = "0123456789_1"; |
2012 |
+ struct kdbus_item *item; |
2013 |
@@ -25011,10 +25009,7 @@ index 0000000..4b376ec |
2014 |
+ int memfd = -1; |
2015 |
+ int ret; |
2016 |
+ |
2017 |
-+ size = sizeof(*msg); |
2018 |
-+ size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec)); |
2019 |
-+ size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec)); |
2020 |
-+ size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec)); |
2021 |
++ size = sizeof(*msg) + 3 * KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec)); |
2022 |
+ |
2023 |
+ if (dst_id == KDBUS_DST_ID_BROADCAST) |
2024 |
+ size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_bloom_filter)) + 64; |
2025 |
@@ -25028,14 +25023,14 @@ index 0000000..4b376ec |
2026 |
+ if (write(memfd, "kdbus memfd 1234567", 19) != 19) { |
2027 |
+ ret = -errno; |
2028 |
+ kdbus_printf("writing to memfd failed: %m\n"); |
2029 |
-+ return ret; |
2030 |
++ goto out; |
2031 |
+ } |
2032 |
+ |
2033 |
+ ret = sys_memfd_seal_set(memfd); |
2034 |
+ if (ret < 0) { |
2035 |
+ ret = -errno; |
2036 |
+ kdbus_printf("memfd sealing failed: %m\n"); |
2037 |
-+ return ret; |
2038 |
++ goto out; |
2039 |
+ } |
2040 |
+ |
2041 |
+ size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_memfd)); |
2042 |
@@ -25048,7 +25043,7 @@ index 0000000..4b376ec |
2043 |
+ if (!msg) { |
2044 |
+ ret = -errno; |
2045 |
+ kdbus_printf("unable to malloc()!?\n"); |
2046 |
-+ return ret; |
2047 |
++ goto out; |
2048 |
+ } |
2049 |
+ |
2050 |
+ if (dst_id == KDBUS_DST_ID_BROADCAST) |
2051 |
@@ -25066,7 +25061,7 @@ index 0000000..4b376ec |
2052 |
+ if (timeout) { |
2053 |
+ ret = clock_gettime(CLOCK_MONOTONIC_COARSE, &now); |
2054 |
+ if (ret < 0) |
2055 |
-+ return ret; |
2056 |
++ goto out; |
2057 |
+ |
2058 |
+ msg->timeout_ns = now.tv_sec * 1000000000ULL + |
2059 |
+ now.tv_nsec + timeout; |
2060 |
@@ -25117,6 +25112,12 @@ index 0000000..4b376ec |
2061 |
+ size += KDBUS_ITEM_SIZE(sizeof(cancel_fd)); |
2062 |
+ |
2063 |
+ cmd = malloc(size); |
2064 |
++ if (!cmd) { |
2065 |
++ ret = -errno; |
2066 |
++ kdbus_printf("unable to malloc()!?\n"); |
2067 |
++ goto out; |
2068 |
++ } |
2069 |
++ |
2070 |
+ cmd->size = size; |
2071 |
+ cmd->flags = cmd_flags; |
2072 |
+ cmd->msg_address = (uintptr_t)msg; |
2073 |
@@ -25131,12 +25132,9 @@ index 0000000..4b376ec |
2074 |
+ } |
2075 |
+ |
2076 |
+ ret = kdbus_cmd_send(conn->fd, cmd); |
2077 |
-+ if (memfd >= 0) |
2078 |
-+ close(memfd); |
2079 |
-+ |
2080 |
+ if (ret < 0) { |
2081 |
+ kdbus_printf("error sending message: %d (%m)\n", ret); |
2082 |
-+ return ret; |
2083 |
++ goto out; |
2084 |
+ } |
2085 |
+ |
2086 |
+ if (cmd_flags & KDBUS_SEND_SYNC_REPLY) { |
2087 |
@@ -25150,13 +25148,17 @@ index 0000000..4b376ec |
2088 |
+ |
2089 |
+ ret = kdbus_free(conn, cmd->reply.offset); |
2090 |
+ if (ret < 0) |
2091 |
-+ return ret; |
2092 |
++ goto out; |
2093 |
+ } |
2094 |
+ |
2095 |
++out: |
2096 |
+ free(msg); |
2097 |
+ free(cmd); |
2098 |
+ |
2099 |
-+ return 0; |
2100 |
++ if (memfd >= 0) |
2101 |
++ close(memfd); |
2102 |
++ |
2103 |
++ return ret < 0 ? ret : 0; |
2104 |
+} |
2105 |
+ |
2106 |
+int kdbus_msg_send(const struct kdbus_conn *conn, const char *name, |
2107 |
@@ -25900,7 +25902,7 @@ index 0000000..4b376ec |
2108 |
+ return 0; |
2109 |
+} |
2110 |
+ |
2111 |
-+int all_uids_gids_are_mapped() |
2112 |
++int all_uids_gids_are_mapped(void) |
2113 |
+{ |
2114 |
+ int ret; |
2115 |
+ |
2116 |
@@ -26094,7 +26096,7 @@ index 0000000..4b376ec |
2117 |
+ cap_t caps; |
2118 |
+ |
2119 |
+ caps = cap_get_proc(); |
2120 |
-+ if (!cap) { |
2121 |
++ if (!caps) { |
2122 |
+ ret = -errno; |
2123 |
+ kdbus_printf("error cap_get_proc(): %d (%m)\n", ret); |
2124 |
+ return ret; |
2125 |
@@ -26162,10 +26164,10 @@ index 0000000..4b376ec |
2126 |
+} |
2127 |
diff --git a/tools/testing/selftests/kdbus/kdbus-util.h b/tools/testing/selftests/kdbus/kdbus-util.h |
2128 |
new file mode 100644 |
2129 |
-index 0000000..50ff071 |
2130 |
+index 0000000..d1a0f1b |
2131 |
--- /dev/null |
2132 |
+++ b/tools/testing/selftests/kdbus/kdbus-util.h |
2133 |
-@@ -0,0 +1,222 @@ |
2134 |
+@@ -0,0 +1,219 @@ |
2135 |
+/* |
2136 |
+ * Copyright (C) 2013-2015 Kay Sievers |
2137 |
+ * Copyright (C) 2013-2015 Daniel Mack |
2138 |
@@ -26175,6 +26177,7 @@ index 0000000..50ff071 |
2139 |
+ * Free Software Foundation; either version 2.1 of the License, or (at |
2140 |
+ * your option) any later version. |
2141 |
+ */ |
2142 |
++ |
2143 |
+#pragma once |
2144 |
+ |
2145 |
+#define BIT(X) (1 << (X)) |
2146 |
@@ -26194,28 +26197,26 @@ index 0000000..50ff071 |
2147 |
+#define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE) |
2148 |
+ |
2149 |
+#define KDBUS_ITEM_NEXT(item) \ |
2150 |
-+ (typeof(item))(((uint8_t *)item) + KDBUS_ALIGN8((item)->size)) |
2151 |
++ (typeof(item))((uint8_t *)(item) + KDBUS_ALIGN8((item)->size)) |
2152 |
+#define KDBUS_ITEM_FOREACH(item, head, first) \ |
2153 |
-+ for (item = (head)->first; \ |
2154 |
++ for ((item) = (head)->first; \ |
2155 |
+ ((uint8_t *)(item) < (uint8_t *)(head) + (head)->size) && \ |
2156 |
-+ ((uint8_t *)(item) >= (uint8_t *)(head)); \ |
2157 |
-+ item = KDBUS_ITEM_NEXT(item)) |
2158 |
++ ((uint8_t *)(item) >= (uint8_t *)(head)); \ |
2159 |
++ (item) = KDBUS_ITEM_NEXT(item)) |
2160 |
+#define KDBUS_FOREACH(iter, first, _size) \ |
2161 |
-+ for (iter = (first); \ |
2162 |
++ for ((iter) = (first); \ |
2163 |
+ ((uint8_t *)(iter) < (uint8_t *)(first) + (_size)) && \ |
2164 |
+ ((uint8_t *)(iter) >= (uint8_t *)(first)); \ |
2165 |
-+ iter = (void*)(((uint8_t *)iter) + KDBUS_ALIGN8((iter)->size))) |
2166 |
++ (iter) = (void *)((uint8_t *)(iter) + KDBUS_ALIGN8((iter)->size))) |
2167 |
+ |
2168 |
-+ |
2169 |
-+#define _KDBUS_ATTACH_BITS_SET_NR (__builtin_popcountll(_KDBUS_ATTACH_ALL)) |
2170 |
++#define _KDBUS_ATTACH_BITS_SET_NR (__builtin_popcountll(_KDBUS_ATTACH_ALL)) |
2171 |
+ |
2172 |
+/* Sum of KDBUS_ITEM_* that reflects _KDBUS_ATTACH_ALL */ |
2173 |
-+#define KDBUS_ATTACH_ITEMS_TYPE_SUM \ |
2174 |
-+ ((((_KDBUS_ATTACH_BITS_SET_NR - 1) * \ |
2175 |
-+ ((_KDBUS_ATTACH_BITS_SET_NR - 1) + 1)) / 2 ) + \ |
2176 |
++#define KDBUS_ATTACH_ITEMS_TYPE_SUM \ |
2177 |
++ ((((_KDBUS_ATTACH_BITS_SET_NR - 1) * \ |
2178 |
++ ((_KDBUS_ATTACH_BITS_SET_NR - 1) + 1)) / 2) + \ |
2179 |
+ (_KDBUS_ITEM_ATTACH_BASE * _KDBUS_ATTACH_BITS_SET_NR)) |
2180 |
+ |
2181 |
-+ |
2182 |
+#define POOL_SIZE (16 * 1024LU * 1024LU) |
2183 |
+ |
2184 |
+#define UNPRIV_UID 65534 |
2185 |
@@ -26273,7 +26274,7 @@ index 0000000..50ff071 |
2186 |
+ _setup_; \ |
2187 |
+ efd = eventfd(0, EFD_CLOEXEC); \ |
2188 |
+ ASSERT_RETURN(efd >= 0); \ |
2189 |
-+ *clone_ret = 0; \ |
2190 |
++ *(clone_ret) = 0; \ |
2191 |
+ pid = syscall(__NR_clone, flags, NULL); \ |
2192 |
+ if (pid == 0) { \ |
2193 |
+ eventfd_t event_status = 0; \ |
2194 |
@@ -26298,7 +26299,7 @@ index 0000000..50ff071 |
2195 |
+ ret = TEST_OK; \ |
2196 |
+ } else { \ |
2197 |
+ ret = -errno; \ |
2198 |
-+ *clone_ret = -errno; \ |
2199 |
++ *(clone_ret) = -errno; \ |
2200 |
+ } \ |
2201 |
+ close(efd); \ |
2202 |
+ ret; \ |
2203 |
@@ -26375,14 +26376,12 @@ index 0000000..50ff071 |
2204 |
+ uint64_t type, uint64_t id); |
2205 |
+int kdbus_add_match_empty(struct kdbus_conn *conn); |
2206 |
+ |
2207 |
-+int all_uids_gids_are_mapped(); |
2208 |
++int all_uids_gids_are_mapped(void); |
2209 |
+int drop_privileges(uid_t uid, gid_t gid); |
2210 |
+uint64_t now(clockid_t clock); |
2211 |
+char *unique_name(const char *prefix); |
2212 |
+ |
2213 |
-+int userns_map_uid_gid(pid_t pid, |
2214 |
-+ const char *map_uid, |
2215 |
-+ const char *map_gid); |
2216 |
++int userns_map_uid_gid(pid_t pid, const char *map_uid, const char *map_gid); |
2217 |
+int test_is_capable(int cap, ...); |
2218 |
+int config_user_ns_is_enabled(void); |
2219 |
+int config_auditsyscall_is_enabled(void); |
2220 |
@@ -26712,762 +26711,6 @@ index 0000000..3d1b763 |
2221 |
+ |
2222 |
+ return TEST_OK; |
2223 |
+} |
2224 |
-diff --git a/tools/testing/selftests/kdbus/test-attach-flags.c b/tools/testing/selftests/kdbus/test-attach-flags.c |
2225 |
-new file mode 100644 |
2226 |
-index 0000000..deee7c3 |
2227 |
---- /dev/null |
2228 |
-+++ b/tools/testing/selftests/kdbus/test-attach-flags.c |
2229 |
-@@ -0,0 +1,750 @@ |
2230 |
-+#include <stdio.h> |
2231 |
-+#include <string.h> |
2232 |
-+#include <stdlib.h> |
2233 |
-+#include <stdbool.h> |
2234 |
-+#include <stddef.h> |
2235 |
-+#include <fcntl.h> |
2236 |
-+#include <unistd.h> |
2237 |
-+#include <stdint.h> |
2238 |
-+#include <errno.h> |
2239 |
-+#include <assert.h> |
2240 |
-+#include <sys/capability.h> |
2241 |
-+#include <sys/mman.h> |
2242 |
-+#include <sys/stat.h> |
2243 |
-+#include <sys/types.h> |
2244 |
-+#include <linux/unistd.h> |
2245 |
-+ |
2246 |
-+#include "kdbus-api.h" |
2247 |
-+#include "kdbus-test.h" |
2248 |
-+#include "kdbus-util.h" |
2249 |
-+#include "kdbus-enum.h" |
2250 |
-+ |
2251 |
-+/* |
2252 |
-+ * Should be the sum of the currently supported and compiled-in |
2253 |
-+ * KDBUS_ITEMS_* that reflect KDBUS_ATTACH_* flags. |
2254 |
-+ */ |
2255 |
-+static unsigned int KDBUS_TEST_ITEMS_SUM = KDBUS_ATTACH_ITEMS_TYPE_SUM; |
2256 |
-+ |
2257 |
-+static struct kdbus_conn *__kdbus_hello(const char *path, uint64_t flags, |
2258 |
-+ uint64_t attach_flags_send, |
2259 |
-+ uint64_t attach_flags_recv) |
2260 |
-+{ |
2261 |
-+ struct kdbus_cmd_free cmd_free = {}; |
2262 |
-+ int ret, fd; |
2263 |
-+ struct kdbus_conn *conn; |
2264 |
-+ struct { |
2265 |
-+ struct kdbus_cmd_hello hello; |
2266 |
-+ |
2267 |
-+ struct { |
2268 |
-+ uint64_t size; |
2269 |
-+ uint64_t type; |
2270 |
-+ char str[16]; |
2271 |
-+ } conn_name; |
2272 |
-+ |
2273 |
-+ uint8_t extra_items[0]; |
2274 |
-+ } h; |
2275 |
-+ |
2276 |
-+ memset(&h, 0, sizeof(h)); |
2277 |
-+ |
2278 |
-+ kdbus_printf("-- opening bus connection %s\n", path); |
2279 |
-+ fd = open(path, O_RDWR|O_CLOEXEC); |
2280 |
-+ if (fd < 0) { |
2281 |
-+ kdbus_printf("--- error %d (%m)\n", fd); |
2282 |
-+ return NULL; |
2283 |
-+ } |
2284 |
-+ |
2285 |
-+ h.hello.flags = flags | KDBUS_HELLO_ACCEPT_FD; |
2286 |
-+ h.hello.attach_flags_send = attach_flags_send; |
2287 |
-+ h.hello.attach_flags_recv = attach_flags_recv; |
2288 |
-+ h.conn_name.type = KDBUS_ITEM_CONN_DESCRIPTION; |
2289 |
-+ strcpy(h.conn_name.str, "this-is-my-name"); |
2290 |
-+ h.conn_name.size = KDBUS_ITEM_HEADER_SIZE + strlen(h.conn_name.str) + 1; |
2291 |
-+ |
2292 |
-+ h.hello.size = sizeof(h); |
2293 |
-+ h.hello.pool_size = POOL_SIZE; |
2294 |
-+ |
2295 |
-+ ret = kdbus_cmd_hello(fd, (struct kdbus_cmd_hello *) &h.hello); |
2296 |
-+ if (ret < 0) { |
2297 |
-+ kdbus_printf("--- error when saying hello: %d (%m)\n", ret); |
2298 |
-+ return NULL; |
2299 |
-+ } |
2300 |
-+ |
2301 |
-+ kdbus_printf("-- New connection ID : %llu\n", |
2302 |
-+ (unsigned long long)h.hello.id); |
2303 |
-+ |
2304 |
-+ cmd_free.size = sizeof(cmd_free); |
2305 |
-+ cmd_free.offset = h.hello.offset; |
2306 |
-+ ret = kdbus_cmd_free(fd, &cmd_free); |
2307 |
-+ if (ret < 0) |
2308 |
-+ return NULL; |
2309 |
-+ |
2310 |
-+ conn = malloc(sizeof(*conn)); |
2311 |
-+ if (!conn) { |
2312 |
-+ kdbus_printf("unable to malloc()!?\n"); |
2313 |
-+ return NULL; |
2314 |
-+ } |
2315 |
-+ |
2316 |
-+ conn->buf = mmap(NULL, POOL_SIZE, PROT_READ, MAP_SHARED, fd, 0); |
2317 |
-+ if (conn->buf == MAP_FAILED) { |
2318 |
-+ ret = -errno; |
2319 |
-+ free(conn); |
2320 |
-+ close(fd); |
2321 |
-+ kdbus_printf("--- error mmap: %d (%m)\n", ret); |
2322 |
-+ return NULL; |
2323 |
-+ } |
2324 |
-+ |
2325 |
-+ conn->fd = fd; |
2326 |
-+ conn->id = h.hello.id; |
2327 |
-+ return conn; |
2328 |
-+} |
2329 |
-+ |
2330 |
-+static int kdbus_test_peers_creation(struct kdbus_test_env *env) |
2331 |
-+{ |
2332 |
-+ int ret; |
2333 |
-+ int control_fd; |
2334 |
-+ char *path; |
2335 |
-+ char *busname; |
2336 |
-+ char buspath[2048]; |
2337 |
-+ char control_path[2048]; |
2338 |
-+ uint64_t attach_flags_mask; |
2339 |
-+ struct kdbus_conn *conn; |
2340 |
-+ |
2341 |
-+ snprintf(control_path, sizeof(control_path), |
2342 |
-+ "%s/control", env->root); |
2343 |
-+ |
2344 |
-+ /* |
2345 |
-+ * Set kdbus system-wide mask to 0, this has nothing |
2346 |
-+ * to do with the following tests, bus and connection |
2347 |
-+ * creation nor connection update, but we do it so we are |
2348 |
-+ * sure that everything work as expected |
2349 |
-+ */ |
2350 |
-+ |
2351 |
-+ attach_flags_mask = 0; |
2352 |
-+ ret = kdbus_sysfs_set_parameter_mask(env->mask_param_path, |
2353 |
-+ attach_flags_mask); |
2354 |
-+ ASSERT_RETURN(ret == 0); |
2355 |
-+ |
2356 |
-+ |
2357 |
-+ /* |
2358 |
-+ * Create bus with a full set of ATTACH flags |
2359 |
-+ */ |
2360 |
-+ |
2361 |
-+ control_fd = open(control_path, O_RDWR); |
2362 |
-+ ASSERT_RETURN(control_fd >= 0); |
2363 |
-+ |
2364 |
-+ busname = unique_name("test-peers-creation-bus"); |
2365 |
-+ ASSERT_RETURN(busname); |
2366 |
-+ |
2367 |
-+ ret = kdbus_create_bus(control_fd, busname, _KDBUS_ATTACH_ALL, |
2368 |
-+ 0, &path); |
2369 |
-+ ASSERT_RETURN(ret == 0); |
2370 |
-+ |
2371 |
-+ snprintf(buspath, sizeof(buspath), "%s/%s/bus", env->root, path); |
2372 |
-+ |
2373 |
-+ /* |
2374 |
-+ * Create a connection with an empty send attach flags, or |
2375 |
-+ * with just KDBUS_ATTACH_CREDS, this should fail |
2376 |
-+ */ |
2377 |
-+ conn = __kdbus_hello(buspath, 0, 0, 0); |
2378 |
-+ ASSERT_RETURN(conn == NULL); |
2379 |
-+ ASSERT_RETURN(errno == ECONNREFUSED); |
2380 |
-+ |
2381 |
-+ conn = __kdbus_hello(buspath, 0, KDBUS_ATTACH_CREDS, |
2382 |
-+ _KDBUS_ATTACH_ALL); |
2383 |
-+ ASSERT_RETURN(conn == NULL); |
2384 |
-+ ASSERT_RETURN(errno == ECONNREFUSED); |
2385 |
-+ |
2386 |
-+ conn = __kdbus_hello(buspath, 0, _KDBUS_ATTACH_ALL, 0); |
2387 |
-+ ASSERT_RETURN(conn); |
2388 |
-+ |
2389 |
-+ /* Try to cut back some send attach flags */ |
2390 |
-+ ret = kdbus_conn_update_attach_flags(conn, |
2391 |
-+ KDBUS_ATTACH_CREDS| |
2392 |
-+ KDBUS_ATTACH_PIDS, |
2393 |
-+ _KDBUS_ATTACH_ALL); |
2394 |
-+ ASSERT_RETURN(ret == -EINVAL); |
2395 |
-+ |
2396 |
-+ ret = kdbus_conn_update_attach_flags(conn, |
2397 |
-+ _KDBUS_ATTACH_ALL, 0); |
2398 |
-+ ASSERT_RETURN(ret == 0); |
2399 |
-+ |
2400 |
-+ kdbus_conn_free(conn); |
2401 |
-+ free(path); |
2402 |
-+ free(busname); |
2403 |
-+ close(control_fd); |
2404 |
-+ |
2405 |
-+ |
2406 |
-+ /* Test a new bus with KDBUS_ATTACH_PIDS */ |
2407 |
-+ |
2408 |
-+ control_fd = open(control_path, O_RDWR); |
2409 |
-+ ASSERT_RETURN(control_fd >= 0); |
2410 |
-+ |
2411 |
-+ busname = unique_name("test-peer-flags-bus"); |
2412 |
-+ ASSERT_RETURN(busname); |
2413 |
-+ |
2414 |
-+ ret = kdbus_create_bus(control_fd, busname, KDBUS_ATTACH_PIDS, |
2415 |
-+ 0, &path); |
2416 |
-+ ASSERT_RETURN(ret == 0); |
2417 |
-+ |
2418 |
-+ snprintf(buspath, sizeof(buspath), "%s/%s/bus", env->root, path); |
2419 |
-+ |
2420 |
-+ /* |
2421 |
-+ * Create a connection with an empty send attach flags, or |
2422 |
-+ * all flags except KDBUS_ATTACH_PIDS |
2423 |
-+ */ |
2424 |
-+ conn = __kdbus_hello(buspath, 0, 0, 0); |
2425 |
-+ ASSERT_RETURN(conn == NULL); |
2426 |
-+ ASSERT_RETURN(errno == ECONNREFUSED); |
2427 |
-+ |
2428 |
-+ conn = __kdbus_hello(buspath, 0, |
2429 |
-+ _KDBUS_ATTACH_ALL & ~KDBUS_ATTACH_PIDS, |
2430 |
-+ _KDBUS_ATTACH_ALL); |
2431 |
-+ ASSERT_RETURN(conn == NULL); |
2432 |
-+ ASSERT_RETURN(errno == ECONNREFUSED); |
2433 |
-+ |
2434 |
-+ /* The following should succeed */ |
2435 |
-+ conn = __kdbus_hello(buspath, 0, KDBUS_ATTACH_PIDS, 0); |
2436 |
-+ ASSERT_RETURN(conn); |
2437 |
-+ kdbus_conn_free(conn); |
2438 |
-+ |
2439 |
-+ conn = __kdbus_hello(buspath, 0, _KDBUS_ATTACH_ALL, 0); |
2440 |
-+ ASSERT_RETURN(conn); |
2441 |
-+ |
2442 |
-+ ret = kdbus_conn_update_attach_flags(conn, |
2443 |
-+ _KDBUS_ATTACH_ALL & |
2444 |
-+ ~KDBUS_ATTACH_PIDS, |
2445 |
-+ _KDBUS_ATTACH_ALL); |
2446 |
-+ ASSERT_RETURN(ret == -EINVAL); |
2447 |
-+ |
2448 |
-+ ret = kdbus_conn_update_attach_flags(conn, 0, |
2449 |
-+ _KDBUS_ATTACH_ALL); |
2450 |
-+ ASSERT_RETURN(ret == -EINVAL); |
2451 |
-+ |
2452 |
-+ /* Now we want only KDBUS_ATTACH_PIDS */ |
2453 |
-+ ret = kdbus_conn_update_attach_flags(conn, |
2454 |
-+ KDBUS_ATTACH_PIDS, 0); |
2455 |
-+ ASSERT_RETURN(ret == 0); |
2456 |
-+ |
2457 |
-+ kdbus_conn_free(conn); |
2458 |
-+ free(path); |
2459 |
-+ free(busname); |
2460 |
-+ close(control_fd); |
2461 |
-+ |
2462 |
-+ |
2463 |
-+ /* |
2464 |
-+ * Create bus with 0 as ATTACH flags, the bus does not |
2465 |
-+ * require any attach flags |
2466 |
-+ */ |
2467 |
-+ |
2468 |
-+ control_fd = open(control_path, O_RDWR); |
2469 |
-+ ASSERT_RETURN(control_fd >= 0); |
2470 |
-+ |
2471 |
-+ busname = unique_name("test-peer-flags-bus"); |
2472 |
-+ ASSERT_RETURN(busname); |
2473 |
-+ |
2474 |
-+ ret = kdbus_create_bus(control_fd, busname, 0, 0, &path); |
2475 |
-+ ASSERT_RETURN(ret == 0); |
2476 |
-+ |
2477 |
-+ snprintf(buspath, sizeof(buspath), "%s/%s/bus", env->root, path); |
2478 |
-+ |
2479 |
-+ /* Bus is open it does not require any send attach flags */ |
2480 |
-+ conn = __kdbus_hello(buspath, 0, 0, 0); |
2481 |
-+ ASSERT_RETURN(conn); |
2482 |
-+ kdbus_conn_free(conn); |
2483 |
-+ |
2484 |
-+ conn = __kdbus_hello(buspath, 0, _KDBUS_ATTACH_ALL, 0); |
2485 |
-+ ASSERT_RETURN(conn); |
2486 |
-+ |
2487 |
-+ ret = kdbus_conn_update_attach_flags(conn, 0, 0); |
2488 |
-+ ASSERT_RETURN(ret == 0); |
2489 |
-+ |
2490 |
-+ ret = kdbus_conn_update_attach_flags(conn, KDBUS_ATTACH_CREDS, 0); |
2491 |
-+ ASSERT_RETURN(ret == 0); |
2492 |
-+ |
2493 |
-+ kdbus_conn_free(conn); |
2494 |
-+ free(path); |
2495 |
-+ free(busname); |
2496 |
-+ close(control_fd); |
2497 |
-+ |
2498 |
-+ return 0; |
2499 |
-+} |
2500 |
-+ |
2501 |
-+static int kdbus_test_peers_info(struct kdbus_test_env *env) |
2502 |
-+{ |
2503 |
-+ int ret; |
2504 |
-+ int control_fd; |
2505 |
-+ char *path; |
2506 |
-+ char *busname; |
2507 |
-+ unsigned int i = 0; |
2508 |
-+ uint64_t offset = 0; |
2509 |
-+ char buspath[2048]; |
2510 |
-+ char control_path[2048]; |
2511 |
-+ uint64_t attach_flags_mask; |
2512 |
-+ struct kdbus_item *item; |
2513 |
-+ struct kdbus_info *info; |
2514 |
-+ struct kdbus_conn *conn; |
2515 |
-+ struct kdbus_conn *reader; |
2516 |
-+ unsigned long long attach_count = 0; |
2517 |
-+ |
2518 |
-+ snprintf(control_path, sizeof(control_path), |
2519 |
-+ "%s/control", env->root); |
2520 |
-+ |
2521 |
-+ attach_flags_mask = 0; |
2522 |
-+ ret = kdbus_sysfs_set_parameter_mask(env->mask_param_path, |
2523 |
-+ attach_flags_mask); |
2524 |
-+ ASSERT_RETURN(ret == 0); |
2525 |
-+ |
2526 |
-+ control_fd = open(control_path, O_RDWR); |
2527 |
-+ ASSERT_RETURN(control_fd >= 0); |
2528 |
-+ |
2529 |
-+ busname = unique_name("test-peers-info-bus"); |
2530 |
-+ ASSERT_RETURN(busname); |
2531 |
-+ |
2532 |
-+ ret = kdbus_create_bus(control_fd, busname, _KDBUS_ATTACH_ALL, |
2533 |
-+ 0, &path); |
2534 |
-+ ASSERT_RETURN(ret == 0); |
2535 |
-+ |
2536 |
-+ snprintf(buspath, sizeof(buspath), "%s/%s/bus", env->root, path); |
2537 |
-+ |
2538 |
-+ /* Create connections with the appropriate flags */ |
2539 |
-+ conn = __kdbus_hello(buspath, 0, _KDBUS_ATTACH_ALL, 0); |
2540 |
-+ ASSERT_RETURN(conn); |
2541 |
-+ |
2542 |
-+ reader = __kdbus_hello(buspath, 0, _KDBUS_ATTACH_ALL, 0); |
2543 |
-+ ASSERT_RETURN(reader); |
2544 |
-+ |
2545 |
-+ ret = kdbus_conn_info(reader, conn->id, NULL, |
2546 |
-+ _KDBUS_ATTACH_ALL, &offset); |
2547 |
-+ ASSERT_RETURN(ret == 0); |
2548 |
-+ |
2549 |
-+ info = (struct kdbus_info *)(reader->buf + offset); |
2550 |
-+ ASSERT_RETURN(info->id == conn->id); |
2551 |
-+ |
2552 |
-+ /* all attach flags are masked, no metadata */ |
2553 |
-+ KDBUS_ITEM_FOREACH(item, info, items) |
2554 |
-+ i++; |
2555 |
-+ |
2556 |
-+ ASSERT_RETURN(i == 0); |
2557 |
-+ |
2558 |
-+ kdbus_free(reader, offset); |
2559 |
-+ |
2560 |
-+ /* Set the mask to _KDBUS_ATTACH_ANY */ |
2561 |
-+ attach_flags_mask = _KDBUS_ATTACH_ANY; |
2562 |
-+ ret = kdbus_sysfs_set_parameter_mask(env->mask_param_path, |
2563 |
-+ attach_flags_mask); |
2564 |
-+ ASSERT_RETURN(ret == 0); |
2565 |
-+ |
2566 |
-+ ret = kdbus_conn_info(reader, conn->id, NULL, |
2567 |
-+ _KDBUS_ATTACH_ALL, &offset); |
2568 |
-+ ASSERT_RETURN(ret == 0); |
2569 |
-+ |
2570 |
-+ info = (struct kdbus_info *)(reader->buf + offset); |
2571 |
-+ ASSERT_RETURN(info->id == conn->id); |
2572 |
-+ |
2573 |
-+ attach_count = 0; |
2574 |
-+ KDBUS_ITEM_FOREACH(item, info, items) |
2575 |
-+ attach_count += item->type; |
2576 |
-+ |
2577 |
-+ /* |
2578 |
-+ * All flags have been returned except for: |
2579 |
-+ * KDBUS_ITEM_TIMESTAMP and |
2580 |
-+ * KDBUS_ITEM_OWNED_NAME we do not own any name. |
2581 |
-+ */ |
2582 |
-+ ASSERT_RETURN(attach_count == (KDBUS_TEST_ITEMS_SUM - |
2583 |
-+ KDBUS_ITEM_OWNED_NAME - |
2584 |
-+ KDBUS_ITEM_TIMESTAMP)); |
2585 |
-+ |
2586 |
-+ kdbus_free(reader, offset); |
2587 |
-+ |
2588 |
-+ /* Request only OWNED names */ |
2589 |
-+ ret = kdbus_conn_info(reader, conn->id, NULL, |
2590 |
-+ KDBUS_ATTACH_NAMES, &offset); |
2591 |
-+ ASSERT_RETURN(ret == 0); |
2592 |
-+ |
2593 |
-+ info = (struct kdbus_info *)(reader->buf + offset); |
2594 |
-+ ASSERT_RETURN(info->id == conn->id); |
2595 |
-+ |
2596 |
-+ attach_count = 0; |
2597 |
-+ KDBUS_ITEM_FOREACH(item, info, items) |
2598 |
-+ attach_count += item->type; |
2599 |
-+ |
2600 |
-+ /* we should not get any metadata since we do not own names */ |
2601 |
-+ ASSERT_RETURN(attach_count == 0); |
2602 |
-+ |
2603 |
-+ kdbus_free(reader, offset); |
2604 |
-+ |
2605 |
-+ kdbus_conn_free(conn); |
2606 |
-+ kdbus_conn_free(reader); |
2607 |
-+ |
2608 |
-+ return 0; |
2609 |
-+} |
2610 |
-+ |
2611 |
-+/** |
2612 |
-+ * @kdbus_mask_param: kdbus module mask parameter (system-wide) |
2613 |
-+ * @requested_meta: The bus owner metadata that we want |
2614 |
-+ * @expected_items: The returned KDBUS_ITEMS_* sum. Used to |
2615 |
-+ * validate the returned metadata items |
2616 |
-+ */ |
2617 |
-+static int kdbus_cmp_bus_creator_metadata(struct kdbus_test_env *env, |
2618 |
-+ struct kdbus_conn *conn, |
2619 |
-+ uint64_t kdbus_mask_param, |
2620 |
-+ uint64_t requested_meta, |
2621 |
-+ unsigned long expected_items) |
2622 |
-+{ |
2623 |
-+ int ret; |
2624 |
-+ uint64_t offset = 0; |
2625 |
-+ struct kdbus_info *info; |
2626 |
-+ struct kdbus_item *item; |
2627 |
-+ unsigned long attach_count = 0; |
2628 |
-+ |
2629 |
-+ ret = kdbus_sysfs_set_parameter_mask(env->mask_param_path, |
2630 |
-+ kdbus_mask_param); |
2631 |
-+ ASSERT_RETURN(ret == 0); |
2632 |
-+ |
2633 |
-+ ret = kdbus_bus_creator_info(conn, requested_meta, &offset); |
2634 |
-+ ASSERT_RETURN(ret == 0); |
2635 |
-+ |
2636 |
-+ info = (struct kdbus_info *)(conn->buf + offset); |
2637 |
-+ |
2638 |
-+ KDBUS_ITEM_FOREACH(item, info, items) |
2639 |
-+ attach_count += item->type; |
2640 |
-+ |
2641 |
-+ ASSERT_RETURN(attach_count == expected_items); |
2642 |
-+ |
2643 |
-+ ret = kdbus_free(conn, offset); |
2644 |
-+ ASSERT_RETURN(ret == 0); |
2645 |
-+ |
2646 |
-+ return 0; |
2647 |
-+} |
2648 |
-+ |
2649 |
-+static int kdbus_test_bus_creator_info(struct kdbus_test_env *env) |
2650 |
-+{ |
2651 |
-+ int ret; |
2652 |
-+ int control_fd; |
2653 |
-+ char *path; |
2654 |
-+ char *busname; |
2655 |
-+ char buspath[2048]; |
2656 |
-+ char control_path[2048]; |
2657 |
-+ uint64_t attach_flags_mask; |
2658 |
-+ struct kdbus_conn *conn; |
2659 |
-+ unsigned long expected_items = 0; |
2660 |
-+ |
2661 |
-+ snprintf(control_path, sizeof(control_path), |
2662 |
-+ "%s/control", env->root); |
2663 |
-+ |
2664 |
-+ control_fd = open(control_path, O_RDWR); |
2665 |
-+ ASSERT_RETURN(control_fd >= 0); |
2666 |
-+ |
2667 |
-+ busname = unique_name("test-peers-info-bus"); |
2668 |
-+ ASSERT_RETURN(busname); |
2669 |
-+ |
2670 |
-+ /* |
2671 |
-+ * Now the bus allows us to see all its KDBUS_ATTACH_* |
2672 |
-+ * items |
2673 |
-+ */ |
2674 |
-+ ret = kdbus_create_bus(control_fd, busname, 0, |
2675 |
-+ _KDBUS_ATTACH_ALL, &path); |
2676 |
-+ ASSERT_RETURN(ret == 0); |
2677 |
-+ |
2678 |
-+ snprintf(buspath, sizeof(buspath), "%s/%s/bus", env->root, path); |
2679 |
-+ |
2680 |
-+ conn = __kdbus_hello(buspath, 0, 0, 0); |
2681 |
-+ ASSERT_RETURN(conn); |
2682 |
-+ |
2683 |
-+ /* |
2684 |
-+ * Start with a kdbus module mask set to _KDBUS_ATTACH_ANY |
2685 |
-+ */ |
2686 |
-+ attach_flags_mask = _KDBUS_ATTACH_ANY; |
2687 |
-+ |
2688 |
-+ /* |
2689 |
-+ * All flags will be returned except for: |
2690 |
-+ * KDBUS_ITEM_TIMESTAMP |
2691 |
-+ * KDBUS_ITEM_OWNED_NAME |
2692 |
-+ * KDBUS_ITEM_CONN_DESCRIPTION |
2693 |
-+ * |
2694 |
-+ * An extra flags is always returned KDBUS_ITEM_MAKE_NAME |
2695 |
-+ * which contains the bus name |
2696 |
-+ */ |
2697 |
-+ expected_items = KDBUS_TEST_ITEMS_SUM + KDBUS_ITEM_MAKE_NAME; |
2698 |
-+ expected_items -= KDBUS_ITEM_TIMESTAMP + |
2699 |
-+ KDBUS_ITEM_OWNED_NAME + |
2700 |
-+ KDBUS_ITEM_CONN_DESCRIPTION; |
2701 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2702 |
-+ attach_flags_mask, |
2703 |
-+ _KDBUS_ATTACH_ALL, |
2704 |
-+ expected_items); |
2705 |
-+ ASSERT_RETURN(ret == 0); |
2706 |
-+ |
2707 |
-+ /* |
2708 |
-+ * We should have: |
2709 |
-+ * KDBUS_ITEM_PIDS + KDBUS_ITEM_CREDS + KDBUS_ITEM_MAKE_NAME |
2710 |
-+ */ |
2711 |
-+ expected_items = KDBUS_ITEM_PIDS + KDBUS_ITEM_CREDS + |
2712 |
-+ KDBUS_ITEM_MAKE_NAME; |
2713 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2714 |
-+ attach_flags_mask, |
2715 |
-+ KDBUS_ATTACH_PIDS | |
2716 |
-+ KDBUS_ATTACH_CREDS, |
2717 |
-+ expected_items); |
2718 |
-+ ASSERT_RETURN(ret == 0); |
2719 |
-+ |
2720 |
-+ /* KDBUS_ITEM_MAKE_NAME is always returned */ |
2721 |
-+ expected_items = KDBUS_ITEM_MAKE_NAME; |
2722 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2723 |
-+ attach_flags_mask, |
2724 |
-+ 0, expected_items); |
2725 |
-+ ASSERT_RETURN(ret == 0); |
2726 |
-+ |
2727 |
-+ /* |
2728 |
-+ * Restrict kdbus system-wide mask to KDBUS_ATTACH_PIDS |
2729 |
-+ */ |
2730 |
-+ |
2731 |
-+ attach_flags_mask = KDBUS_ATTACH_PIDS; |
2732 |
-+ |
2733 |
-+ /* |
2734 |
-+ * We should have: |
2735 |
-+ * KDBUS_ITEM_PIDS + KDBUS_ITEM_MAKE_NAME |
2736 |
-+ */ |
2737 |
-+ expected_items = KDBUS_ITEM_PIDS + KDBUS_ITEM_MAKE_NAME; |
2738 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2739 |
-+ attach_flags_mask, |
2740 |
-+ _KDBUS_ATTACH_ALL, |
2741 |
-+ expected_items); |
2742 |
-+ ASSERT_RETURN(ret == 0); |
2743 |
-+ |
2744 |
-+ |
2745 |
-+ /* system-wide mask to 0 */ |
2746 |
-+ attach_flags_mask = 0; |
2747 |
-+ |
2748 |
-+ /* we should only see: KDBUS_ITEM_MAKE_NAME */ |
2749 |
-+ expected_items = KDBUS_ITEM_MAKE_NAME; |
2750 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2751 |
-+ attach_flags_mask, |
2752 |
-+ _KDBUS_ATTACH_ALL, |
2753 |
-+ expected_items); |
2754 |
-+ ASSERT_RETURN(ret == 0); |
2755 |
-+ |
2756 |
-+ kdbus_conn_free(conn); |
2757 |
-+ free(path); |
2758 |
-+ free(busname); |
2759 |
-+ close(control_fd); |
2760 |
-+ |
2761 |
-+ |
2762 |
-+ /* |
2763 |
-+ * A new bus that hides all its owner metadata |
2764 |
-+ */ |
2765 |
-+ |
2766 |
-+ control_fd = open(control_path, O_RDWR); |
2767 |
-+ ASSERT_RETURN(control_fd >= 0); |
2768 |
-+ |
2769 |
-+ busname = unique_name("test-peers-info-bus"); |
2770 |
-+ ASSERT_RETURN(busname); |
2771 |
-+ |
2772 |
-+ ret = kdbus_create_bus(control_fd, busname, 0, 0, &path); |
2773 |
-+ ASSERT_RETURN(ret == 0); |
2774 |
-+ |
2775 |
-+ snprintf(buspath, sizeof(buspath), "%s/%s/bus", env->root, path); |
2776 |
-+ |
2777 |
-+ conn = __kdbus_hello(buspath, 0, 0, 0); |
2778 |
-+ ASSERT_RETURN(conn); |
2779 |
-+ |
2780 |
-+ /* |
2781 |
-+ * Start with a kdbus module mask set to _KDBUS_ATTACH_ANY |
2782 |
-+ */ |
2783 |
-+ attach_flags_mask = _KDBUS_ATTACH_ANY; |
2784 |
-+ |
2785 |
-+ /* |
2786 |
-+ * We only get the KDBUS_ITEM_MAKE_NAME |
2787 |
-+ */ |
2788 |
-+ expected_items = KDBUS_ITEM_MAKE_NAME; |
2789 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2790 |
-+ attach_flags_mask, |
2791 |
-+ _KDBUS_ATTACH_ALL, |
2792 |
-+ expected_items); |
2793 |
-+ ASSERT_RETURN(ret == 0); |
2794 |
-+ |
2795 |
-+ /* |
2796 |
-+ * We still get only kdbus_ITEM_MAKE_NAME |
2797 |
-+ */ |
2798 |
-+ attach_flags_mask = 0; |
2799 |
-+ expected_items = KDBUS_ITEM_MAKE_NAME; |
2800 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2801 |
-+ attach_flags_mask, |
2802 |
-+ _KDBUS_ATTACH_ALL, |
2803 |
-+ expected_items); |
2804 |
-+ ASSERT_RETURN(ret == 0); |
2805 |
-+ |
2806 |
-+ kdbus_conn_free(conn); |
2807 |
-+ free(path); |
2808 |
-+ free(busname); |
2809 |
-+ close(control_fd); |
2810 |
-+ |
2811 |
-+ |
2812 |
-+ /* |
2813 |
-+ * A new bus that shows only the PID and CREDS metadata |
2814 |
-+ * of the bus owner. |
2815 |
-+ */ |
2816 |
-+ control_fd = open(control_path, O_RDWR); |
2817 |
-+ ASSERT_RETURN(control_fd >= 0); |
2818 |
-+ |
2819 |
-+ busname = unique_name("test-peers-info-bus"); |
2820 |
-+ ASSERT_RETURN(busname); |
2821 |
-+ |
2822 |
-+ ret = kdbus_create_bus(control_fd, busname, 0, |
2823 |
-+ KDBUS_ATTACH_PIDS| |
2824 |
-+ KDBUS_ATTACH_CREDS, &path); |
2825 |
-+ ASSERT_RETURN(ret == 0); |
2826 |
-+ |
2827 |
-+ snprintf(buspath, sizeof(buspath), "%s/%s/bus", env->root, path); |
2828 |
-+ |
2829 |
-+ conn = __kdbus_hello(buspath, 0, 0, 0); |
2830 |
-+ ASSERT_RETURN(conn); |
2831 |
-+ |
2832 |
-+ /* |
2833 |
-+ * Start with a kdbus module mask set to _KDBUS_ATTACH_ANY |
2834 |
-+ */ |
2835 |
-+ attach_flags_mask = _KDBUS_ATTACH_ANY; |
2836 |
-+ |
2837 |
-+ /* |
2838 |
-+ * We should have: |
2839 |
-+ * KDBUS_ITEM_PIDS + KDBUS_ITEM_CREDS + KDBUS_ITEM_MAKE_NAME |
2840 |
-+ */ |
2841 |
-+ expected_items = KDBUS_ITEM_PIDS + KDBUS_ITEM_CREDS + |
2842 |
-+ KDBUS_ITEM_MAKE_NAME; |
2843 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2844 |
-+ attach_flags_mask, |
2845 |
-+ _KDBUS_ATTACH_ALL, |
2846 |
-+ expected_items); |
2847 |
-+ ASSERT_RETURN(ret == 0); |
2848 |
-+ |
2849 |
-+ expected_items = KDBUS_ITEM_CREDS + KDBUS_ITEM_MAKE_NAME; |
2850 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2851 |
-+ attach_flags_mask, |
2852 |
-+ KDBUS_ATTACH_CREDS, |
2853 |
-+ expected_items); |
2854 |
-+ ASSERT_RETURN(ret == 0); |
2855 |
-+ |
2856 |
-+ /* KDBUS_ITEM_MAKE_NAME is always returned */ |
2857 |
-+ expected_items = KDBUS_ITEM_MAKE_NAME; |
2858 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2859 |
-+ attach_flags_mask, |
2860 |
-+ 0, expected_items); |
2861 |
-+ ASSERT_RETURN(ret == 0); |
2862 |
-+ |
2863 |
-+ /* |
2864 |
-+ * Restrict kdbus system-wide mask to KDBUS_ATTACH_PIDS |
2865 |
-+ */ |
2866 |
-+ |
2867 |
-+ attach_flags_mask = KDBUS_ATTACH_PIDS; |
2868 |
-+ /* |
2869 |
-+ * We should have: |
2870 |
-+ * KDBUS_ITEM_PIDS + KDBUS_ITEM_MAKE_NAME |
2871 |
-+ */ |
2872 |
-+ expected_items = KDBUS_ITEM_PIDS + KDBUS_ITEM_MAKE_NAME; |
2873 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2874 |
-+ attach_flags_mask, |
2875 |
-+ _KDBUS_ATTACH_ALL, |
2876 |
-+ expected_items); |
2877 |
-+ ASSERT_RETURN(ret == 0); |
2878 |
-+ |
2879 |
-+ /* No KDBUS_ATTACH_CREDS */ |
2880 |
-+ expected_items = KDBUS_ITEM_MAKE_NAME; |
2881 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2882 |
-+ attach_flags_mask, |
2883 |
-+ KDBUS_ATTACH_CREDS, |
2884 |
-+ expected_items); |
2885 |
-+ ASSERT_RETURN(ret == 0); |
2886 |
-+ |
2887 |
-+ /* system-wide mask to 0 */ |
2888 |
-+ attach_flags_mask = 0; |
2889 |
-+ |
2890 |
-+ /* we should only see: KDBUS_ITEM_MAKE_NAME */ |
2891 |
-+ expected_items = KDBUS_ITEM_MAKE_NAME; |
2892 |
-+ ret = kdbus_cmp_bus_creator_metadata(env, conn, |
2893 |
-+ attach_flags_mask, |
2894 |
-+ _KDBUS_ATTACH_ALL, |
2895 |
-+ expected_items); |
2896 |
-+ ASSERT_RETURN(ret == 0); |
2897 |
-+ |
2898 |
-+ |
2899 |
-+ kdbus_conn_free(conn); |
2900 |
-+ free(path); |
2901 |
-+ free(busname); |
2902 |
-+ close(control_fd); |
2903 |
-+ |
2904 |
-+ return 0; |
2905 |
-+} |
2906 |
-+ |
2907 |
-+int kdbus_test_attach_flags(struct kdbus_test_env *env) |
2908 |
-+{ |
2909 |
-+ int ret; |
2910 |
-+ uint64_t flags_mask; |
2911 |
-+ uint64_t old_kdbus_flags_mask; |
2912 |
-+ |
2913 |
-+ /* We need CAP_DAC_OVERRIDE to overwrite the kdbus mask */ |
2914 |
-+ ret = test_is_capable(CAP_DAC_OVERRIDE, -1); |
2915 |
-+ ASSERT_RETURN(ret >= 0); |
2916 |
-+ |
2917 |
-+ /* no enough privileges, SKIP test */ |
2918 |
-+ if (!ret) |
2919 |
-+ return TEST_SKIP; |
2920 |
-+ |
2921 |
-+ /* |
2922 |
-+ * We need to be able to write to |
2923 |
-+ * "/sys/module/kdbus/parameters/attach_flags_mask" |
2924 |
-+ * perhaps we are unprvileged/privileged in its userns |
2925 |
-+ */ |
2926 |
-+ ret = access(env->mask_param_path, W_OK); |
2927 |
-+ if (ret < 0) { |
2928 |
-+ kdbus_printf("--- access() '%s' failed: %d (%m)\n", |
2929 |
-+ env->mask_param_path, -errno); |
2930 |
-+ return TEST_SKIP; |
2931 |
-+ } |
2932 |
-+ |
2933 |
-+ ret = kdbus_sysfs_get_parameter_mask(env->mask_param_path, |
2934 |
-+ &old_kdbus_flags_mask); |
2935 |
-+ ASSERT_RETURN(ret == 0); |
2936 |
-+ |
2937 |
-+ /* setup the right KDBUS_TEST_ITEMS_SUM */ |
2938 |
-+ if (!config_auditsyscall_is_enabled()) |
2939 |
-+ KDBUS_TEST_ITEMS_SUM -= KDBUS_ITEM_AUDIT; |
2940 |
-+ |
2941 |
-+ if (!config_cgroups_is_enabled()) |
2942 |
-+ KDBUS_TEST_ITEMS_SUM -= KDBUS_ITEM_CGROUP; |
2943 |
-+ |
2944 |
-+ if (!config_security_is_enabled()) |
2945 |
-+ KDBUS_TEST_ITEMS_SUM -= KDBUS_ITEM_SECLABEL; |
2946 |
-+ |
2947 |
-+ /* |
2948 |
-+ * Test the connection creation attach flags |
2949 |
-+ */ |
2950 |
-+ ret = kdbus_test_peers_creation(env); |
2951 |
-+ /* Restore previous kdbus mask */ |
2952 |
-+ kdbus_sysfs_set_parameter_mask(env->mask_param_path, |
2953 |
-+ old_kdbus_flags_mask); |
2954 |
-+ ASSERT_RETURN(ret == 0); |
2955 |
-+ |
2956 |
-+ /* |
2957 |
-+ * Test the CONN_INFO attach flags |
2958 |
-+ */ |
2959 |
-+ ret = kdbus_test_peers_info(env); |
2960 |
-+ /* Restore previous kdbus mask */ |
2961 |
-+ kdbus_sysfs_set_parameter_mask(env->mask_param_path, |
2962 |
-+ old_kdbus_flags_mask); |
2963 |
-+ ASSERT_RETURN(ret == 0); |
2964 |
-+ |
2965 |
-+ /* |
2966 |
-+ * Test the Bus creator info and its attach flags |
2967 |
-+ */ |
2968 |
-+ ret = kdbus_test_bus_creator_info(env); |
2969 |
-+ /* Restore previous kdbus mask */ |
2970 |
-+ kdbus_sysfs_set_parameter_mask(env->mask_param_path, |
2971 |
-+ old_kdbus_flags_mask); |
2972 |
-+ ASSERT_RETURN(ret == 0); |
2973 |
-+ |
2974 |
-+ ret = kdbus_sysfs_get_parameter_mask(env->mask_param_path, |
2975 |
-+ &flags_mask); |
2976 |
-+ ASSERT_RETURN(ret == 0 && old_kdbus_flags_mask == flags_mask); |
2977 |
-+ |
2978 |
-+ return TEST_OK; |
2979 |
-+} |
2980 |
diff --git a/tools/testing/selftests/kdbus/test-benchmark.c b/tools/testing/selftests/kdbus/test-benchmark.c |
2981 |
new file mode 100644 |
2982 |
index 0000000..8a9744b |
2983 |
@@ -28236,10 +27479,10 @@ index 0000000..71a92d8 |
2984 |
+} |
2985 |
diff --git a/tools/testing/selftests/kdbus/test-connection.c b/tools/testing/selftests/kdbus/test-connection.c |
2986 |
new file mode 100644 |
2987 |
-index 0000000..5c2bf35 |
2988 |
+index 0000000..e7c4866 |
2989 |
--- /dev/null |
2990 |
+++ b/tools/testing/selftests/kdbus/test-connection.c |
2991 |
-@@ -0,0 +1,616 @@ |
2992 |
+@@ -0,0 +1,606 @@ |
2993 |
+#include <stdio.h> |
2994 |
+#include <string.h> |
2995 |
+#include <fcntl.h> |
2996 |
@@ -28427,13 +27670,10 @@ index 0000000..5c2bf35 |
2997 |
+ int ret; |
2998 |
+ unsigned int cnt = 0; |
2999 |
+ uint64_t offset = 0; |
3000 |
-+ uint64_t kdbus_flags_mask; |
3001 |
+ struct kdbus_info *info; |
3002 |
+ struct kdbus_conn *conn; |
3003 |
+ struct kdbus_conn *privileged; |
3004 |
+ const struct kdbus_item *item; |
3005 |
-+ uint64_t valid_flags_set; |
3006 |
-+ uint64_t invalid_flags_set; |
3007 |
+ uint64_t valid_flags = KDBUS_ATTACH_NAMES | |
3008 |
+ KDBUS_ATTACH_CREDS | |
3009 |
+ KDBUS_ATTACH_PIDS | |
3010 |
@@ -28469,13 +27709,6 @@ index 0000000..5c2bf35 |
3011 |
+ .ppid = getppid(), |
3012 |
+ }; |
3013 |
+ |
3014 |
-+ ret = kdbus_sysfs_get_parameter_mask(env->mask_param_path, |
3015 |
-+ &kdbus_flags_mask); |
3016 |
-+ ASSERT_RETURN(ret == 0); |
3017 |
-+ |
3018 |
-+ valid_flags_set = valid_flags & kdbus_flags_mask; |
3019 |
-+ invalid_flags_set = invalid_flags & kdbus_flags_mask; |
3020 |
-+ |
3021 |
+ ret = kdbus_conn_info(env->conn, env->conn->id, NULL, |
3022 |
+ valid_flags, &offset); |
3023 |
+ ASSERT_RETURN(ret == 0); |
3024 |
@@ -28488,7 +27721,7 @@ index 0000000..5c2bf35 |
3025 |
+ ASSERT_RETURN(item == NULL); |
3026 |
+ |
3027 |
+ item = kdbus_get_item(info, KDBUS_ITEM_CONN_DESCRIPTION); |
3028 |
-+ if (valid_flags_set & KDBUS_ATTACH_CONN_DESCRIPTION) { |
3029 |
++ if (valid_flags & KDBUS_ATTACH_CONN_DESCRIPTION) { |
3030 |
+ ASSERT_RETURN(item); |
3031 |
+ } else { |
3032 |
+ ASSERT_RETURN(item == NULL); |
3033 |
@@ -28513,7 +27746,7 @@ index 0000000..5c2bf35 |
3034 |
+ ASSERT_RETURN(item == NULL); |
3035 |
+ |
3036 |
+ cnt = kdbus_count_item(info, KDBUS_ITEM_CREDS); |
3037 |
-+ if (valid_flags_set & KDBUS_ATTACH_CREDS) { |
3038 |
++ if (valid_flags & KDBUS_ATTACH_CREDS) { |
3039 |
+ ASSERT_RETURN(cnt == 1); |
3040 |
+ |
3041 |
+ item = kdbus_get_item(info, KDBUS_ITEM_CREDS); |
3042 |
@@ -28527,7 +27760,7 @@ index 0000000..5c2bf35 |
3043 |
+ } |
3044 |
+ |
3045 |
+ item = kdbus_get_item(info, KDBUS_ITEM_PIDS); |
3046 |
-+ if (valid_flags_set & KDBUS_ATTACH_PIDS) { |
3047 |
++ if (valid_flags & KDBUS_ATTACH_PIDS) { |
3048 |
+ ASSERT_RETURN(item); |
3049 |
+ |
3050 |
+ /* Compare item->pids with cached PIDs */ |
3051 |
@@ -28554,7 +27787,7 @@ index 0000000..5c2bf35 |
3052 |
+ ASSERT_RETURN(info->id == conn->id); |
3053 |
+ |
3054 |
+ item = kdbus_get_item(info, KDBUS_ITEM_OWNED_NAME); |
3055 |
-+ if (valid_flags_set & KDBUS_ATTACH_NAMES) { |
3056 |
++ if (valid_flags & KDBUS_ATTACH_NAMES) { |
3057 |
+ ASSERT_RETURN(item && !strcmp(item->name.name, "com.example.a")); |
3058 |
+ } else { |
3059 |
+ ASSERT_RETURN(item == NULL); |
3060 |
@@ -28582,14 +27815,14 @@ index 0000000..5c2bf35 |
3061 |
+ info = (struct kdbus_info *)(conn->buf + offset); |
3062 |
+ ASSERT_EXIT(info->id == conn->id); |
3063 |
+ |
3064 |
-+ if (valid_flags_set & KDBUS_ATTACH_NAMES) { |
3065 |
++ if (valid_flags & KDBUS_ATTACH_NAMES) { |
3066 |
+ item = kdbus_get_item(info, KDBUS_ITEM_OWNED_NAME); |
3067 |
+ ASSERT_EXIT(item && |
3068 |
+ strcmp(item->name.name, |
3069 |
+ "com.example.a") == 0); |
3070 |
+ } |
3071 |
+ |
3072 |
-+ if (valid_flags_set & KDBUS_ATTACH_CREDS) { |
3073 |
++ if (valid_flags & KDBUS_ATTACH_CREDS) { |
3074 |
+ item = kdbus_get_item(info, KDBUS_ITEM_CREDS); |
3075 |
+ ASSERT_EXIT(item); |
3076 |
+ |
3077 |
@@ -28598,7 +27831,7 @@ index 0000000..5c2bf35 |
3078 |
+ sizeof(struct kdbus_creds)) == 0); |
3079 |
+ } |
3080 |
+ |
3081 |
-+ if (valid_flags_set & KDBUS_ATTACH_PIDS) { |
3082 |
++ if (valid_flags & KDBUS_ATTACH_PIDS) { |
3083 |
+ item = kdbus_get_item(info, KDBUS_ITEM_PIDS); |
3084 |
+ ASSERT_EXIT(item); |
3085 |
+ |
3086 |
@@ -28627,7 +27860,7 @@ index 0000000..5c2bf35 |
3087 |
+ * it points to the cached creds. |
3088 |
+ */ |
3089 |
+ cnt = kdbus_count_item(info, KDBUS_ITEM_CREDS); |
3090 |
-+ if (invalid_flags_set & KDBUS_ATTACH_CREDS) { |
3091 |
++ if (invalid_flags & KDBUS_ATTACH_CREDS) { |
3092 |
+ ASSERT_EXIT(cnt == 1); |
3093 |
+ |
3094 |
+ item = kdbus_get_item(info, KDBUS_ITEM_CREDS); |
3095 |
@@ -28640,7 +27873,7 @@ index 0000000..5c2bf35 |
3096 |
+ ASSERT_EXIT(cnt == 0); |
3097 |
+ } |
3098 |
+ |
3099 |
-+ if (invalid_flags_set & KDBUS_ATTACH_PIDS) { |
3100 |
++ if (invalid_flags & KDBUS_ATTACH_PIDS) { |
3101 |
+ cnt = kdbus_count_item(info, KDBUS_ITEM_PIDS); |
3102 |
+ ASSERT_EXIT(cnt == 1); |
3103 |
+ |
3104 |
@@ -28653,14 +27886,14 @@ index 0000000..5c2bf35 |
3105 |
+ } |
3106 |
+ |
3107 |
+ cnt = kdbus_count_item(info, KDBUS_ITEM_CGROUP); |
3108 |
-+ if (invalid_flags_set & KDBUS_ATTACH_CGROUP) { |
3109 |
++ if (invalid_flags & KDBUS_ATTACH_CGROUP) { |
3110 |
+ ASSERT_EXIT(cnt == 1); |
3111 |
+ } else { |
3112 |
+ ASSERT_EXIT(cnt == 0); |
3113 |
+ } |
3114 |
+ |
3115 |
+ cnt = kdbus_count_item(info, KDBUS_ITEM_CAPS); |
3116 |
-+ if (invalid_flags_set & KDBUS_ATTACH_CAPS) { |
3117 |
++ if (invalid_flags & KDBUS_ATTACH_CAPS) { |
3118 |
+ ASSERT_EXIT(cnt == 1); |
3119 |
+ } else { |
3120 |
+ ASSERT_EXIT(cnt == 0); |
3121 |
@@ -28684,7 +27917,7 @@ index 0000000..5c2bf35 |
3122 |
+ ASSERT_RETURN(info->id == conn->id); |
3123 |
+ |
3124 |
+ cnt = kdbus_count_item(info, KDBUS_ITEM_OWNED_NAME); |
3125 |
-+ if (valid_flags_set & KDBUS_ATTACH_NAMES) { |
3126 |
++ if (valid_flags & KDBUS_ATTACH_NAMES) { |
3127 |
+ ASSERT_RETURN(cnt == 2); |
3128 |
+ } else { |
3129 |
+ ASSERT_RETURN(cnt == 0); |
3130 |
@@ -28929,10 +28162,10 @@ index 0000000..8bc2386 |
3131 |
+} |
3132 |
diff --git a/tools/testing/selftests/kdbus/test-endpoint.c b/tools/testing/selftests/kdbus/test-endpoint.c |
3133 |
new file mode 100644 |
3134 |
-index 0000000..dcc6ab9 |
3135 |
+index 0000000..34a7be4 |
3136 |
--- /dev/null |
3137 |
+++ b/tools/testing/selftests/kdbus/test-endpoint.c |
3138 |
-@@ -0,0 +1,341 @@ |
3139 |
+@@ -0,0 +1,352 @@ |
3140 |
+#include <stdio.h> |
3141 |
+#include <string.h> |
3142 |
+#include <fcntl.h> |
3143 |
@@ -29190,6 +28423,13 @@ index 0000000..dcc6ab9 |
3144 |
+ ep_conn = kdbus_hello(ep, 0, NULL, 0); |
3145 |
+ ASSERT_RETURN(ep_conn); |
3146 |
+ |
3147 |
++ /* Check that the reader got the IdAdd notification */ |
3148 |
++ ret = kdbus_msg_recv(reader, &msg, NULL); |
3149 |
++ ASSERT_RETURN(ret == 0); |
3150 |
++ ASSERT_RETURN(msg->items[0].type == KDBUS_ITEM_ID_ADD); |
3151 |
++ ASSERT_RETURN(msg->items[0].id_change.id == ep_conn->id); |
3152 |
++ kdbus_msg_free(msg); |
3153 |
++ |
3154 |
+ /* |
3155 |
+ * Add a name add match on the endpoint connection, acquire name from |
3156 |
+ * the unfiltered connection, and make sure the filtered connection |
3157 |
@@ -29218,7 +28458,7 @@ index 0000000..dcc6ab9 |
3158 |
+ ret = kdbus_conn_info(ep_conn, 0x0fffffffffffffffULL, NULL, 0, NULL); |
3159 |
+ ASSERT_RETURN(ret == -ENXIO); |
3160 |
+ |
3161 |
-+ /* Check that the reader did not receive anything */ |
3162 |
++ /* Check that the reader did not receive the name notification */ |
3163 |
+ ret = kdbus_msg_recv(reader, NULL, NULL); |
3164 |
+ ASSERT_RETURN(ret == -EAGAIN); |
3165 |
+ |
3166 |
@@ -29230,6 +28470,10 @@ index 0000000..dcc6ab9 |
3167 |
+ ret = kdbus_name_release(env->conn, name); |
3168 |
+ ASSERT_RETURN(ret == 0); |
3169 |
+ |
3170 |
++ /* Check that the reader did not receive the name notification */ |
3171 |
++ ret = kdbus_msg_recv(reader, NULL, NULL); |
3172 |
++ ASSERT_RETURN(ret == -EAGAIN); |
3173 |
++ |
3174 |
+ ret = update_endpoint(ep_fd, name); |
3175 |
+ ASSERT_RETURN(ret == 0); |
3176 |
+ |
3177 |
@@ -31325,10 +30569,10 @@ index 0000000..f1615da |
3178 |
+} |
3179 |
diff --git a/tools/testing/selftests/kdbus/test-metadata-ns.c b/tools/testing/selftests/kdbus/test-metadata-ns.c |
3180 |
new file mode 100644 |
3181 |
-index 0000000..2cb1d4d |
3182 |
+index 0000000..ccdfae0 |
3183 |
--- /dev/null |
3184 |
+++ b/tools/testing/selftests/kdbus/test-metadata-ns.c |
3185 |
-@@ -0,0 +1,506 @@ |
3186 |
+@@ -0,0 +1,503 @@ |
3187 |
+/* |
3188 |
+ * Test metadata in new namespaces. Even if our tests can run |
3189 |
+ * in a namespaced setup, this test is necessary so we can inspect |
3190 |
@@ -31612,16 +30856,13 @@ index 0000000..2cb1d4d |
3191 |
+static int kdbus_clone_userns_test(const char *bus, |
3192 |
+ struct kdbus_conn *conn) |
3193 |
+{ |
3194 |
-+ int ret; |
3195 |
-+ int status; |
3196 |
-+ int efd = -1; |
3197 |
++ int ret, status, efd; |
3198 |
+ pid_t pid, ppid; |
3199 |
-+ uint64_t unpriv_conn_id = 0; |
3200 |
-+ uint64_t userns_conn_id = 0; |
3201 |
++ uint64_t unpriv_conn_id, userns_conn_id; |
3202 |
+ struct kdbus_msg *msg; |
3203 |
+ const struct kdbus_item *item; |
3204 |
+ struct kdbus_pids expected_pids; |
3205 |
-+ struct kdbus_conn *monitor = NULL; |
3206 |
++ struct kdbus_conn *monitor; |
3207 |
+ |
3208 |
+ kdbus_printf("STARTING TEST 'metadata-ns'.\n"); |
3209 |
+ |