Loading changes/bug24104 0 → 100644 +4 −0 Original line number Diff line number Diff line o Minor bugfix (relay statistics): - Update relay descriptor on bandwidth changes only when the uptime is smaller than 24h in order to reduce the efficiency of guard discovery attacks. Fixes bug 24104; bugfix on 0.1.1.6-alpha. src/or/rephist.c +3 −4 Original line number Diff line number Diff line /* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** Loading Loading @@ -1203,8 +1203,8 @@ find_largest_max(bw_array_t *b) * * Return the smaller of these sums, divided by NUM_SECS_ROLLING_MEASURE. */ int rep_hist_bandwidth_assess(void) MOCK_IMPL(int, rep_hist_bandwidth_assess,(void)) { uint64_t w,r; r = find_largest_max(read_array); Loading Loading @@ -3205,4 +3205,3 @@ rep_hist_free_all(void) tor_assert_nonfatal(rephist_total_alloc == 0); tor_assert_nonfatal_once(rephist_total_num == 0); } src/or/rephist.h +2 −3 Original line number Diff line number Diff line /* Copyright (c) 2001 Matej Pfajfar. * Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** Loading @@ -22,7 +22,7 @@ void rep_hist_make_router_pessimal(const char *id, time_t when); void rep_hist_note_dir_bytes_read(size_t num_bytes, time_t when); void rep_hist_note_dir_bytes_written(size_t num_bytes, time_t when); int rep_hist_bandwidth_assess(void); MOCK_DECL(int, rep_hist_bandwidth_assess, (void)); char *rep_hist_get_bandwidth_lines(void); void rep_hist_update_state(or_state_t *state); int rep_hist_load_state(or_state_t *state, char **err); Loading Loading @@ -137,4 +137,3 @@ void rep_hist_prep_published_padding_counts(time_t now); void rep_hist_padding_count_timers(uint64_t num_timers); #endif /* !defined(TOR_REPHIST_H) */ src/or/router.c +20 −5 Original line number Diff line number Diff line Loading @@ -2516,22 +2516,38 @@ mark_my_descriptor_dirty(const char *reason) * if our previous bandwidth estimate was exactly 0. */ #define MAX_BANDWIDTH_CHANGE_FREQ (3*60*60) /** Maximum uptime to republish our descriptor because of large shifts in * estimated bandwidth. */ #define MAX_UPTIME_BANDWIDTH_CHANGE (24*60*60) /** By which factor bandwidth shifts have to change to be considered large. */ #define BANDWIDTH_CHANGE_FACTOR 2 /** Check whether bandwidth has changed a lot since the last time we announced * bandwidth. If so, mark our descriptor dirty. */ * bandwidth while the uptime is smaller than MAX_UPTIME_BANDWIDTH_CHANGE. * If so, mark our descriptor dirty. */ void check_descriptor_bandwidth_changed(time_t now) { static time_t last_changed = 0; uint64_t prev, cur; const routerinfo_t *my_ri = router_get_my_routerinfo(); int hibernating = we_are_hibernating(); /* If the relay uptime is bigger than MAX_UPTIME_BANDWIDTH_CHANGE, * the next regularly scheduled descriptor update (18h) will be enough */ if (get_uptime() > MAX_UPTIME_BANDWIDTH_CHANGE && !hibernating) return; if (!my_ri) /* make sure routerinfo exists */ return; prev = my_ri->bandwidthcapacity; cur = we_are_hibernating() ? 0 : rep_hist_bandwidth_assess(); cur = hibernating ? 0 : rep_hist_bandwidth_assess(); if ((prev != cur && (!prev || !cur)) || cur > prev*2 || cur < prev/2) { cur > (prev * BANDWIDTH_CHANGE_FACTOR) || cur < (prev / BANDWIDTH_CHANGE_FACTOR) ) { if (last_changed+MAX_BANDWIDTH_CHANGE_FREQ < now || !prev) { log_info(LD_GENERAL, "Measured bandwidth has changed; rebuilding descriptor."); Loading Loading @@ -3733,4 +3749,3 @@ router_get_all_orports(const routerinfo_t *ri) fake_node.ri = (routerinfo_t *)ri; return node_get_all_orports(&fake_node); } src/test/log_test_helpers.c +21 −2 Original line number Diff line number Diff line /* Copyright (c) 2015-2017, The Tor Project, Inc. */ /* Copyright (c) 2015-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ #define LOG_PRIVATE #include "torlog.h" Loading Loading @@ -158,6 +158,26 @@ mock_saved_log_has_message_containing(const char *msg) return 0; } /** * Return true iff there is not a message recorded by log capture * that contains <b>msg</b> as a substring. */ int mock_saved_log_has_message_not_containing(const char *msg) { if (saved_logs) { SMARTLIST_FOREACH( saved_logs, mock_saved_log_entry_t *, m, { if (msg && m->generated_msg && strstr(m->generated_msg, msg)) return 0; } ); } return 1; } /** Return true iff the saved logs have any messages with <b>severity</b> */ int mock_saved_log_has_severity(int severity) Loading Loading @@ -238,4 +258,3 @@ mock_dump_saved_logs(void) escaped(m->generated_msg)); } SMARTLIST_FOREACH_END(m); } Loading
changes/bug24104 0 → 100644 +4 −0 Original line number Diff line number Diff line o Minor bugfix (relay statistics): - Update relay descriptor on bandwidth changes only when the uptime is smaller than 24h in order to reduce the efficiency of guard discovery attacks. Fixes bug 24104; bugfix on 0.1.1.6-alpha.
src/or/rephist.c +3 −4 Original line number Diff line number Diff line /* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** Loading Loading @@ -1203,8 +1203,8 @@ find_largest_max(bw_array_t *b) * * Return the smaller of these sums, divided by NUM_SECS_ROLLING_MEASURE. */ int rep_hist_bandwidth_assess(void) MOCK_IMPL(int, rep_hist_bandwidth_assess,(void)) { uint64_t w,r; r = find_largest_max(read_array); Loading Loading @@ -3205,4 +3205,3 @@ rep_hist_free_all(void) tor_assert_nonfatal(rephist_total_alloc == 0); tor_assert_nonfatal_once(rephist_total_num == 0); }
src/or/rephist.h +2 −3 Original line number Diff line number Diff line /* Copyright (c) 2001 Matej Pfajfar. * Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** Loading @@ -22,7 +22,7 @@ void rep_hist_make_router_pessimal(const char *id, time_t when); void rep_hist_note_dir_bytes_read(size_t num_bytes, time_t when); void rep_hist_note_dir_bytes_written(size_t num_bytes, time_t when); int rep_hist_bandwidth_assess(void); MOCK_DECL(int, rep_hist_bandwidth_assess, (void)); char *rep_hist_get_bandwidth_lines(void); void rep_hist_update_state(or_state_t *state); int rep_hist_load_state(or_state_t *state, char **err); Loading Loading @@ -137,4 +137,3 @@ void rep_hist_prep_published_padding_counts(time_t now); void rep_hist_padding_count_timers(uint64_t num_timers); #endif /* !defined(TOR_REPHIST_H) */
src/or/router.c +20 −5 Original line number Diff line number Diff line Loading @@ -2516,22 +2516,38 @@ mark_my_descriptor_dirty(const char *reason) * if our previous bandwidth estimate was exactly 0. */ #define MAX_BANDWIDTH_CHANGE_FREQ (3*60*60) /** Maximum uptime to republish our descriptor because of large shifts in * estimated bandwidth. */ #define MAX_UPTIME_BANDWIDTH_CHANGE (24*60*60) /** By which factor bandwidth shifts have to change to be considered large. */ #define BANDWIDTH_CHANGE_FACTOR 2 /** Check whether bandwidth has changed a lot since the last time we announced * bandwidth. If so, mark our descriptor dirty. */ * bandwidth while the uptime is smaller than MAX_UPTIME_BANDWIDTH_CHANGE. * If so, mark our descriptor dirty. */ void check_descriptor_bandwidth_changed(time_t now) { static time_t last_changed = 0; uint64_t prev, cur; const routerinfo_t *my_ri = router_get_my_routerinfo(); int hibernating = we_are_hibernating(); /* If the relay uptime is bigger than MAX_UPTIME_BANDWIDTH_CHANGE, * the next regularly scheduled descriptor update (18h) will be enough */ if (get_uptime() > MAX_UPTIME_BANDWIDTH_CHANGE && !hibernating) return; if (!my_ri) /* make sure routerinfo exists */ return; prev = my_ri->bandwidthcapacity; cur = we_are_hibernating() ? 0 : rep_hist_bandwidth_assess(); cur = hibernating ? 0 : rep_hist_bandwidth_assess(); if ((prev != cur && (!prev || !cur)) || cur > prev*2 || cur < prev/2) { cur > (prev * BANDWIDTH_CHANGE_FACTOR) || cur < (prev / BANDWIDTH_CHANGE_FACTOR) ) { if (last_changed+MAX_BANDWIDTH_CHANGE_FREQ < now || !prev) { log_info(LD_GENERAL, "Measured bandwidth has changed; rebuilding descriptor."); Loading Loading @@ -3733,4 +3749,3 @@ router_get_all_orports(const routerinfo_t *ri) fake_node.ri = (routerinfo_t *)ri; return node_get_all_orports(&fake_node); }
src/test/log_test_helpers.c +21 −2 Original line number Diff line number Diff line /* Copyright (c) 2015-2017, The Tor Project, Inc. */ /* Copyright (c) 2015-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ #define LOG_PRIVATE #include "torlog.h" Loading Loading @@ -158,6 +158,26 @@ mock_saved_log_has_message_containing(const char *msg) return 0; } /** * Return true iff there is not a message recorded by log capture * that contains <b>msg</b> as a substring. */ int mock_saved_log_has_message_not_containing(const char *msg) { if (saved_logs) { SMARTLIST_FOREACH( saved_logs, mock_saved_log_entry_t *, m, { if (msg && m->generated_msg && strstr(m->generated_msg, msg)) return 0; } ); } return 1; } /** Return true iff the saved logs have any messages with <b>severity</b> */ int mock_saved_log_has_severity(int severity) Loading Loading @@ -238,4 +258,3 @@ mock_dump_saved_logs(void) escaped(m->generated_msg)); } SMARTLIST_FOREACH_END(m); }