]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
hs: Never pick a MiddleOnly node for HS circuit purposes
authorDavid Goulet <dgoulet@torproject.org>
Tue, 11 Mar 2025 16:00:22 +0000 (12:00 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Thu, 20 Mar 2025 13:50:50 +0000 (09:50 -0400)
Related to #41023

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/or/circuitbuild.c
src/feature/hs/hs_circuit.c
src/feature/hs/hs_service.c
src/feature/nodelist/node_select.h
src/feature/nodelist/routerlist.c

index 032b6def6ca76ab6f4542a067d42f7d516dd85e0..fdebe367d20ec908a96304a8885d8cac49259f43 100644 (file)
@@ -1847,14 +1847,6 @@ choose_good_exit_server_general(router_crn_flags_t flags)
   return NULL;
 }
 
-/* Pick a Rendezvous Point for our HS circuits according to <b>flags</b>. */
-static const node_t *
-pick_rendezvous_node(router_crn_flags_t flags)
-{
-  const or_options_t *options = get_options();
-  return router_choose_random_node(NULL, options->ExcludeNodes, flags);
-}
-
 /*
  * Helper function to pick a configured restricted middle node
  * (either HSLayer2Nodes or HSLayer3Nodes).
@@ -1962,9 +1954,12 @@ choose_good_exit_server(origin_circuit_t *circ,
     case CIRCUIT_PURPOSE_C_HSDIR_GET:
     case CIRCUIT_PURPOSE_S_HSDIR_POST:
     case CIRCUIT_PURPOSE_HS_VANGUARDS:
+    case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
       /* For these three, we want to pick the exit like a middle hop,
        * since it should be random. */
       tor_assert_nonfatal(is_internal);
+      /* We want to avoid picking certain nodes for HS purposes. */
+      flags |= CRN_FOR_HS;
       FALLTHROUGH;
     case CIRCUIT_PURPOSE_CONFLUX_UNLINKED:
     case CIRCUIT_PURPOSE_C_GENERAL:
@@ -1972,14 +1967,6 @@ choose_good_exit_server(origin_circuit_t *circ,
         return router_choose_random_node(NULL, options->ExcludeNodes, flags);
       else
         return choose_good_exit_server_general(flags);
-    case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
-      {
-        /* Pick a new RP */
-        const node_t *rendezvous_node = pick_rendezvous_node(flags);
-        log_info(LD_REND, "Picked new RP: %s",
-                 safe_str_client(node_describe(rendezvous_node)));
-        return rendezvous_node;
-      }
   }
   log_warn(LD_BUG,"Unhandled purpose %d", TO_CIRCUIT(circ)->purpose);
   tor_fragile_assert();
index 4904f3ddf9eba6ad4e732105d3ebc2e1ed671d07..43b563b48a4e933ff38c1fc4cba68b8586956105 100644 (file)
@@ -44,6 +44,7 @@
 #include "core/or/congestion_control_st.h"
 #include "core/or/cpath_build_state_st.h"
 #include "core/or/crypt_path_st.h"
+#include "core/or/extend_info_st.h"
 #include "feature/nodelist/node_st.h"
 #include "core/or/origin_circuit_st.h"
 
index 3cc8c23e0b0019c55528dc21c4be56e168ace163..5a53b913cfc9344935f829f834cb1453a8649984 100644 (file)
@@ -2203,7 +2203,7 @@ pick_intro_point(unsigned int direct_conn, smartlist_t *exclude_nodes)
   const node_t *node;
   hs_service_intro_point_t *ip = NULL;
   /* Normal 3-hop introduction point flags. */
-  router_crn_flags_t flags = CRN_NEED_UPTIME | CRN_NEED_DESC;
+  router_crn_flags_t flags = CRN_NEED_UPTIME | CRN_NEED_DESC | CRN_FOR_HS;
   /* Single onion flags. */
   router_crn_flags_t direct_flags = flags | CRN_PREF_ADDR | CRN_DIRECT_CONN;
 
index 9dba333fe23d48b91f6ec710526dac0f36796863..03d3a160196460a1e83efb0ed04e1f16d99a7b1c 100644 (file)
@@ -29,6 +29,9 @@ typedef enum router_crn_flags_t {
   /* On clients, if choosing a node for a direct connection, only provide
    * nodes that satisfy ClientPreferIPv6OR. */
   CRN_PREF_ADDR = 1<<5,
+  /* On clients, indiate that we need a HS related circuit (IP, HSDir or RP).
+   * This is used in order to avoid certain nodes for these purposes. */
+  CRN_FOR_HS = 1<<6,
   /* On clients, only provide nodes that can initiate IPv6 extends. */
   CRN_INITIATE_IPV6_EXTEND = 1<<7,
   /* On clients, only provide nodes that support Conflux (Relay=5). */
index 9687a4dc3c4264a37a02d9c665489a135c66e471..6913d8778d2f68e3c6f5f980b0d9632232e33e20 100644 (file)
@@ -558,6 +558,7 @@ router_can_choose_node(const node_t *node, int flags)
   const bool direct_conn = (flags & CRN_DIRECT_CONN) != 0;
   const bool initiate_ipv6_extend = (flags & CRN_INITIATE_IPV6_EXTEND) != 0;
   const bool need_conflux = (flags & CRN_CONFLUX) != 0;
+  const bool for_hs = (flags & CRN_FOR_HS) != 0;
 
   const or_options_t *options = get_options();
   const bool check_reach =
@@ -599,6 +600,10 @@ router_can_choose_node(const node_t *node, int flags)
     return false;
   if (initiate_ipv6_extend && !node_supports_initiating_ipv6_extends(node))
     return false;
+  /* MiddleOnly node should never be used for HS ndpoints (IP, RP, HSDir). */
+  if (for_hs && node->is_middle_only) {
+    return false;
+  }
 
   return true;
 }