limit unicast message rate per address and grant duration (RHEL-29738)

Resolves: RHEL-29738
This commit is contained in:
Miroslav Lichvar 2021-08-02 15:58:40 +02:00
parent 2c52fa21fd
commit c2449868f3
2 changed files with 54 additions and 1 deletions

45
linuxptp-ucastrate.patch Normal file
View File

@ -0,0 +1,45 @@
commit a36602f1e65cd6bace6ed9405b0ce359de4a27d1
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Jan 3 15:23:54 2019 +0100
unicast: limit message rate and grant duration
Deny service requests with logInterMessagePeriod smaller than -7 (128
packets per second) or larger than 16. This limits the network and CPU
consumption per address and prevents undefined shifts in the calculation
of the interval.
Also, limit the maximum grant duration to one hour.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/unicast_service.c b/unicast_service.c
index 9c9b95b..c6c17c6 100644
--- a/unicast_service.c
+++ b/unicast_service.c
@@ -31,6 +31,9 @@
#include "unicast_service.h"
#include "util.h"
+#define MIN_LOG_INTER_MESSAGE_PERIOD -7
+#define MAX_LOG_INTER_MESSAGE_PERIOD 16
+#define MAX_DURATION 3600
#define QUEUE_LEN 16
struct unicast_client_address {
@@ -289,6 +292,15 @@ int unicast_service_add(struct port *p, struct ptp_message *m,
return SERVICE_DENIED;
}
+ if (req->logInterMessagePeriod < MIN_LOG_INTER_MESSAGE_PERIOD ||
+ req->logInterMessagePeriod > MAX_LOG_INTER_MESSAGE_PERIOD) {
+ return SERVICE_DENIED;
+ }
+
+ if (req->durationField > MAX_DURATION) {
+ req->durationField = MAX_DURATION;
+ }
+
LIST_FOREACH(itmp, &p->unicast_service->intervals, list) {
/*
* Remember the interval of interest.

View File

@ -27,6 +27,9 @@ Source20: linuxptp.fc
Source21: linuxptp.if
Source22: linuxptp.te
# limit unicast message rate per address and grant duration
Patch1: linuxptp-ucastrate.patch
BuildRequires: gcc gcc-c++ make systemd
%{?systemd_requires}
@ -57,7 +60,12 @@ linuxptp SELinux policy module
%endif
%prep
%setup -q -a 10 -a 11 -n %{name}-%{!?gitfullver:%{version}}%{?gitfullver}
%autosetup -N
# autosetup doesn't accept multiple -a options
%__rpmuncompress -x %{SOURCE10}
%__rpmuncompress -x %{SOURCE11}
%autopatch -p1
mv linuxptp-testsuite-%{testsuite_ver}* testsuite
mv clknetsim-%{clknetsim_ver}* testsuite/clknetsim