Skip to content

Commit 297131a

Browse files
authored
addition of a fuzzing client and subsequent rewrite of parts of the network communication and SSL detection
Addition of a fuzzing client and subsequent rewrite of parts of the network communication and SSL detection in order to be more robust against horribly incorrect input from the client Authored-by: Bruggeman, Otto G <[email protected]>
1 parent 94f160a commit 297131a

7 files changed

+719
-280
lines changed

src/debug.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ namespace debug {
3232
template<typename LVL, typename PF, typename F, typename L, typename... Args>
3333
void dyn_debug_output( std::ostream& out, LVL level, PF pretty_function, F file, L line, Args... args ) {
3434
std::stringstream ss;
35+
auto now = time(nullptr);
3536
ss << "DBG(" << std::dec << level << "): File '" << file << "', line '" << std::dec << line << "' :\n";
3637
ss << "DBG(" << std::dec << level << "): " << pretty_function << ":\n";
37-
ss << "DBG(" << std::dec << level << "): "; // Next code line will continue printing on this output line
38+
ss << "DBG(" << std::dec << level << ") " << std::put_time( localtime(&now), "%F_%T: " ); // Next code line will continue printing on this output line
3839
dyn_debug_output_helper( ss, args... );
3940
out << ss.str() << std::flush;
4041
}
@@ -57,6 +58,6 @@ namespace debug {
5758

5859
#define DBG( level, ... ) \
5960
if ( debug::currentDebugLevel >= level ) \
60-
debug::dyn_debug_output( std::cout, level, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
61+
debug::dyn_debug_output( std::cerr, level, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
6162

6263
} // namespace pcm

src/pcm-sensor-server.cpp

+608-191
Large diffs are not rendered by default.

src/threadpool.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ void ThreadPool::execute( ThreadPool* tp ) {
1111
Work* w = tp->retrieveWork();
1212
if ( w == nullptr ) break;
1313
w->execute();
14-
deleteAndNullify(w);
14+
// There can never be a double delete here, once taken from the tp it is owned by this thread
15+
// but in order to silence cppcheck w is set explicitly to null
16+
deleteAndNullify( w );
17+
DBG( 5, "Work deleted, waiting for more work..." );
1518
}
19+
DBG( 4, "Thread is explicitly dying now..." );
1620
}
1721

1822
} // namespace pcm

src/threadpool.h

+24-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ThreadPool {
5555
ThreadPool & operator = ( ThreadPool const& ) = delete;
5656

5757
public:
58-
~ThreadPool() {
58+
void emptyThreadPool( void ) {
5959
try {
6060
for (size_t i = 0; i < threads_.size(); ++i)
6161
addWork(nullptr);
@@ -69,28 +69,33 @@ class ThreadPool {
6969
}
7070
}
7171

72+
~ThreadPool() {
73+
DBG( 5, "Threadpool is being deleted..." );
74+
emptyThreadPool();
75+
}
76+
7277
public:
7378
static ThreadPool& getInstance() {
7479
static ThreadPool tp_(64);
7580
return tp_;
7681
}
7782

7883
void addWork( Work* w ) {
79-
DBG( 3, "WQ: Adding work" );
84+
DBG( 5, "WQ: Adding work" );
8085
std::lock_guard<std::mutex> lg( qMutex_ );
8186
workQ_.push( w );
8287
queueCV_.notify_one();
83-
DBG( 3, "WQ: Work available" );
88+
DBG( 5, "WQ: Work available" );
8489
}
8590

8691
Work* retrieveWork() {
87-
DBG( 3, "WQ: Retrieving work" );
92+
DBG( 5, "WQ: Retrieving work" );
8893
std::unique_lock<std::mutex> lock( qMutex_ );
8994
queueCV_.wait( lock, [this]{ return !workQ_.empty(); } );
9095
Work* w = workQ_.front();
9196
workQ_.pop();
9297
lock.unlock();
93-
DBG( 3, "WQ: Work retrieved" );
98+
DBG( 5, "WQ: Work retrieved" );
9499

95100
return w;
96101
}
@@ -111,12 +116,23 @@ class ThreadPool {
111116
};
112117

113118
class WorkQueue {
114-
public:
115-
WorkQueue() : tp_( ThreadPool::getInstance() ), workProcessed_(0) {}
119+
private:
120+
WorkQueue( size_t init ) : tp_( ThreadPool::getInstance() ), workProcessed_( init ) {
121+
DBG( 5, "Constructing WorkQueue..." );
122+
}
116123
WorkQueue( WorkQueue const& ) = delete;
117124
WorkQueue & operator = ( WorkQueue const& ) = delete;
118-
~WorkQueue() = default;
119125

126+
public:
127+
~WorkQueue() {
128+
DBG( 5, "Destructing WorkQueue..." );
129+
}
130+
131+
public:
132+
static WorkQueue* getInstance() {
133+
static WorkQueue wq_( 0 );
134+
return &wq_;
135+
}
120136
// Just forwarding to the threadpool
121137
void addWork( Work* w ) {
122138
++workProcessed_;

src/topology.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,4 @@ void Aggregator::dispatch( SystemRoot const& syp ) {
102102
readAccelCounters(sycs_);
103103
}
104104

105-
Aggregator::Aggregator()
106-
{
107-
PCM* const pcm = PCM::getInstance();
108-
// Resize user provided vectors to the right size
109-
ccsVector_.resize( pcm->getNumCores() );
110-
socsVector_.resize( pcm->getNumSockets() );
111-
// Internal use only, need to be the same size as the user provided vectors
112-
ccsFutures_.resize( pcm->getNumCores() );
113-
ucsFutures_.resize( pcm->getNumSockets() );
114-
}
115-
116105
}// namespace pcm

src/topology.h

+19-9
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,20 @@ class SystemRoot : public SystemObject {
451451
class Aggregator : Visitor
452452
{
453453
public:
454-
Aggregator();
455-
virtual ~Aggregator() {}
454+
Aggregator() : wq_( WorkQueue::getInstance() )
455+
{
456+
PCM* const pcm = PCM::getInstance();
457+
// Resize user provided vectors to the right size
458+
ccsVector_.resize( pcm->getNumCores() );
459+
socsVector_.resize( pcm->getNumSockets() );
460+
// Internal use only, need to be the same size as the user provided vectors
461+
ccsFutures_.resize( pcm->getNumCores() );
462+
ucsFutures_.resize( pcm->getNumSockets() );
463+
}
464+
465+
virtual ~Aggregator() {
466+
wq_ = nullptr;
467+
}
456468

457469
public:
458470
virtual void dispatch( SystemRoot const& syp ) override;
@@ -465,17 +477,15 @@ class Aggregator : Visitor
465477
// Fetch UncoreCounterState async result
466478
auto job = new LambdaJob<UncoreCounterState>(
467479
[]( Socket* s ) -> UncoreCounterState {
468-
DBG( 3, "Lambda fetching UncoreCounterState async" );
480+
DBG( 5, "Lambda fetching UncoreCounterState async" );
469481
UncoreCounterState ucs;
470482
if ( !s->isOnline() )
471483
return ucs;
472484
return s->uncore()->uncoreCounterState();
473485
}, sop
474486
);
475487
ucsFutures_[ sop->socketID() ] = job->getFuture();
476-
wq_.addWork( job );
477-
// For now execute directly to compile test
478-
//job->execute();
488+
wq_->addWork( job );
479489
}
480490

481491
virtual void dispatch( Core* cop ) override {
@@ -492,15 +502,15 @@ class Aggregator : Visitor
492502
// std::cerr << "Dispatch htp with osID=" << htp->osID() << "\n";
493503
auto job = new LambdaJob<CoreCounterState>(
494504
[]( HyperThread* h ) -> CoreCounterState {
495-
DBG( 3, "Lambda fetching CoreCounterState async" );
505+
DBG( 5, "Lambda fetching CoreCounterState async" );
496506
CoreCounterState ccs;
497507
if ( !h->isOnline() )
498508
return ccs;
499509
return h->coreCounterState();
500510
}, htp
501511
);
502512
ccsFutures_[ htp->osID() ] = job->getFuture();
503-
wq_.addWork( job );
513+
wq_->addWork( job );
504514
}
505515

506516
virtual void dispatch( ServerUncore* /*sup*/ ) override {
@@ -528,13 +538,13 @@ class Aggregator : Visitor
528538
}
529539

530540
private:
541+
WorkQueue* wq_;
531542
std::vector<CoreCounterState> ccsVector_;
532543
std::vector<SocketCounterState> socsVector_;
533544
SystemCounterState sycs_;
534545
std::vector<std::future<CoreCounterState>> ccsFutures_;
535546
std::vector<std::future<UncoreCounterState>> ucsFutures_;
536547
std::chrono::steady_clock::time_point dispatchedAt_{};
537-
WorkQueue wq_;
538548
};
539549

540550
} // namespace pcm

0 commit comments

Comments
 (0)