connection: pin the subjective cred for KDBUS_POLICY_OWN

Make sure that the credentials of the connection at creation time will
last so the kdbus_policy_check_own_access() will work as expected.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
domain: rework kdbus_domain_new() error path to fix a BUG_ON()

Currently just running: test/test-kdbus will trigger the BUG_ON()
appended at the bottom.

This is due to the test in check_domain_make() where we try to register
the same domain twice line: 297, hence kdbus_domain_new() fails with
-EEXIST at line domain.c:289

Later on error path we clear the non-finalized domain:
kdbus_domain_unref()
 => __kdbus_domain_free()
   => BUG_ON(!domain->disconnected)

After a closer look, it seems we will hit this BUG_ON() on every time
kdbus_domain_new() fails. domain was not finalized so
kdbus_domain_disconnect() is never called, and domain->disconnect can't
be true.

To fix this, as suggested by Kay we remove the kdbus_domain_unref()
call and clean up things manually.

While we are it, make sure we unregister the chrdev and restore the idr
slot on error paths too.

[16254.397574] ------------[ cut here ]------------
[16254.398272] kernel BUG at /home/tixxdz/code/d-bus/domain.c:163!
[16254.398524] invalid opcode: 0000 [#1] SMP
[16254.398524] Modules linked in: kdbus(OE) ip6t_rpfilter bnep bluetooth ip6t_REJECT cfg80211 rfkill xt_conntrack ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw ppdev serio_raw 8139too i2c_piix4 parport_pc parport microcode bochs_drm drm_kms_helper ttm drm 8139cp i2c_core mii ata_generic pata_acpi
[16254.398524] CPU: 3 PID: 30638 Comm: test-kdbus Tainted: G	OE 3.15.0-0.rc5.git2.9.fc21.x86_64 #1
[16254.398524] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
[16254.398524] task: ffff88005c11cd40 ti: ffff880005958000 task.ti: ffff880005958000
[16254.398524] RIP: 0010:[<ffffffffa031939b>]  [<ffffffffa031939b>] __kdbus_domain_free+0x9b/0xa0 [kdbus]
[16254.398524] RSP: 0018:ffff880005959de8  EFLAGS: 00010246
[16254.398524] RAX: ffff88005c11cd40 RBX: ffff880046743400 RCX: 0000000000008b40
[16254.398524] RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff880046743400
[16254.398524] RBP: ffff880005959df0 R08: 0000000000000000 R09: 0000000000000000
[16254.398524] R10: 0000000000000000 R11: 0000000000000000 R12: ffff8800466fa800
[16254.398524] R13: 00000000ffffffef R14: ffff8800466fa960 R15: ffff880046741400
[16254.398524] FS:  00007fa151358740(0000) GS:ffff88005dc00000(0000) knlGS:0000000000000000
[16254.398524] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[16254.398524] CR2: 00007fa13db78048 CR3: 0000000005a25000 CR4: 00000000000006e0
[16254.398524] Stack:
[16254.398524]  ffff880046743400 ffff880005959e40 ffffffffa03199e8 ffff880005959e68
[16254.398524]  ffff8800466fa8a8 01ffffffa031c0a0 ffff880005a58540 00000000ffff0180
[16254.398524]  ffff880005a589c0 0000000000000005 00007fff3dc96990 ffff880005959ec0
[16254.398524] Call Trace:
[16254.398524]  [<ffffffffa03199e8>] kdbus_domain_new+0x218/0x4c0 [kdbus]
[16254.398524]  [<ffffffffa0315546>] kdbus_handle_ioctl+0xb46/0xbd0 [kdbus]
[16254.398524]  [<ffffffff81360c21>] ? inode_has_perm.isra.47+0x51/0x90
[16254.398524]  [<ffffffff81251540>] do_vfs_ioctl+0x2f0/0x520
[16254.398524]  [<ffffffff812517f1>] SyS_ioctl+0x81/0xa0
[16254.398524]  [<ffffffff817fc769>] system_call_fastpath+0x16/0x1b
[16254.398524] Code: 8b 7b 08 e8 98 ca ef e0 48 8b 7b 10 e8 8f ca ef e0 48 89 df e8 87 ca ef e0 5b 5d c3 0f 1f 40 00 e8 6b ff ff ff eb d8 0f 0b 0f 0b <0f> 0b 0f 1f 00 0f 1f 44 00 00 55 48 89 e5 53 8b 47 28 48 89 fb
[16254.398524] RIP  [<ffffffffa031939b>] __kdbus_domain_free+0x9b/0xa0 [kdbus]
[16254.437815] ---[ end trace bb9a1036dec78fcc ]---

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
policy: clean up headers and code documentation

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
Merge remote-tracking branch 'kdbus/master' into 3.14/kdbus
connection: fix cpu stall by checking kdbus item alignment

Fix the following stall triggered by a policy holder hello:
call test/kdbus-util.c:kdbus_hello_registrar() and pass
KDBUS_HELLO_POLICY_HOLDER as a flag.

While we are it make sure that kdbus_cmd_conn_update() also checks for
proper 8 byte alignment.

[  142.731011] INFO: rcu_sched self-detected stall on CPU { 3}  (t=65000 jiffies g=3085 c=3084 q=4316)
[  142.731011] sending NMI to all CPUs:
[  142.731011] NMI backtrace for cpu 3
[  142.731011] CPU: 3 PID: 1352 Comm: test-kdbus-poli Tainted: G OE 3.15.0-0.rc8.git4.1.fc21.x86_64 #1
[  142.731011] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
[  142.731011] task: ffff88005a2719d0 ti: ffff88004587c000 task.ti: ffff88004587c000
[  142.731011] RIP: 0010:[<ffffffff81055a12>]  [<ffffffff81055a12>] flat_send_IPI_all+0x92/0xd0
[  142.731011] RSP: 0018:ffff88005dc03dc0  EFLAGS: 00010006
[  142.731011] RAX: 0000000000000000 RBX: 0000000000000c00 RCX: 0000000000000000
[  142.731011] RDX: 0000000000000c00 RSI: 0000000000000000 RDI: 0000000000000300
[  142.731011] RBP: ffff88005dc03dd8 R08: 0000000000000001 R09: 0000000000000001
[  142.731011] R10: ffffffff81e5d720 R11: 0000000000000001 R12: 0000000000000046
[  142.731011] R13: 000000000000000f R14: ffffffff81e86880 R15: 0000000000000003
[  142.731011] FS:  00007f4b9d727740(0000) GS:ffff88005dc00000(0000) knlGS:0000000000000000
[  142.731011] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[  142.731011] CR2: 0000000000401312 CR3: 000000005b66f000 CR4: 00000000000006e0
[  142.731011] Stack:
[  142.731011]  0000000000002710 ffffffff81e86880 ffffffff81fa3e40 ffff88005dc03df0
[  142.731011]  ffffffff81050654 ffff88005ddcf000 ffff88005dc03e48 ffffffff8111a194
[  142.731011]  0000000000000000 7fffffffffffffff 0000000000000046 00000000000010dc
[  142.731011] Call Trace:
[  142.731011]  <IRQ>

[  142.731011]  [<ffffffff81050654>] arch_trigger_all_cpu_backtrace+0x64/0xa0
[  142.731011]  [<ffffffff8111a194>] rcu_check_callbacks+0x584/0x850
[  142.731011]  [<ffffffff810a74a7>] update_process_times+0x47/0x70
[  142.731011]  [<ffffffff81126765>] tick_sched_handle.isra.19+0x25/0x60
[  142.731011]  [<ffffffff81127061>] tick_sched_timer+0x41/0x60
[  142.731011]  [<ffffffff810c7446>] __run_hrtimer+0x86/0x460
[  142.731011]  [<ffffffff81127020>] ? tick_sched_do_timer+0x40/0x40
[  142.731011]  [<ffffffff810c809f>] hrtimer_interrupt+0x10f/0x260
[  142.731011]  [<ffffffff8104e55a>] local_apic_timer_interrupt+0x3a/0x60
[  142.731011]  [<ffffffff8180089f>] smp_apic_timer_interrupt+0x3f/0x50
[  142.731011]  [<ffffffff817ff1f2>] apic_timer_interrupt+0x72/0x80
[  142.731011]  <EOI>

[  142.731011]  [<ffffffff817f42b3>] ? retint_restore_args+0x13/0x13
[  142.731011]  [<ffffffffa02a666b>] ? kdbus_conn_new+0x25b/0xf20 [kdbus]
[  142.731011]  [<ffffffffa02a6741>] ? kdbus_conn_new+0x331/0xf20 [kdbus]
[  142.731011]  [<ffffffffa02a8161>] kdbus_handle_ioctl+0x221/0xad0 [kdbus]
[  142.731011]  [<ffffffff81361a31>] ? inode_has_perm.isra.47+0x51/0x90
[  142.731011]  [<ffffffff81251f60>] do_vfs_ioctl+0x2f0/0x520
[  142.731011]  [<ffffffff81252211>] SyS_ioctl+0x81/0xa0
[  142.731011]  [<ffffffff817fe4e9>] system_call_fastpath+0x16/0x1b

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
kdbus-test: fix kdbus item alignment in kdbus_hello_registrar()

Currently running the test-kdbus-activator test will fail with -EINVAL

To fix this, remove the redundant offsetof() macros since it is already
handled. The KDBUS_ITEM_SIZE() will expand into KDBUS_ITEM_HEADER_SIZE()
which expands into an offsetof() one.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
Merge remote-tracking branch 'kdbus/master' into 3.14/kdbus