Skip to content

Instantly share code, notes, and snippets.

From 64f9c91766cbcaa8a61e5b633ac78e354ac3355c Mon Sep 17 00:00:00 2001
From: Azat Khuzhin <a3at.mail@gmail.com>
Date: Mon, 31 Jan 2022 19:14:53 +0300
Subject: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with
INTERP) binaries
Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
and this breaks PIE binaries, since after this change data segment
became too nearby the stack:
#include <vector>
#include <memory>
#include <benchmark/benchmark.h>
#define LEN 1<<20
using AggregateDataPtr = char *;
struct AvgState {
uint64_t numerator{0};
uint64_t denominator{0};
$ docker run --rm --name ch -v zzz-cluster.xml:/etc/clickhouse-server/config.d/zzz-cluster.xml:ro -it yandex/clickhouse-server:20.8
# 2021.11.19 14:47:23.804900 [ 1 ] {} <Information> : Starting ClickHouse 20.8.19.4 with revision 54438, build id: C4778BE3F258FC00, PID 1
$ docker exec -i ch clickhouse client -nm --testmode < test.sql
/* Minimal exapmle of static jemalloc.
*
* $ gcc -g3 -o main main.cpp -Wl,-Bstatic -ljemalloc_pic -Wl,-Bdynamic -nodefaultlibs -lc -lpthread -ldl -lgcc
* (or if you have only libjemalloc.a then -ljemalloc)
* NOTE: order is important
*
* $ ldd main
* linux-vdso.so.1 (0x00007ffff7fcb000)
* libc.so.6 => /usr/lib/libc.so.6 (0x00007ffff7b22000)
* libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007ffff7b01000)
fgrep -e EOF -e 'to pull' test_attach_without_fetching_test_py_0_dockerd.log
time="2021-08-30T21:23:52.359898277+03:00" level=debug msg="Trying to pull yandex/clickhouse-integration-test from http://dockerhub-proxy.sas.yp-c.yandex.net:5000/ v2"
time="2021-08-30T21:23:52.790020329+03:00" level=info msg="Download failed, retrying (1/5): unexpected EOF"
time="2021-08-30T21:23:52.790055852+03:00" level=info msg="Download failed, retrying (1/5): unexpected EOF"
time="2021-08-30T21:23:53.135745179+03:00" level=info msg="Download failed, retrying (1/5): unexpected EOF"
time="2021-08-30T21:23:57.805630607+03:00" level=info msg="Download failed, retrying (2/5): unexpected EOF"
time="2021-08-30T21:23:57.805667990+03:00" level=info msg="Download failed, retrying (2/5): unexpected EOF"
time="2021-08-30T21:23:58.153682401+03:00" level=info msg="Download failed, retrying (2/5): unexpected EOF"
time="2021-08-30T21:24:07.825100818+03:00" level=info msg="Download failed, retrying (3/5): unexpected EOF"
time="2021-08-30T21:24:
@azat
azat / 0001-Fix-always-false-check-in-evaluateConstantExpression.patch
Created August 9, 2021 20:48
[PATCH] Fix always false check in evaluateConstantExpression
From 111f1566e13efd03c4b72b2325b2254284d17fe8 Mon Sep 17 00:00:00 2001
From: Azat Khuzhin <a3at.mail@gmail.com>
Date: Mon, 9 Aug 2021 23:23:39 +0300
Subject: [PATCH] Fix always false check in evaluateConstantExpression
---
.../evaluateConstantExpression.cpp | 22 +++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/Interpreters/evaluateConstantExpression.cpp b/src/Interpreters/evaluateConstantExpression.cpp
/// Test case for alternative stack overflow in TLS
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <csignal>
#include <cassert>
#include <string>
#include <algorithm>
#include <thread>
/// Based on https://bugzilla.redhat.com/show_bug.cgi?id=178986#c1
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
2021.04.29 09:58:46.288464 [ 4496 ] {e2ef9d81-db30-465f-9286-d134ea77513f} <Debug> executeQuery: (from 127.0.0.1:40464, using production parser) SELECT [1, 2, 3, 11] = arraySort(multiMatchAllIndices('фабрикант', ['', 'рикан', 'а', 'f[a27844e]b[ei]rl', 'ф[иа27475эе]б[еэи][рпл]', 'афиукд', 'a[f6564t],th', '^ф[аие3965э]?б?[еэи]?$', 'бе22501рлик', 'fa32369b', 'фа[беьв]+е?[рл17534ко]']))
==4450==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x2668d831 in boost::container::vector_alloc_holder<boost::container::small_vector_allocator<std::__1::pair<unsigned char, unsigned char>, std::__1::allocator<void> >, unsigned long, boost::move_detail::integral_constant<unsigned int, 1u> >::~vector_alloc_holder() /src/ch/clickhouse/.cmake-msan/../contrib/boost/boost/container/vector.hpp:410:10
#1 0x2668d831 in boost::container::vector<std::__1::pair<unsigned char, unsigned char>, boost::container::small_vector_allocator<std::__1::pair<unsigned char, unsigned char>, std::__1::allocator<void> >, void>::~vector(
/// clang++ -O2 -g3 -isystem /src/ch/clickhouse/contrib/boost -fsanitize-memory-track-origins -fsanitize=memory test-msan-3.cpp -o test-msan-3; MSAN_OPTIONS='abort_on_error=1 poison_in_dtor=1' ./test-msan-3
/// clang++ -O2 -g3 -fsanitize-memory-track-origins -fsanitize=memory test-msan-3.cpp -o test-msan-3; MSAN_OPTIONS='abort_on_error=1 poison_in_dtor=1' ./test-msan-3
#include <boost/container/small_vector.hpp>
#include <algorithm>
template <class T, std::size_t N,
typename Allocator = boost::container::new_allocator<T>>
using small_vector = boost::container::small_vector<T, N, Allocator>;