From 90e2395d6c78b7e99f51587747b7db7acab23903 Mon Sep 17 00:00:00 2001 From: wangchen Date: Tue, 13 Aug 2024 19:49:33 +0800 Subject: [PATCH] netlink:add tls cleanup protection to protect waitsem in netlink_get_response Signed-off-by: wangchen --- net/netlink/netlink.h | 2 +- net/netlink/netlink_conn.c | 3 +++ net/netlink/netlink_notifier.c | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h index ccb88d5663..b1ebf8e0b7 100644 --- a/net/netlink/netlink.h +++ b/net/netlink/netlink.h @@ -385,7 +385,7 @@ int netlink_notifier_setup(worker_t worker, FAR struct netlink_conn_s *conn, * ****************************************************************************/ -void netlink_notifier_teardown(FAR struct netlink_conn_s *conn); +void netlink_notifier_teardown(FAR void *conn); /**************************************************************************** * Name: netlink_notifier_signal diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c index 0bea2a5021..0a1b5f71da 100644 --- a/net/netlink/netlink_conn.c +++ b/net/netlink/netlink_conn.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "utils/utils.h" #include "netlink/netlink.h" @@ -533,7 +534,9 @@ int netlink_get_response(FAR struct netlink_conn_s *conn, { /* Wait for a response to be queued */ + tls_cleanup_push(tls_get_info(), netlink_notifier_teardown, conn); ret = net_sem_wait(&waitsem); + tls_cleanup_pop(tls_get_info(), 0); } /* Clean-up the semaphore */ diff --git a/net/netlink/netlink_notifier.c b/net/netlink/netlink_notifier.c index 9b85ecf814..d8a0fc884e 100644 --- a/net/netlink/netlink_notifier.c +++ b/net/netlink/netlink_notifier.c @@ -97,8 +97,9 @@ int netlink_notifier_setup(worker_t worker, FAR struct netlink_conn_s *conn, * ****************************************************************************/ -void netlink_notifier_teardown(FAR struct netlink_conn_s *conn) +void netlink_notifier_teardown(FAR void *arg) { + FAR struct netlink_conn_s *conn = arg; DEBUGASSERT(conn != NULL); /* This is just a simple wrapper around work_notifier_teardown(). */