From 7d1991ddab8639e363ee5297836bf66a800cb6ed Mon Sep 17 00:00:00 2001 From: Djalal Harouni Date: Wed, 7 Jan 2015 14:33:29 +0100 Subject: [PATCH] message: messages that expect a reply must provide a valid tracking cookie Signed-off-by: Djalal Harouni --- kdbus.txt | 4 ++-- message.c | 4 ++-- test/test-message.c | 5 +++++ test/test-timeout.c | 10 ++++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/kdbus.txt b/kdbus.txt index 8e057f5..e5171e2 100644 --- a/kdbus.txt +++ b/kdbus.txt @@ -1934,8 +1934,8 @@ For KDBUS_CMD_SEND: file descriptors are either kdbus handles or unix domain sockets. Both are currently unsupported -EINVAL The submitted payload type is KDBUS_PAYLOAD_KERNEL, - KDBUS_MSG_EXPECT_REPLY was set without a timeout value, - KDBUS_MSG_SYNC_REPLY was set without + KDBUS_MSG_EXPECT_REPLY was set without timeout or cookie + values, KDBUS_MSG_SYNC_REPLY was set without KDBUS_MSG_EXPECT_REPLY, an invalid item was supplied, src_id was != 0 and different from the current connection's ID, a supplied memfd had a size of 0, a string was not properly diff --git a/message.c b/message.c index eba4303..229aa6b 100644 --- a/message.c +++ b/message.c @@ -549,8 +549,8 @@ struct kdbus_kmsg *kdbus_kmsg_new_from_cmd(struct kdbus_conn *conn, } if (m->msg.flags & KDBUS_MSG_EXPECT_REPLY) { - /* requests for replies need a timeout */ - if (m->msg.timeout_ns == 0) { + /* requests for replies need timeout and cookie */ + if (m->msg.timeout_ns == 0 || m->msg.cookie == 0) { ret = -EINVAL; goto exit_free; } diff --git a/test/test-message.c b/test/test-message.c index f792c61..4728b64 100644 --- a/test/test-message.c +++ b/test/test-message.c @@ -76,6 +76,11 @@ int kdbus_test_message_basic(struct kdbus_test_env *env) kdbus_msg_free(msg); + /* Msgs that expect a reply must have timeout and cookie */ + ret = kdbus_msg_send(sender, NULL, 0, KDBUS_MSG_EXPECT_REPLY, + 0, 0, conn->id); + ASSERT_RETURN(ret == -EINVAL); + ret = kdbus_free(conn, offset); ASSERT_RETURN(ret == 0); diff --git a/test/test-timeout.c b/test/test-timeout.c index 5797519..5558b0b 100644 --- a/test/test-timeout.c +++ b/test/test-timeout.c @@ -51,6 +51,7 @@ int kdbus_test_timeout(struct kdbus_test_env *env) struct pollfd fd; int ret, i, n_msgs = 4; uint64_t expected = 0; + uint64_t cookie = 0xdeadbeef; conn_a = kdbus_hello(env->buspath, 0, NULL, 0); conn_b = kdbus_hello(env->buspath, 0, NULL, 0); @@ -62,13 +63,14 @@ int kdbus_test_timeout(struct kdbus_test_env *env) * send messages that expect a reply (within 100 msec), * but never answer it. */ - for (i = 0; i < n_msgs; i++) { - kdbus_printf("Sending message with cookie %d ...\n", i); - ASSERT_RETURN(kdbus_msg_send(conn_b, NULL, i, + for (i = 0; i < n_msgs; i++, cookie++) { + kdbus_printf("Sending message with cookie %llu ...\n", + (unsigned long long)cookie); + ASSERT_RETURN(kdbus_msg_send(conn_b, NULL, cookie, KDBUS_MSG_EXPECT_REPLY, (i + 1) * 100ULL * 1000000ULL, 0, conn_a->id) == 0); - expected |= 1ULL << i; + expected |= 1ULL << cookie; } for (;;) { -- 2.34.1