aboutsummaryrefslogtreecommitdiff
path: root/src/app/config/resolve_addr.c
AgeCommit message (Collapse)Author
2021-02-10relay: Allow RFC1918 addresses for non public relaysDavid Goulet
In other words, if PublishServerDescriptor is set to 0 and AssumeReachable to 1, then allow a relay to hold a RFC1918 address. Reasons for this are documented in #40208 Fixes #40208 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-12-21relay: Log address suggested by directory authoritiesDavid Goulet
If we get an address suggestion from a directory authority and we have no address configured or discovered, log it at notice level so the operator can learn what address will be used by Tor. Fixes #40201 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-10-01fix typosRoger Dingledine
no actual changes
2020-09-03addr: Missing AF family to index conversionDavid Goulet
When accessing the last_resolved_address cache we always need to convert the AF family value to an index value else we are out of bound and thus overflowing if we write to it. This fix is on code that has not been released. GeKo reported the following libasan crash using Tor Browser alpha with tor 0.4.5.0-alpha-dev (3c884bc9e077e997): ==4240==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55888490e388 at pc 0x5588842cc216 bp 0x7ffc8c421b00 sp 0x7ffc8c421af8 READ of size 2 at 0x55888490e388 thread T0 #0 0x5588842cc215 in tor_addr_compare_masked (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x5a6215) #1 0x558884203210 in is_local_to_resolve_addr (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x4dd210) #2 0x558883f7e252 in channel_tls_connect (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x258252) #3 0x558883f87ff7 in channel_connect_for_circuit (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x261ff7) #4 0x558883f8bc90 in circuit_handle_first_hop (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x265c90) #5 0x558883f8c891 in circuit_establish_circuit (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x266891) #6 0x558883fc3bbc in circuit_launch_by_extend_info (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x29dbbc) #7 0x558883fc5900 (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x29f900) #8 0x558883fc6988 in connection_ap_handshake_attach_circuit (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x2a0988) #9 0x558883fd0d3f in connection_ap_attach_pending (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x2aad3f) #10 0x7f4d50110885 (TorBrowser/Tor/libevent-2.1.so.7+0x22885) #11 0x7f4d501110de in event_base_loop (TorBrowser/Tor/libevent-2.1.so.7+0x230de) #12 0x558883f69b3c in do_main_loop (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x243b3c) #13 0x558883f3f70c in tor_run_main (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x21970c) #14 0x558883f3c2f7 in tor_main (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x2162f7) #15 0x558883f3531b in main (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x20f31b) #16 0x7f4d4f76acc9 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26cc9) #17 0x558883f3ba00 (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x215a00) 0x55888490e388 is located 24 bytes to the left of global variable 'state_mgr' defined in 'src/app/config/statefile.c:184:22' (0x55888490e3a0) of size 8 0x55888490e388 is located 32 bytes to the right of global variable 'global_state' defined in 'src/app/config/statefile.c:204:20' (0x55888490e360) of size 8 SUMMARY: AddressSanitizer: global-buffer-overflow (/home/thomas/Arbeit/Tor/tor-browser-build/tor-browser_en-US/Browser/TorBrowser/Tor/tor+0x5a6215) in tor_addr_compare_masked Shadow bytes around the buggy address: 0x0ab190919c20: 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 0x0ab190919c30: 04 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 03 f9 f9 f9 0x0ab190919c40: f9 f9 f9 f9 03 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 0x0ab190919c50: 00 00 00 04 f9 f9 f9 f9 00 00 00 00 00 00 00 04 0x0ab190919c60: f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 =>0x0ab190919c70: f9[f9]f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 0x0ab190919c80: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 0x0ab190919c90: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 0x0ab190919ca0: 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 0x0ab190919cb0: 01 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 0x0ab190919cc0: 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==4240==ABORTING Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-24relay: Add a cache that tracks which address was configuredDavid Goulet
Related to #33247 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-24relay: Turn find address "method_used" into enumDavid Goulet
Enum allows us to easily compare what is being returned but also better semantic to the code. Related #33247 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-22Merge branch 'tor-gitlab/mr/74'David Goulet
2020-07-22addr: Always set addr_out to UNSPEC in find_my_addressDavid Goulet
Related #40058 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-22relay: Limit Directory Authority Addresses to Address and ORPortDavid Goulet
Closes #33239 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-21relay: Add AddressDisableIPv6 torrc optionDavid Goulet
This option controls if a tor relay will attempt address auto discovery and thus ultimately publish an IPv6 ORPort in the descriptor. Behavior is from proposal 312 section 3.2.6. Closes #33245 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20relay: Don't log at warn level when we find an addressDavid Goulet
Dirauth code use the warn log severity when calling find_my_address() which made it that every time we would find an address, it would log a warning. These are not needed below info level and thus set them to info level. An IP change is set to notice by default. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20test: Unit test for relay_address_new_suggestion()David Goulet
Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-20addr: Continue discovery if Address exits but not for wanted familyDavid Goulet
Commit b14b1f2b1d9 was a mistake. In case an Address statement is missing for the wanted family but another one exists for another family, simply continue the address discovery. It is not a mistake to be missing an Address statement for a family because the address could simply be discovered by the next methods. Not all address family requires a specific Address statement. However, we do bail if we couldn't find any valid address for the requested family _and_ a resolve failed meaning we had a hostname but couldn't resolve it. In that case, we can't know if that hostname would have been for v4 or v6 thus we can't continue the address discovery properly. Couple unit tests case were removed to match this reality. Related #40025 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-10addr: Remove BUG() that always triggersDavid Goulet
Fix on unreleased code. Logical || in the BUG() made it that it would always trigger the BUG(). Fixes #40034 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-09Merge remote-tracking branch 'tor-gitlab/mr/21'Nick Mathewson
2020-07-09addr: Static assert resolved address cache sizeDavid Goulet
This will make sure that we always properly initialize the cache by the exact size all the time. Related to #40022 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-08addr: Initialize resolved address cache to NULL addressDavid Goulet
Related to #40022 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-07addr: Attempt to learn our address with ORPortDavid Goulet
If no Address statement are found in the configuration file, attempt to learn our address by looking at the ORPort address if any. Specifying an address is optional so if we can't find one, it is fine, we move on to the next discovery mechanism. Note that specifying a hostname on the ORPort is not yet supported at this commit. Closes #33236 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-07addr: New function relay_address_new_suggestion()David Goulet
This behaves like router_new_address_suggestion() but differs in couple of ways: 1. It takes a tor_addr_t instead of an address string and supports both AF_INET and AF_INET6. 2. It does _not_ use the last_guessed_ip local cache and instead only relies on the last resolved address cache in resolve_addr.c It is not used at this commit. This function is made to process a suggested address found in a NETINFO cell exactly like router_new_address_suggestion() does with the address a directory suggests us. Related to #40022 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-07addr: Rename and make resolved_addr_set_last() function publicDavid Goulet
Rename the static function update_resolved_cache() to resolved_addr_set_last() and make it public. We are about to use it in order to record any suggested address from a NETINFO cell. Related to #40022 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-06addr: Fix possible memleak in find_my_address()David Goulet
Unit tests also suffered from a memleak. Closes #40024 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-02addr: Prioritize interface lookup over local hostnameDavid Goulet
The find_my_address() function now prioritize the local interface over the local hostname when guessing the IP address. See proposal 312, section 3.2.1, general case: https://gitweb.torproject.org/torspec.git/tree/proposals/312-relay-auto-ipv6-addr.txt#n359 The entire unit tests had to be refactored to make this possible. Instead of hot patching it, it has been rewritten to cover all possible cases and the test interface has been changed to accomodate both IPv4 and IPv6 in order for them to be tested identically. Closes #33238 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-07-01Merge remote-tracking branch 'dgoulet/ticket33235_045_01'Nick Mathewson
2020-06-30resolve_addr.c: remove a needless quote markNick Mathewson
2020-06-30addr: Document better is_local_addr_to_resolve_addr()David Goulet
This function is about learning if a given address is local to us as in the resolved address as a relay. Closes #40009 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-30addr: Don't guess our address if no Address lines are validDavid Goulet
If at least one Address line is given but invalid, we should not attempt to guess our address. This commit sends back the "bail" signal so find_my_address() can return an error if the requested family doesn't exists but still an Address line is found which is likely another family. Fixed in #33235 Related to #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-30addr: Continue trying all Address options on resolve failureDavid Goulet
When going over all Address lines from the configuration, continue to attempt resolving other lines if one fails. Before that, we would bail right away and never noticed the other Address lines. Fixed in #33235 Related to #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-30addr: Only attempt Address resolution on non parsable linesDavid Goulet
In get_address_from_config(), we would attempt to resolve an Address line that is not from the requested family but that line could be a valid address from another family (v4 vs v6). This makes it that we don't attempt to resolve a valid address from another family. Found with unit test config/find_my_address_mixed. Fixed in #33235 Related to #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-25addr: Look at /48 for IPv6 in is_local_addr()David Goulet
Closes #33618 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Rename resolved_addr_is_local()David Goulet
Better function name. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Refactor find_my_address() to simplify itDavid Goulet
Instead of a complex if/else block, use a table of functions that have the same interface and each of them attempt to find the address one after the other. Pointed out by nickm's during review. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Set out parameters to NULL in resolve_addr.cDavid Goulet
By doing this, a memory leak was found with "hostname_used" that could have been overwritten by another function. This commit changes that by making it a NULL string instead. Found by nickm's review. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Safeguard last resolved address index accessDavid Goulet
The last resolved address cache uses an index that is mapped to an address family (AF_INET and AF_INET6). This commit adds a conversion function from af to index and change the code to use that all the time only. In the process, this commit fixes a bug that the last resolved address accessors were using the af value insted of the index. Spotted by nickm during review Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Remove resolve_my_address_v4()David Goulet
Replace it by find_my_address() everywhere. This changes many parts of the code that uses it to use a tor_addr_t instead of a plain uint32_t for IPv4. Many changes to the unit test to also use the new interface. Part #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Refactor is_local_addr() to support IPv6David Goulet
Series of changes: 1. Rename function to reflect the namespace of the file. 2. Use the new last resolved cache instead of the unused last_resolved_addr_v4 (which is also removed in this commit). 3. Make the entire code base use the new resolved_addr_is_local() function. You will notice that this function uses /24 to differentiate subnets where the rest of tor uses /16 (including documentation of EnforceDistinctSubnets). Ticket #40009 has been opened for that. But that the moment, the function keeps looking at /24. Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Refactor last resolved address cache accessorsDavid Goulet
Series of things done in this commit: 1. Rename the functions to better reflect the namespace of the file. 2. Make both reset and get function to operate on the last_resolved_addrs cache that is per family. 3. Make the get function to take a tor_addr_t. 4. Change all callsite to use the new convention. Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: Make resolve_my_address_v4() use find_my_address()David Goulet
In order to transition smoothly, maek resolve_my_address_v4() call the new fancy find_my_address() with AF_INET. Next commits should remove the use of resolve_my_address_v4() accross the code to use find_my_address(). This commit is so the unit tests would be more easily fixed and port to the new find_my_address() internals. Part of #33233. Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-24addr: New find_my_address() to support multiple address familiesDavid Goulet
resolve_my_address() was beyond repair in terms of refactoring. Way too complex and doing too many things. This commit implements find_my_address() which in theory does the same as resolve_my_address() but in a more clean, concise and modern way using the tor_addr_t interface and for multiple address family. The caller needs to pass the address family (IPv4 or IPv6) which this interface supports. For both, a last resolved cache is used as well. Implements #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-23addr: Rename last_resolved_addr to be v4 specificDavid Goulet
Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-23addr: Rename resolve_my_address to be v4 specificDavid Goulet
Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-23config: Change Address to be a LINELISTDavid Goulet
With prop312, we want to support IPv4 and IPv6 thus multiple Address statement (up to 2) will be accepted. For this, "Address" option becomes a LINELIST so we can properly process the IPv4 or/and IPv6. Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
2020-06-05Merge remote-tracking branch 'tor-github/pr/1902/head'Nick Mathewson
2020-06-01config: Add IPv4 Address config debug loggingc
Per ticket #32888 this should address logging "the Address torrc option", "and whether it is an IP address, or a DNS name"; or the detected "local hostname", "and whether it is an IP address, or a DNS name". Some of these details already seem to be logged, so just add what's missing.
2020-05-21Check for NULL from tor_dup_ip()rl1987
2020-05-05config: New file resolve_addr.{c|h}David Goulet
Move a series of function from config.c into that new file which is related to address resolving. Part of #33789 Signed-off-by: David Goulet <dgoulet@torproject.org>