0002-wispr-Add-reference-counter-to-portal-context.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. From 72343929836de80727a27d6744c869dff045757c Mon Sep 17 00:00:00 2001
  2. From: Daniel Wagner <wagi@monom.org>
  3. Date: Tue, 5 Jul 2022 08:32:12 +0200
  4. Subject: wispr: Add reference counter to portal context
  5. Track the connman_wispr_portal_context live time via a
  6. refcounter. This only adds the infrastructure to do proper reference
  7. counting.
  8. Fixes: CVE-2022-32293
  9. [Retrieved from:
  10. https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=72343929836de80727a27d6744c869dff045757c]
  11. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  12. ---
  13. src/wispr.c | 52 ++++++++++++++++++++++++++++++++++++++++++----------
  14. 1 file changed, 42 insertions(+), 10 deletions(-)
  15. diff --git a/src/wispr.c b/src/wispr.c
  16. index a07896ca..bde7e63b 100644
  17. --- a/src/wispr.c
  18. +++ b/src/wispr.c
  19. @@ -56,6 +56,7 @@ struct wispr_route {
  20. };
  21. struct connman_wispr_portal_context {
  22. + int refcount;
  23. struct connman_service *service;
  24. enum connman_ipconfig_type type;
  25. struct connman_wispr_portal *wispr_portal;
  26. @@ -97,6 +98,11 @@ static char *online_check_ipv4_url = NULL;
  27. static char *online_check_ipv6_url = NULL;
  28. static bool enable_online_to_ready_transition = false;
  29. +#define wispr_portal_context_ref(wp_context) \
  30. + wispr_portal_context_ref_debug(wp_context, __FILE__, __LINE__, __func__)
  31. +#define wispr_portal_context_unref(wp_context) \
  32. + wispr_portal_context_unref_debug(wp_context, __FILE__, __LINE__, __func__)
  33. +
  34. static void connman_wispr_message_init(struct connman_wispr_message *msg)
  35. {
  36. DBG("");
  37. @@ -162,9 +168,6 @@ static void free_connman_wispr_portal_context(
  38. {
  39. DBG("context %p", wp_context);
  40. - if (!wp_context)
  41. - return;
  42. -
  43. if (wp_context->wispr_portal) {
  44. if (wp_context->wispr_portal->ipv4_context == wp_context)
  45. wp_context->wispr_portal->ipv4_context = NULL;
  46. @@ -201,9 +204,38 @@ static void free_connman_wispr_portal_context(
  47. g_free(wp_context);
  48. }
  49. +static struct connman_wispr_portal_context *
  50. +wispr_portal_context_ref_debug(struct connman_wispr_portal_context *wp_context,
  51. + const char *file, int line, const char *caller)
  52. +{
  53. + DBG("%p ref %d by %s:%d:%s()", wp_context,
  54. + wp_context->refcount + 1, file, line, caller);
  55. +
  56. + __sync_fetch_and_add(&wp_context->refcount, 1);
  57. +
  58. + return wp_context;
  59. +}
  60. +
  61. +static void wispr_portal_context_unref_debug(
  62. + struct connman_wispr_portal_context *wp_context,
  63. + const char *file, int line, const char *caller)
  64. +{
  65. + if (!wp_context)
  66. + return;
  67. +
  68. + DBG("%p ref %d by %s:%d:%s()", wp_context,
  69. + wp_context->refcount - 1, file, line, caller);
  70. +
  71. + if (__sync_fetch_and_sub(&wp_context->refcount, 1) != 1)
  72. + return;
  73. +
  74. + free_connman_wispr_portal_context(wp_context);
  75. +}
  76. +
  77. static struct connman_wispr_portal_context *create_wispr_portal_context(void)
  78. {
  79. - return g_try_new0(struct connman_wispr_portal_context, 1);
  80. + return wispr_portal_context_ref(
  81. + g_new0(struct connman_wispr_portal_context, 1));
  82. }
  83. static void free_connman_wispr_portal(gpointer data)
  84. @@ -215,8 +247,8 @@ static void free_connman_wispr_portal(gpointer data)
  85. if (!wispr_portal)
  86. return;
  87. - free_connman_wispr_portal_context(wispr_portal->ipv4_context);
  88. - free_connman_wispr_portal_context(wispr_portal->ipv6_context);
  89. + wispr_portal_context_unref(wispr_portal->ipv4_context);
  90. + wispr_portal_context_unref(wispr_portal->ipv6_context);
  91. g_free(wispr_portal);
  92. }
  93. @@ -452,7 +484,7 @@ static void portal_manage_status(GWebResult *result,
  94. connman_info("Client-Timezone: %s", str);
  95. if (!enable_online_to_ready_transition)
  96. - free_connman_wispr_portal_context(wp_context);
  97. + wispr_portal_context_unref(wp_context);
  98. __connman_service_ipconfig_indicate_state(service,
  99. CONNMAN_SERVICE_STATE_ONLINE, type);
  100. @@ -616,7 +648,7 @@ static void wispr_portal_request_wispr_login(struct connman_service *service,
  101. return;
  102. }
  103. - free_connman_wispr_portal_context(wp_context);
  104. + wispr_portal_context_unref(wp_context);
  105. return;
  106. }
  107. @@ -952,7 +984,7 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
  108. if (wp_context->token == 0) {
  109. err = -EINVAL;
  110. - free_connman_wispr_portal_context(wp_context);
  111. + wispr_portal_context_unref(wp_context);
  112. }
  113. } else if (wp_context->timeout == 0) {
  114. wp_context->timeout = g_idle_add(no_proxy_callback, wp_context);
  115. @@ -1001,7 +1033,7 @@ int __connman_wispr_start(struct connman_service *service,
  116. /* If there is already an existing context, we wipe it */
  117. if (wp_context)
  118. - free_connman_wispr_portal_context(wp_context);
  119. + wispr_portal_context_unref(wp_context);
  120. wp_context = create_wispr_portal_context();
  121. if (!wp_context)
  122. --
  123. cgit