Commit Graph

289 Commits

Author SHA1 Message Date
Micah Elizabeth Scott
cfbf74352f More fixes for compile-time warnings in equix and hashx
This addresses issue #40800 and a couple other problems I noticed while
trying to reproduce that one.

The original issue is just a missing cast to void* on the args of
__builtin___clear_cache(), and clang is picky about the implicit cast
between what it considers to be char of different signedness. Original
report is from MacOS but it's also reproducible on other clang targets.

The cmake-based original build system for equix and hashx was a handy
way to run tests, but it suffered from some warnings due to incorrect
application of include_directories().

And lastly, there were some return codes from hashx_exec() that get
ignored on equix when asserts are disabled. It bugged me too much to
just silence this with a (void) cast, since even though this is in the
realm of low-likelyhood programming errors and not true runtime errors, I
don't want to make it easy for the hashx_exec() wrappers to return
values that are dangerously wrong if an error is ignored. I made sure
that even if asserts are disabled, we return values that will cause the
solver and verifier to both fail to validate a potential solution.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-06-05 11:45:33 -07:00
Micah Elizabeth Scott
a3513dea54 equix: API changes for new result codes and hashx compatibility
This change adapts Equi-X to the corresponding HashX API changes that
added HASHX_TRY_COMPILE. The new regularized HashX return codes are
reflected by revised corresponding Equi-X return codes.

Both solve and verify operations now return an error/success code, and a
new equix_solutions_buffer struct includes both the solution buffer
and information about the solution count and hashx implementation.

With this change, it's possible to discern between hash construction
failures (invalid seed) and some external error like an mprotect()
failure.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-28 20:02:02 -07:00
Micah Elizabeth Scott
5a4f92ea7b hashx: API changes to allow recovery from late compile failures
This is an API breaking change to hashx, which modifies the error
handling strategy. The main goal here is to allow unproblematic
recovery from hashx_compile failures.

hashx_alloc can no longer fail for reasons other than memory
allocation. All platform-specific compile failures are now reported via
hashx_make(), in order to both allow later failure and avoid requiring
users of the API to maintain and test multiple failure paths.

Note that late failures may be more common in actual use than early
failures. Early failures represent architectures other than x86_64 and
aarch64. Late failures could represent a number of system configurations
where syscalls are restricted.

The definition of a hashx context no longer tries to overlay storage for
the different types of program, and instead allows one context to always
contain an interpretable description of the program as well as an optional
buffer for compiled code.

The hashx_type enum is now used to mean either a specific type of hash
function or a type of hashx context. You can allocate a context for use
only with interpreted or compiled functions, or you can use
HASHX_TRY_COMPILE to prefer the compiler with an automatic fallback on
the interpreter. After calling hashx_make(), the new hashx_query_type()
can be used if needed to determine which implementation was actually
chosen.

The error return types have been overhauled so that everyone uses the
hashx_result enum, and seed failures vs compile failures are always
clearly distinguishable.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-28 20:02:02 -07:00
Micah Elizabeth Scott
6fd5ca4914 hashx: allow hashx_compile to fail, avoid segfault without changing API
This is a minimal portion of the fix for tor issue #40794, in which
hashx segfaults due to denial of mprotect() syscalls at runtime.

Prior to this fix, hashx makes the assumption that if the JIT is
supported on the current architecture, it will also be usable at
runtime. This isn't true if mprotect fails on linux, which it may for
various reasons: the tor built-in sandbox, the shadow simulator, or
external security software that implements a syscall filter.

The necessary error propagation was missing internally in hashx,
causing us to obliviously call into code which was never made
executable. With this fix, hashx_make() will instead fail by returning
zero.

A proper fix will require API changes so that callers can discern
between different types of failures. Zero already means that a program
couldn't be constructed, which requires a different response: choosing a
different seed, vs switching implementations. Callers would also benefit
from a way to use one context (with its already-built program) to
run in either compiled or interpreted mode.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-28 19:54:50 -07:00
Micah Elizabeth Scott
941613c663 hashx: minor, another logical operator change
The code style in equix and hashx sometimes uses bitwise operators
in place of logical ones in cases where it doesn't really matter
either way. This sometimes annoys our static analyzer tools.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-28 19:54:50 -07:00
Micah Elizabeth Scott
c71b6a14a3 equix: avoid a coverity warning in hashx_alloc()
This addresses one of the warnings in issue #40792. As far as I can tell
this is a false positive, since the use of "ctx->type" in hashx_free()
can only be hit after the unioned code/program pointer is non-NULL. It's
no big deal to zero this value explicitly to silence the warning though.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-11 11:10:15 -07:00
Micah Elizabeth Scott
0c11411f35 hashx: trim trailing whitespace
Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10 07:38:28 -07:00
Micah Elizabeth Scott
ae86d98815 equix: Portability fixes for big endian platforms
Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10 07:38:28 -07:00
Micah Elizabeth Scott
daa08557ad equix: Build cleanly with -Wall -Werror
Fixes some type nitpicks that show up in Tor development builds,
which usually run with -Wall -Werror. Tested on x86_64 and aarch64
for clean build and passing equix-tests + hashx-tests.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10 07:38:28 -07:00
Micah Elizabeth Scott
246ced3a8c ext: build equix and hashx using automake
This replaces the sketchy cmake invocation we had inside configure

The libs are always built and always used in unit tests, but only
included in libtor and tor when --enable-gpl is set.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10 07:38:28 -07:00
Micah Elizabeth Scott
bfa2102c95 hs_pow: Replace libb2 dependency with hashx's internal blake2
This forgoes another external library dependency, and instead
introduces a compatibility header so that interested parties
(who already depend on equix, like hs_pow and unit tests) can
use the implementation of blake2b included in hashx.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10 07:38:28 -07:00
Micah Elizabeth Scott
ffa8531fe0 test_crypto: add equix and hashx tests
This adds test vectors for the Equi-X proof of work algorithm and the
Hash-X function it's based on. The overall Equi-X test takes about
10 seconds to run on my machine, so it's in test_crypto_slow. The hashx
test still covers both the compiled and interpreted versions of the
hash function.

There aren't any official test vectors for Equi-X or for its particular
configuration of Hash-X, so I made some up based on the current
implementation.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-05-10 07:38:28 -07:00
David Goulet
95445f49f1 ext: Add Equi-X library
Signed-off-by: David Goulet <dgoulet@torproject.org>
2023-05-10 07:37:10 -07:00
Alex Xu (Hello71)
65ea7eed1f Remove broken MSVC support
MSVC compilation has been broken since at least 1e417b7275 ("All remaining
files in src/common belong to the event loop.") deleted
src/common/Makefile.nmake in 2018.
2022-04-27 23:09:44 -04:00
Hans-Christoph Steiner
a86918d524 fix syntax errors listed by cppcheck 2021-12-16 10:21:18 +01:00
David Goulet
d0d3b028d5 Remove last artifacts of Rust related code
Signed-off-by: David Goulet <dgoulet@torproject.org>
2021-10-06 15:12:04 -04:00
David Goulet
d45354d5ea Merge branch 'tor-gitlab/mr/243' into maint-0.4.5 2020-12-17 08:25:18 -05:00
George Kadianakis
d89974c5c6 Fix Keccak undefined behavior on exotic platforms.
Bug reported and diagnosed in:
    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=975977

Fixes bug #40210.
2020-12-17 13:49:17 +02:00
Samanta Navarro
4a0cd79588 Fix typos.
Typos found with codespell.

Please keep in mind that this should have impact on actual code
and must be carefully evaluated:

src/core/or/lttng_circuit.inc
-    ctf_enum_value("CONTROLER", CIRCUIT_PURPOSE_CONTROLLER)
+    ctf_enum_value("CONTROLLER", CIRCUIT_PURPOSE_CONTROLLER)
2020-11-12 11:44:09 -05:00
Neel Chauhan
b16d82043c Include crypto_rand.h in ed25519_tor.c 2020-08-23 06:05:08 -07:00
Nick Mathewson
b0a716dfb0 Move description of ext contents into an md file.
This way, doxygen can include it.
2020-07-02 13:46:25 -04:00
Nick Mathewson
fbf8bda30b Mention that src/ext should not be edited lightly.
Closes #32661
2020-07-02 13:38:17 -04:00
Nick Mathewson
4a2347d290 Merge branch 'maint-0.4.3'
Amazingly, this time we had no merge conflicts with "falls through" comments.
2020-05-06 16:55:41 -04:00
Nick Mathewson
c116728209 Use __attribute__((fallthrough)) rather than magic GCC comments.
GCC added an implicit-fallthrough warning a while back, where it
would complain if you had a nontrivial "case:" block that didn't end
with break, return, or something like that.  Clang recently added
the same thing.

GCC, however, would let you annotate a fall-through as intended by
any of various magic "/* fall through */" comments.  Clang, however,
only seems to like "__attribute__((fallthrough))".  Fortunately, GCC
accepts that too.

A previous commit in this branch defined a FALLTHROUGH macro to do
the right thing if GNUC is defined; here we replace all of our "fall
through" comments with uses of that macro.

This is an automated commit, made with the following perl one-liner:

  #!/usr/bin/perl -i -p
  s#/\* *falls? ?thr.*?\*/#FALLTHROUGH;#i;

(In order to avoid conflicts, I'm applying this script separately to
each maint branch. This is the 0.4.3 version.)
2020-05-06 16:55:25 -04:00
Nick Mathewson
cc397449fc Use __attribute__((fallthrough)) rather than magic GCC comments.
GCC added an implicit-fallthrough warning a while back, where it
would complain if you had a nontrivial "case:" block that didn't end
with break, return, or something like that.  Clang recently added
the same thing.

GCC, however, would let you annotate a fall-through as intended by
any of various magic "/* fall through */" comments.  Clang, however,
only seems to like "__attribute__((fallthrough))".  Fortunately, GCC
accepts that too.

A previous commit in this branch defined a FALLTHROUGH macro to do
the right thing if GNUC is defined; here we replace all of our "fall
through" comments with uses of that macro.

This is an automated commit, made with the following perl one-liner:

  #!/usr/bin/perl -i -p
  s#/\* *falls? ?thr.*?\*/#FALLTHROUGH;#i;
2020-05-06 16:51:11 -04:00
Nick Mathewson
82effefb69 Merge branch 'maint-0.4.3' 2020-05-06 16:47:03 -04:00
Nick Mathewson
fecc5fd38d Merge branch 'maint-0.4.2' into maint-0.4.3 2020-05-06 16:47:03 -04:00
Nick Mathewson
d04b708b4b Merge branch 'maint-0.4.1' into maint-0.4.2 2020-05-06 16:47:03 -04:00
Nick Mathewson
3e42464f5a Merge branch 'bug34078_prelim_035' into bug34078_prelim_041 2020-05-06 15:18:36 -04:00
Nick Mathewson
37b8324ed3 include compat_compiler for ed25519_donna 2020-05-06 15:08:02 -04:00
Nick Mathewson
a9cc4ce0eb ht.h: Require a semicolon after HT_PROTOTYPE and HT_GENERATE[2] 2020-02-10 12:54:06 -05:00
cclauss
3208a74f90 Use print() function in both Python 2 and Python 3 2020-01-28 01:38:54 +01:00
Nick Mathewson
c4ac5adc4a siphash.h: include stdint.
Doing this gives us a valid uint64_t type, freeing us from
dependencies on include order.
2020-01-09 07:30:35 -05:00
Nick Mathewson
7b0d8834f2 Use raw_assert in ht.h
Also, include torerr.h from ht.h if we are using raw_assert.

Otherwise, our includes need to be ordered so that ht.h comes after
util_log.h.
2020-01-09 07:30:35 -05:00
Nick Mathewson
73b83b8f1a Remove extra ; from tt_assert() macro definition.
We were actually omitting the semicolon in a few places, leading to
confusing indentation and some cocci failures.
2020-01-09 07:30:35 -05:00
teor
0bb879e821
src/ext: Add __future__ imports for python 3 compatibility
Closes ticket 32732.
2019-12-12 15:59:47 +10:00
Nick Mathewson
cf22841e3b ht.h: improve documentation for HT_NEXT_RMV. 2019-11-21 11:56:42 -05:00
Nick Mathewson
4845ab53f0 Make all our struct names end with "_t".
This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        address_ttl_s address_ttl_t \
        aes_cnt_cipher aes_cnt_cipher_t \
        authchallenge_data_s authchallenge_data_t \
        authenticate_data_s authenticate_data_t \
        cached_bw_event_s cached_bw_event_t \
        cbuf cbuf_t \
        cell_ewma_s cell_ewma_t \
        certs_data_s certs_data_t \
        channel_idmap_entry_s channel_idmap_entry_t \
        channel_listener_s channel_listener_t \
        channel_s channel_t \
        channel_tls_s channel_tls_t \
        circuit_build_times_s circuit_build_times_t \
        circuit_muxinfo_s circuit_muxinfo_t \
        circuitmux_policy_circ_data_s circuitmux_policy_circ_data_t \
        circuitmux_policy_data_s circuitmux_policy_data_t \
        circuitmux_policy_s circuitmux_policy_t \
        circuitmux_s circuitmux_t \
        coord coord_t \
        cpuworker_job_u cpuworker_job_u_t \
        cv_testinfo_s cv_testinfo_t \
        ddmap_entry_s ddmap_entry_t \
        dircollator_s dircollator_t \
        dist_ops dist_ops_t \
        ecdh_work_s ecdh_work_t \
        ewma_policy_circ_data_s ewma_policy_circ_data_t \
        ewma_policy_data_s ewma_policy_data_t \
        fp_pair_map_entry_s fp_pair_map_entry_t \
        fp_pair_map_s fp_pair_map_t \
        guard_selection_s guard_selection_t \
        mbw_cache_entry_s mbw_cache_entry_t \
        outbuf_table_ent_s outbuf_table_ent_t \
        queued_event_s queued_event_t \
        replyqueue_s replyqueue_t \
        rsa_work_s rsa_work_t \
        sandbox_cfg_elem sandbox_cfg_elem_t \
        scheduler_s scheduler_t \
        smp_param smp_param_t \
        socket_table_ent_s socket_table_ent_t \
        state_s state_t \
        threadpool_s threadpool_t \
        timeout_cb timeout_cb_t \
        tor_libevent_cfg tor_libevent_cfg_t \
        tor_threadlocal_s tor_threadlocal_t \
        url_table_ent_s url_table_ent_t \
        worker_state_s worker_state_t \
        workerthread_s workerthread_t \
        workqueue_entry_s workqueue_entry_t
2019-11-07 08:41:22 -05:00
Nick Mathewson
f55598f870 Coverity: different implementation for csiphash
Coverity has had trouble figuring out our csiphash implementation,
and has given spurious warnings about its behavior.

This patch changes the csiphash implementation when coverity is in
use, so that coverity can figure out that we are not about to read
beyond the provided input.

Closes ticket 31025.
2019-06-28 12:07:38 -04:00
David Goulet
c1359b32a4 trunnel: Rename sendme.trunnel to sendme_cell.trunnel
This is to avoid having two sendme.{c|h} in the repository since the subsystem
is implemented in src/core/or/sendme.{c|h}.

Fixes #30769

Signed-off-by: David Goulet <dgoulet@torproject.org>
2019-06-11 14:11:10 +03:00
Nick Mathewson
e4feb4ad01 Give tinytest a function to say whether the current test has failed 2019-05-15 07:50:56 -04:00
Nick Mathewson
3be1e26b8d Merge branch 'maint-0.4.0' 2019-04-10 11:31:44 -04:00
Nick Mathewson
412bcc5b2a Merge remote-tracking branch 'tor-github/pr/926' into maint-0.4.0 2019-04-10 11:31:33 -04:00
Tobias Stoeckmann
9ce0bdd226 Prevent double free on huge files with 32 bit.
The function compat_getdelim_ is used for tor_getline if tor is compiled
on a system that lacks getline and getdelim. These systems should be
very rare, considering that getdelim is POSIX.

If this system is further a 32 bit architecture, it is possible to
trigger a double free with huge files.

If bufsiz has been already increased to 2 GB, the next chunk would
be 4 GB in size, which wraps around to 0 due to 32 bit limitations.

A realloc(*buf, 0) could be imagined as "free(*buf); return malloc(0);"
which therefore could return NULL. The code in question considers
that an error, but will keep the value of *buf pointing to already
freed memory.

The caller of tor_getline() would free the pointer again, therefore
leading to a double free.

This code can only be triggered in dirserv_read_measured_bandwidths
with a huge measured bandwith list file on a system that actually
allows to reach 2 GB of space through realloc.

It is not possible to trigger this on Linux with glibc or other major
*BSD systems even on unit tests, because these systems cannot reach
so much memory due to memory fragmentation.

This patch is effectively based on the penetration test report of
cure53 for curl available at https://cure53.de/pentest-report_curl.pdf
and explained under section "CRL-01-007 Double-free in aprintf() via
unsafe size_t multiplication (Medium)".
2019-04-10 12:46:27 +03:00
Nick Mathewson
c66df27c90 Fix checkIncludes warning about "unusual pattern in src/ext/timeouts/"
Closes ticket 28806.
2019-03-28 16:35:24 -04:00
Nick Mathewson
c393171403 Use openssl's version of sha3 when available.
Part of 28837.
2019-01-17 12:43:20 -05:00
Nick Mathewson
2f683465d4 Bump copyright date to 2019 2019-01-16 12:33:22 -05:00
Nick Mathewson
efe55b8898 Bump copyright date to 2019. 2019-01-16 12:32:32 -05:00
Nick Mathewson
e6a4401200 Merge branch 'maint-0.3.5' 2019-01-09 08:52:10 -05:00
Kris Katterjohn
c13a81f7f9 Fix (and make consistent) the use of OpenBSD preprocessor macro tests
Prior to this commit, the testsuite was failing on OpenBSD.  After
this commit the testsuite runs fine on OpenBSD.

It was previously decided to test for the OpenBSD macro (rather than
__OpenBSD__, etc.) because OpenBSD forks seem to have the former
macro defined.  sys/param.h must be included for the OpenBSD macro
definition; however, many files tested for the OpenBSD macro without
having this header included.

This commit includes sys/param.h in the files where the OpenBSD macro
is used (and sys/param.h is not already included), and it also
changes some instances of the __OpenBSD__ macro to OpenBSD.

See commit 27df23abb6 which changed
everything to use OpenBSD instead of __OpenBSD__ or OPENBSD.  See
also tickets #6982 and #20980 (the latter ticket is where it was
decided to use the OpenBSD macro).

Signed-off-by: Kris Katterjohn <katterjohn@gmail.com>
2019-01-09 08:51:57 -05:00