Repository navigation
[#689] Reject too long keys and values in conf set - #703
shubhamk0205 wants to merge 1 commit into
Conversation
cff6f1c to
1286b4f
Compare
Pranav-error
left a comment
There was a problem hiding this comment.
The same two memcpys still read out of bounds when there is nothing before/after a dot: conf set "" 1, conf set .host x and conf set primary. x leave begin == -1, so end - begin + 1 is 1, the new check passes and memcpy reads config_key[-1]. ASan on 1286b4f: heap-buffer-overflow READ at configuration.c:3145 / 3169 (same on main at 3139 / 3157). Could you reject begin < 0 before both copies (here or as a follow-up) and add these three keys to the test?
The >= checks for key and server name, and the as_bytes one, aren't pinned: the test still passes with > MISC_LENGTH / index >= MISC_LENGTH, while a 128 char key, a 128 char server name and a 128 digit size crash the worker with that change. Please add those three to the test.
Verified (macOS, ASan+UBSan Debug): new test fails on 801d41c (stack-buffer-overflow in as_milliseconds) and passes on 1286b4f, 3/3 each; removing any one of the four checks fails it; 127 digits accepted, 128 rejected. Not run: Linux.
1286b4f to
86f5f35
Compare
Fixes #689
conf setcopies the key and the digits of time/size values into 128 byte stack buffers without checking the length, so a long key or value overflows them and the management worker dies. The CLI prints nothing and exits with 1. The config file path was fixed for the same thing in #617, butconf settakes the text straight from the CLI.There was no reply on the issue, so I went with the simplest approach. Happy to change it:
as_milliseconds()andas_bytes()stop with the normal "invalid value" error once the number would not fit invalue[]. This also covers the 128 digit case, where only the terminating'\0'went past the end.pgexporter_conf_set()checks the length before copying the server name and the key. A too long server name gives "unknown server", a too long key gives "unknown configuration key", the same answers you get for names that don't exist.Added
test_configuration_reject_long_key_and_valuefor both value helpers, the 128 digit boundary, a long key and a long server name.Tested on Rocky Linux 10 (aarch64) with an ASan build: on main all five cases give
stack-buffer-overflow(configuration.c 3139, 3157, 5215, 5270, 5333). With the patch they return the normal error and ASan is quiet;conf set metrics_cache_max_age 30sstill works../clang-format.sh(21.1.8) makes no changes.test/check.sh ci(clang Debug): 242 pass, 6 timescaledb skips, no failures, then the run stops with a segfault intest_connection_bind_unix_socket_permissions. That happens on main too, and is the same segfault the Debug jobs on main currently show in CI. The test puts a wholestruct configuration(about 26 MB) on the stack, which is more than the 8 MB default. Can open a separate issue for it.pgagroal and pgmoneta have the same
value[index++]loop in their configuration.c (pgagroal also the key copy). I can cross-port once this one looks right.