[tor-commits] [tor/master] Don't accept posted votes after :52:30

nickm at torproject.org nickm at torproject.org
Thu Feb 20 13:18:24 UTC 2020


commit acb5b0d535dae67b6a85780b4ae54bcf415e79fc
Author: Roger Dingledine <arma at torproject.org>
Date:   Wed Jan 29 07:31:19 2020 -0500

    Don't accept posted votes after :52:30
    
    If we receive via 'post' a vote from a dir auth after the
    fetch_missing_votes cutoff, that means we didn't get it by the time we
    begin the "fetching missing votes from everybody else" phase, which means
    it is very likely to cause a consensus split if we count it. Instead,
    we reject it.
    
    But we still allow votes that we fetch ourselves after that cutoff.
    
    This is a demo branch for making progress on #4631.
    
    I've been running it on moria1 and it catches and handles real buggy
    behavior from directory authorities, e.g.
    
    Jan 28 15:59:50.804 [warn] Rejecting vote from 199.58.81.140 received at 2020-01-28 20:59:50; our cutoff for received votes is 2020-01-28 20:52:30
    Jan 28 15:59:50.805 [warn] Rejected vote from 199.58.81.140 ("Vote received too late, would be dangerous to count it").
    Jan 29 01:52:52.667 [warn] Rejecting vote from 204.13.164.118 received at 2020-01-29 06:52:52; our cutoff for received votes is 2020-01-29 06:52:30
    Jan 29 01:52:52.669 [warn] Rejected vote from 204.13.164.118 ("Vote received too late, would be dangerous to count it").
    Jan 29 04:53:26.323 [warn] Rejecting vote from 204.13.164.118 received at 2020-01-29 09:53:26; our cutoff for received votes is 2020-01-29 09:52:30
    Jan 29 04:53:26.326 [warn] Rejected vote from 204.13.164.118 ("Vote received too late, would be dangerous to count it").
---
 src/feature/dirauth/dirvote.c     | 24 ++++++++++++++++++++++--
 src/feature/dirauth/dirvote.h     |  1 +
 src/feature/dircache/dircache.c   |  2 +-
 src/feature/dirclient/dirclient.c |  2 +-
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c
index 4e0e19dc9..a87e78d29 100644
--- a/src/feature/dirauth/dirvote.c
+++ b/src/feature/dirauth/dirvote.c
@@ -2963,7 +2963,7 @@ dirvote_perform_vote(void)
   if (!contents)
     return -1;
 
-  pending_vote = dirvote_add_vote(contents, &msg, &status);
+  pending_vote = dirvote_add_vote(contents, 0, &msg, &status);
   tor_free(contents);
   if (!pending_vote) {
     log_warn(LD_DIR, "Couldn't store my own vote! (I told myself, '%s'.)",
@@ -3125,7 +3125,8 @@ list_v3_auth_ids(void)
  * *<b>status_out</b> to an HTTP response and status code.  (V3 authority
  * only) */
 pending_vote_t *
-dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
+dirvote_add_vote(const char *vote_body, time_t time_posted,
+                 const char **msg_out, int *status_out)
 {
   networkstatus_t *vote;
   networkstatus_voter_info_t *vi;
@@ -3200,6 +3201,25 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
     goto err;
   }
 
+  if (!time_posted) { /* I imported this one myself */
+    log_notice(LD_DIR, "Retrieved vote from %s.", vi->address);
+  }
+
+  /* Check if we received it, as a post, after the cutoff when we
+   * start asking other dir auths for it. If we do, the best plan
+   * is to discard it, because using it greatly increases the chances
+   * of a split vote for this round (some dir auths got it in time,
+   * some didn't). */
+  if (time_posted && time_posted > voting_schedule.fetch_missing_votes) {
+    char tbuf1[ISO_TIME_LEN+1], tbuf2[ISO_TIME_LEN+1];
+    format_iso_time(tbuf1, time_posted);
+    format_iso_time(tbuf2, voting_schedule.fetch_missing_votes);
+    log_warn(LD_DIR, "Rejecting vote from %s received at %s; "
+             "our cutoff for received votes is %s", vi->address, tbuf1, tbuf2);
+    *msg_out = "Vote received too late, would be dangerous to count it";
+    goto err;
+  }
+
   /* Fetch any new router descriptors we just learned about */
   update_consensus_router_descriptor_downloads(time(NULL), 1, vote);
 
diff --git a/src/feature/dirauth/dirvote.h b/src/feature/dirauth/dirvote.h
index 305094aa4..b5e34a9c2 100644
--- a/src/feature/dirauth/dirvote.h
+++ b/src/feature/dirauth/dirvote.h
@@ -94,6 +94,7 @@ void dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items,
 
 /* Storing signatures and votes functions */
 struct pending_vote_t * dirvote_add_vote(const char *vote_body,
+                                         time_t time_posted,
                                          const char **msg_out,
                                          int *status_out);
 int dirvote_add_signatures(const char *detached_signatures_body,
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c
index ef7054001..9e1794272 100644
--- a/src/feature/dircache/dircache.c
+++ b/src/feature/dircache/dircache.c
@@ -1696,7 +1696,7 @@ directory_handle_command_post,(dir_connection_t *conn, const char *headers,
       !strcmp(url,"/tor/post/vote")) { /* v3 networkstatus vote */
     const char *msg = "OK";
     int status;
-    if (dirvote_add_vote(body, &msg, &status)) {
+    if (dirvote_add_vote(body, approx_time(), &msg, &status)) {
       write_short_http_response(conn, status, "Vote stored");
     } else {
       tor_assert(msg);
diff --git a/src/feature/dirclient/dirclient.c b/src/feature/dirclient/dirclient.c
index 1b6eed12f..a216e5e27 100644
--- a/src/feature/dirclient/dirclient.c
+++ b/src/feature/dirclient/dirclient.c
@@ -2364,7 +2364,7 @@ handle_response_fetch_status_vote(dir_connection_t *conn,
              conn->base_.port, conn->requested_resource);
     return -1;
   }
-  dirvote_add_vote(body, &msg, &st);
+  dirvote_add_vote(body, 0, &msg, &st);
   if (st > 299) {
     log_warn(LD_DIR, "Error adding retrieved vote: %s", msg);
   } else {





More information about the tor-commits mailing list