From de3eb8c5e40fb45821c54cc237e95c98b39d0e2a Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Thu, 30 May 2019 15:15:01 -0700 Subject: [PATCH 1/5] Bug 30649: Check that machine is absent before warn --- src/core/or/circuitpadding.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c index b2315d822f..ae32713bfa 100644 --- a/src/core/or/circuitpadding.c +++ b/src/core/or/circuitpadding.c @@ -254,17 +254,25 @@ circpad_marked_circuit_for_padding(circuit_t *circ, int reason) return 0; // No machine wanted to keep the circuit open; mark for close } -/** Free all the machineinfos in circ that match machine_num. */ -static void +/** + * Free all the machineinfos in circ that match machine_num. + * + * Returns true if any machineinfos with that number were freed. + * False otherwise. */ +static int free_circ_machineinfos_with_machine_num(circuit_t *circ, int machine_num) { + int found = 0; FOR_EACH_CIRCUIT_MACHINE_BEGIN(i) { if (circ->padding_machine[i] && circ->padding_machine[i]->machine_num == machine_num) { circpad_circuit_machineinfo_free_idx(circ, i); circ->padding_machine[i] = NULL; + found = 1; } } FOR_EACH_CIRCUIT_MACHINE_END; + + return found; } /** @@ -2811,7 +2819,10 @@ circpad_handle_padding_negotiate(circuit_t *circ, cell_t *cell) if (negotiate->command == CIRCPAD_COMMAND_STOP) { /* Free the machine corresponding to this machine type */ - free_circ_machineinfos_with_machine_num(circ, negotiate->machine_type); + if (free_circ_machineinfos_with_machine_num(circ, + negotiate->machine_type)) { + goto done; + } log_fn(LOG_WARN, LD_CIRC, "Received circuit padding stop command for unknown machine."); goto err; From 9bef75a29a009f057c69c730b6bf3eccfc0c4b45 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Thu, 30 May 2019 15:18:16 -0700 Subject: [PATCH 2/5] Bug 30649: Changes file. --- changes/bug30649 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changes/bug30649 diff --git a/changes/bug30649 b/changes/bug30649 new file mode 100644 index 0000000000..3f5768bcb4 --- /dev/null +++ b/changes/bug30649 @@ -0,0 +1,4 @@ + o Minor bugfixes (circuit padding): + - On relays, properly check that a padding machine is absent before + logging a warn about it being absent. Fixes bug 30649; + bugfix on 0.4.1.1-alpha. From 6263755728f62b2535535f68960e601dccaead9d Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Thu, 30 May 2019 16:20:56 -0700 Subject: [PATCH 3/5] Make some warns into protocol warns I'm not sure I agree with this option. --- src/core/or/circuitpadding.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c index ae32713bfa..84650a5a98 100644 --- a/src/core/or/circuitpadding.c +++ b/src/core/or/circuitpadding.c @@ -2805,14 +2805,14 @@ circpad_handle_padding_negotiate(circuit_t *circ, cell_t *cell) circpad_negotiate_t *negotiate; if (CIRCUIT_IS_ORIGIN(circ)) { - log_fn(LOG_WARN, LD_PROTOCOL, + log_fn(LOG_WARN, LD_CIRC, "Padding negotiate cell unsupported at origin."); return -1; } if (circpad_negotiate_parse(&negotiate, cell->payload+RELAY_HEADER_SIZE, CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE) < 0) { - log_fn(LOG_WARN, LD_CIRC, + log_fn(LOG_PROTOCOL_WARN, LD_CIRC, "Received malformed PADDING_NEGOTIATE cell; dropping."); return -1; } @@ -2823,7 +2823,7 @@ circpad_handle_padding_negotiate(circuit_t *circ, cell_t *cell) negotiate->machine_type)) { goto done; } - log_fn(LOG_WARN, LD_CIRC, + log_fn(LOG_PROTOCOL_WARN, LD_CIRC, "Received circuit padding stop command for unknown machine."); goto err; } else if (negotiate->command == CIRCPAD_COMMAND_START) { @@ -2864,21 +2864,21 @@ circpad_handle_padding_negotiated(circuit_t *circ, cell_t *cell, circpad_negotiated_t *negotiated; if (!CIRCUIT_IS_ORIGIN(circ)) { - log_fn(LOG_WARN, LD_PROTOCOL, + log_fn(LOG_PROTOCOL_WARN, LD_CIRC, "Padding negotiated cell unsupported at non-origin."); return -1; } /* Verify this came from the expected hop */ if (!circpad_padding_is_from_expected_hop(circ, layer_hint)) { - log_fn(LOG_WARN, LD_PROTOCOL, + log_fn(LOG_WARN, LD_CIRC, "Padding negotiated cell from wrong hop!"); return -1; } if (circpad_negotiated_parse(&negotiated, cell->payload+RELAY_HEADER_SIZE, CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE) < 0) { - log_fn(LOG_WARN, LD_CIRC, + log_fn(LOG_PROTOCOL_WARN, LD_CIRC, "Received malformed PADDING_NEGOTIATED cell; " "dropping."); return -1; From e54ce03b4f439d7cdf9d0d0da3be11b72a1a83fd Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Wed, 5 Jun 2019 12:33:39 -0700 Subject: [PATCH 4/5] More LOG_PROTOCOL_WARN. Make origin-side messages about padding negotiation failure into LOG_PROTOCOL_WARN. I'm not sure I like this either.. But the negotiation refusal case might happen naturally due to consensus drift, and is functionally no different than a corrupted cell. --- src/core/or/circuitpadding.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c index 84650a5a98..ebad6518b6 100644 --- a/src/core/or/circuitpadding.c +++ b/src/core/or/circuitpadding.c @@ -2805,7 +2805,7 @@ circpad_handle_padding_negotiate(circuit_t *circ, cell_t *cell) circpad_negotiate_t *negotiate; if (CIRCUIT_IS_ORIGIN(circ)) { - log_fn(LOG_WARN, LD_CIRC, + log_fn(LOG_PROTOCOL_WARN, LD_CIRC, "Padding negotiate cell unsupported at origin."); return -1; } @@ -2871,7 +2871,7 @@ circpad_handle_padding_negotiated(circuit_t *circ, cell_t *cell, /* Verify this came from the expected hop */ if (!circpad_padding_is_from_expected_hop(circ, layer_hint)) { - log_fn(LOG_WARN, LD_CIRC, + log_fn(LOG_PROTOCOL_WARN, LD_CIRC, "Padding negotiated cell from wrong hop!"); return -1; } @@ -2898,7 +2898,7 @@ circpad_handle_padding_negotiated(circuit_t *circ, cell_t *cell, // and be sad free_circ_machineinfos_with_machine_num(circ, negotiated->machine_type); TO_ORIGIN_CIRCUIT(circ)->padding_negotiation_failed = 1; - log_fn(LOG_INFO, LD_CIRC, + log_fn(LOG_PROTOCOL_WARN, LD_CIRC, "Middle node did not accept our padding request."); } From a15ec8bf84db2dcadcc292b9672fbd6d35ffdf77 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Tue, 11 Jun 2019 14:28:38 +0300 Subject: [PATCH 5/5] circpad: some more logging changes. - Add an info log when receiving a STOP command. - Keep warning if we receive padding from a wrong hop. --- src/core/or/circuitpadding.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c index ebad6518b6..7521fd3394 100644 --- a/src/core/or/circuitpadding.c +++ b/src/core/or/circuitpadding.c @@ -2821,6 +2821,8 @@ circpad_handle_padding_negotiate(circuit_t *circ, cell_t *cell) /* Free the machine corresponding to this machine type */ if (free_circ_machineinfos_with_machine_num(circ, negotiate->machine_type)) { + log_info(LD_CIRC, "Received STOP command for machine %u", + negotiate->machine_type); goto done; } log_fn(LOG_PROTOCOL_WARN, LD_CIRC, @@ -2871,7 +2873,7 @@ circpad_handle_padding_negotiated(circuit_t *circ, cell_t *cell, /* Verify this came from the expected hop */ if (!circpad_padding_is_from_expected_hop(circ, layer_hint)) { - log_fn(LOG_PROTOCOL_WARN, LD_CIRC, + log_fn(LOG_WARN, LD_CIRC, "Padding negotiated cell from wrong hop!"); return -1; }