diff options
author | David Goulet <dgoulet@torproject.org> | 2019-08-20 10:50:31 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-09-09 11:07:36 -0400 |
commit | 385f6bcfccbc327f42e5139ac8136086e79fbb17 (patch) | |
tree | 4269b817a32b88582b6e451e9d150ab3c299ac32 /src/feature/hs/hs_intropoint.c | |
parent | a8a1ea4e0e78e5a24fad6939c47ef9dbf78b38c2 (diff) | |
download | tor-385f6bcfccbc327f42e5139ac8136086e79fbb17.tar.gz tor-385f6bcfccbc327f42e5139ac8136086e79fbb17.zip |
hs-v3: Move DoS parameter check against 0
Move it outside of the validation function since 0 is a valid value but
disables defenses.
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/hs/hs_intropoint.c')
-rw-r--r-- | src/feature/hs/hs_intropoint.c | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/src/feature/hs/hs_intropoint.c b/src/feature/hs/hs_intropoint.c index 9b6a966288..fb2ac52e5b 100644 --- a/src/feature/hs/hs_intropoint.c +++ b/src/feature/hs/hs_intropoint.c @@ -191,28 +191,40 @@ validate_cell_dos_extension_parameters(uint64_t intro2_rate_per_sec, { bool ret = false; - /* A value of 0 is valid in the sense that we accept it but we still disable - * the defenses so return false. */ - if (intro2_rate_per_sec == 0 || intro2_burst_per_sec == 0) { - log_info(LD_REND, "Intro point DoS defenses parameter set to 0."); + /* Check that received value is not below the minimum. Don't check if minimum + is set to 0, since the param is a positive value and gcc will complain. */ +#if HS_CONFIG_V3_DOS_DEFENSE_RATE_PER_SEC_MIN > 0 + if (intro2_rate_per_sec < HS_CONFIG_V3_DOS_DEFENSE_RATE_PER_SEC_MIN) { + log_fn(LOG_PROTOCOL_WARN, LD_REND, + "Intro point DoS defenses rate per second is " + "too small. Received value: %" PRIu64, intro2_rate_per_sec); goto end; } +#endif - /* Bound check the received rate per second. MIN/MAX are inclusive. */ - if (!(intro2_rate_per_sec <= HS_CONFIG_V3_DOS_DEFENSE_RATE_PER_SEC_MAX && - intro2_rate_per_sec > HS_CONFIG_V3_DOS_DEFENSE_RATE_PER_SEC_MIN)) { - log_info(LD_REND, "Intro point DoS defenses rate per second is " - "invalid. Received value: %" PRIu64, - intro2_rate_per_sec); + /* Check that received value is not above maximum */ + if (intro2_rate_per_sec > HS_CONFIG_V3_DOS_DEFENSE_RATE_PER_SEC_MAX) { + log_fn(LOG_PROTOCOL_WARN, LD_REND, + "Intro point DoS defenses rate per second is " + "too big. Received value: %" PRIu64, intro2_rate_per_sec); + goto end; + } + + /* Check that received value is not below the minimum */ +#if HS_CONFIG_V3_DOS_DEFENSE_BURST_PER_SEC_MIN > 0 + if (intro2_burst_per_sec < HS_CONFIG_V3_DOS_DEFENSE_BURST_PER_SEC_MIN) { + log_fn(LOG_PROTOCOL_WARN, LD_REND, + "Intro point DoS defenses burst per second is " + "too small. Received value: %" PRIu64, intro2_burst_per_sec); goto end; } +#endif - /* Bound check the received burst per second. MIN/MAX are inclusive. */ - if (!(intro2_burst_per_sec <= HS_CONFIG_V3_DOS_DEFENSE_BURST_PER_SEC_MAX && - intro2_burst_per_sec > HS_CONFIG_V3_DOS_DEFENSE_BURST_PER_SEC_MIN)) { - log_info(LD_REND, "Intro point DoS defenses burst per second is " - "invalid. Received value: %" PRIu64, - intro2_burst_per_sec); + /* Check that received value is not above maximum */ + if (intro2_burst_per_sec > HS_CONFIG_V3_DOS_DEFENSE_BURST_PER_SEC_MAX) { + log_fn(LOG_PROTOCOL_WARN, LD_REND, + "Intro point DoS defenses burst per second is " + "too big. Received value: %" PRIu64, intro2_burst_per_sec); goto end; } @@ -273,6 +285,16 @@ handle_establish_intro_cell_dos_extension( } } + /* A value of 0 is valid in the sense that we accept it but we still disable + * the defenses so return false. */ + if (intro2_rate_per_sec == 0 || intro2_burst_per_sec == 0) { + log_info(LD_REND, "Intro point DoS defenses parameter set to 0. " + "Disabling INTRO2 DoS defenses on circuit id %u", + circ->p_circ_id); + circ->introduce2_dos_defense_enabled = 0; + goto end; + } + /* If invalid, we disable the defense on the circuit. */ if (!validate_cell_dos_extension_parameters(intro2_rate_per_sec, intro2_burst_per_sec)) { |