From a3ef25568dc0d5dc9b15c6e4c269f92bdbe3eff2 Mon Sep 17 00:00:00 2001 From: Paul Osmialowski Date: Thu, 18 Jun 2015 17:29:11 +0200 Subject: [PATCH] kdbus: do not append the same connection to the queue twice 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] [] dump_backtrace+0x0/0x12c [ 243.364718] [] show_stack+0x10/0x1c [ 243.364798] [] dump_stack+0x74/0x98 [ 243.364874] [] warn_slowpath_common+0x98/0xd0 [ 243.364951] [] warn_slowpath_null+0x14/0x20 [ 243.365026] [] kdbus_name_entry_replace_owner+0x84/0x8c [ 243.365105] [] kdbus_name_release_unlocked.isra.5+0x34/0x170 [ 243.365183] [] kdbus_cmd_name_release+0x1b8/0x1c8 [ 243.365270] [] kdbus_handle_ioctl+0x5e0/0x690 [ 243.365347] [] do_vfs_ioctl+0x31c/0x5c0 [ 243.365423] [] SyS_ioctl+0x80/0x98 [ 243.365473] ---[ end trace 5bf3630c98408d38 ]--- Change-Id: I469242f51c9b15e1701fc80962833e61575f360c Signed-off-by: Lukasz Skalski Signed-off-by: Paul Osmialowski --- ipc/kdbus/names.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ipc/kdbus/names.c b/ipc/kdbus/names.c index 657008e1bb37..df99e4df815b 100644 --- a/ipc/kdbus/names.c +++ b/ipc/kdbus/names.c @@ -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; -- 2.34.1