item: add struct kdbus_item_header
authorDaniel Mack <daniel@zonque.org>
Wed, 17 Dec 2014 09:52:38 +0000 (10:52 +0100)
committerDaniel Mack <daniel@zonque.org>
Wed, 17 Dec 2014 09:56:13 +0000 (10:56 +0100)
Never allocate a kdbus_item object on the stack. It's only there as
memory layout definition and can, in theory, grow to arbitrary sizes.

Instead, add a struct kdbus_item_header to item.h that just describes
the header of an item, which is all we care for when manually
assembling an item from kernel space.

Signed-off-by: Daniel Mack <daniel@zonque.org>
bus.c
item.h

diff --git a/bus.c b/bus.c
index ff1790443210f6d90a7e1610a7570e0a2d3260c6..a0b03b9b0d947023ed66397bfef27c4e55efc27b 100644 (file)
--- a/bus.c
+++ b/bus.c
@@ -504,9 +504,9 @@ int kdbus_cmd_bus_creator_info(struct kdbus_conn *conn,
 {
        struct kdbus_bus *bus = conn->ep->bus;
        struct kdbus_pool_slice *slice = NULL;
+       struct kdbus_item_header item_hdr;
        struct kdbus_item *meta_items;
        struct kdbus_info info = {};
-       struct kdbus_item item = {};
        size_t meta_size, name_len;
        struct kvec kvec[5];
        u64 attach_flags;
@@ -525,11 +525,11 @@ int kdbus_cmd_bus_creator_info(struct kdbus_conn *conn,
        if (IS_ERR(meta_items))
                return PTR_ERR(meta_items);
 
-       item.type = KDBUS_ITEM_MAKE_NAME;
-       item.size = KDBUS_ITEM_HEADER_SIZE + name_len;
+       item_hdr.type = KDBUS_ITEM_MAKE_NAME;
+       item_hdr.size = KDBUS_ITEM_HEADER_SIZE + name_len;
 
        kdbus_kvec_set(&kvec[cnt++], &info, sizeof(info), &info.size);
-       kdbus_kvec_set(&kvec[cnt++], &item, KDBUS_ITEM_HEADER_SIZE, &info.size);
+       kdbus_kvec_set(&kvec[cnt++], &item_hdr, sizeof(item_hdr), &info.size);
        kdbus_kvec_set(&kvec[cnt++], bus->node.name, name_len, &info.size);
        cnt += !!kdbus_kvec_pad(&kvec[cnt], &info.size);
 
diff --git a/item.h b/item.h
index 83d9f9c8b81632eba263768a69c500a5dde8f95e..592711d91a20668bf3205e170bff812ec4c7e547 100644 (file)
--- a/item.h
+++ b/item.h
               ((u8 *)(_i) >= (u8 *)(_is));                             \
             _i = KDBUS_ITEM_NEXT(_i))
 
+/**
+ * struct kdbus_item_header - Describes the fix part of an item
+ * @size:      The total size of the item
+ * @type:      The item type, one of KDBUS_ITEM_*
+ */
+struct kdbus_item_header {
+       u64 size;
+       u64 type;
+};
+
 int kdbus_item_validate_name(const struct kdbus_item *item);
 int kdbus_items_validate(const struct kdbus_item *items, size_t items_size);
 struct kdbus_item *kdbus_items_get(const struct kdbus_item *items,