kdbus: do not append the same connection to the queue twice
authorPaul Osmialowski <p.osmialowsk@samsung.com>
Thu, 18 Jun 2015 15:29:11 +0000 (17:29 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 14 Dec 2016 04:48:46 +0000 (13:48 +0900)
As it was discussed on systemd ML [1], the same connection should be
queued up only once for a given well-known name.

[1] http://lists.freedesktop.org/archives/systemd-devel/2015-April/030494.html

This commit fixes following issue:

[  243.364270] ------------[ cut here ]------------
[  243.364352] WARNING: CPU: 1 PID: 223 at ../ipc/kdbus/names.c:137 kdbus_name_entry_replace_owner+0x88/0x8c()
[  243.364408] Modules linked in:
[  243.364474] CPU: 1 PID: 223 Comm: kdbus-test Not tainted 4.0.0+ #1
[  243.364526] Hardware name: Foundation-v8A (DT)
[  243.364569] Call trace:
[  243.364639] [<ffff800000089d38>] dump_backtrace+0x0/0x12c
[  243.364718] [<ffff800000089e74>] show_stack+0x10/0x1c
[  243.364798] [<ffff8000006642f4>] dump_stack+0x74/0x98
[  243.364874] [<ffff8000000b282c>] warn_slowpath_common+0x98/0xd0
[  243.364951] [<ffff8000000b2928>] warn_slowpath_null+0x14/0x20
[  243.365026] [<ffff8000003cf7a4>] kdbus_name_entry_replace_owner+0x84/0x8c
[  243.365105] [<ffff8000003cf7e0>] kdbus_name_release_unlocked.isra.5+0x34/0x170
[  243.365183] [<ffff8000003d0554>] kdbus_cmd_name_release+0x1b8/0x1c8
[  243.365270] [<ffff8000003cbd28>] kdbus_handle_ioctl+0x5e0/0x690
[  243.365347] [<ffff8000001b3520>] do_vfs_ioctl+0x31c/0x5c0
[  243.365423] [<ffff8000001b3844>] SyS_ioctl+0x80/0x98
[  243.365473] ---[ end trace 5bf3630c98408d38 ]---

Signed-off-by: Lukasz Skalski <l.skalski@samsung.com>
Signed-off-by: Paul Osmialowski <p.osmialowsk@samsung.com>
ipc/kdbus/names.c

index 657008e..df99e4d 100644 (file)
@@ -353,10 +353,24 @@ int kdbus_name_acquire(struct kdbus_name_registry *reg,
        } else if (flags & KDBUS_NAME_QUEUE) {
                /* add to waiting-queue of the name */
 
-               ret = kdbus_name_pending_new(e, conn, flags);
-               if (ret >= 0)
-                       /* tell the caller that we queued it */
-                       rflags |= KDBUS_NAME_IN_QUEUE;
+               struct kdbus_name_pending *p;
+               bool in_queue = false;
+
+               list_for_each_entry(p, &e->queue, name_entry) {
+                       if (p->conn == conn) {
+                               /* connection is already queued */
+                               rflags |= KDBUS_NAME_IN_QUEUE;
+                               in_queue = true;
+                               break;
+                       }
+               }
+
+               if (!in_queue) {
+                       ret = kdbus_name_pending_new(e, conn, flags);
+                       if (ret >= 0)
+                               /* tell the caller that we queued it */
+                               rflags |= KDBUS_NAME_IN_QUEUE;
+               }
        } else {
                /* the name is busy, return a failure */
                ret = -EEXIST;