attemping to fix possible shell code injection through GUI notifications
This commit is contained in:
parent
b910bf1b28
commit
53dbd40128
19
README.md
19
README.md
@ -89,17 +89,16 @@ optional arguments:
|
|||||||
|
|
||||||
The program can be configured by editing the [config file](https://github.com/hakavlad/nohang/blob/master/nohang.conf). The configuration includes the following sections:
|
The program can be configured by editing the [config file](https://github.com/hakavlad/nohang/blob/master/nohang.conf). The configuration includes the following sections:
|
||||||
|
|
||||||
- THRESHOLDS FOR SENDING SIGNALS
|
- Thresholds for sending signals to victims
|
||||||
- INTENSITY OF MONITORING (AND CPU USAGE)
|
- Intensity of monitoring (and CPU usage)
|
||||||
- PREVENTION OF KILLING INNOCENT VICTIMS
|
- Prevention of killing innocent victims
|
||||||
- AVOID AND PREFER VICTIM NAMES VIA REGEX
|
- Avoid and prefer victim names via regex matching
|
||||||
- EXECUTE THE COMMAND INSTEAD OF SENDING THE SIGTERM SIGNAL
|
- Execute the command instead of sending the SIGTERM signal
|
||||||
- GUI NOTIFICATIONS
|
- GUI notifications: results of preventing OOM and low memory warnings
|
||||||
- LOW MEMORY WARNINGS
|
- Self-defense and preventing slowing down the program
|
||||||
- SELF-DEFENSE AND PREVENTING SLOWING DOWN THE PROGRAM
|
- Output verbosity
|
||||||
- OUTPUT VERBOSITY
|
|
||||||
|
|
||||||
Just read the description of the parameters and edit the values. Run the command `sudo systemctl restart nohang` to apply changes. Default path to the config arter installing via `./install.sh` is `/etc/nohang/nohang.conf`.
|
Just read the description of the parameters and edit the values. Please restart nohang to apply changes. Default path to the config arter installing via `./install.sh` is `/etc/nohang/nohang.conf`.
|
||||||
|
|
||||||
### Feedback
|
### Feedback
|
||||||
|
|
||||||
|
13
nohang
13
nohang
@ -33,6 +33,8 @@ conf_err_mess = '\nSet up the path to the valid config file with -c/--confi' \
|
|||||||
# но это утверждение противоречит опытным данным
|
# но это утверждение противоречит опытным данным
|
||||||
zram_disksize_factor = 0.0042
|
zram_disksize_factor = 0.0042
|
||||||
|
|
||||||
|
name_strip_string = '\'"`\\!-$'
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
# function definition section
|
# function definition section
|
||||||
@ -199,7 +201,7 @@ def send_notify(signal, name, pid, oom_score, vm_rss, vm_swap):
|
|||||||
info = '"<u>Nohang</u> sent <u>{}</u> \nto the process <b>{}</b> \n<i>P' \
|
info = '"<u>Nohang</u> sent <u>{}</u> \nto the process <b>{}</b> \n<i>P' \
|
||||||
'id:</i> <b>{}</b> \n<i>Badness:</i> <b>{}</b> \n<i>VmRSS:</i> <b' \
|
'id:</i> <b>{}</b> \n<i>Badness:</i> <b>{}</b> \n<i>VmRSS:</i> <b' \
|
||||||
'>{} MiB</b> \n<i>VmSwap:</i> <b>{} MiB</b>" &'.format(
|
'>{} MiB</b> \n<i>VmSwap:</i> <b>{} MiB</b>" &'.format(
|
||||||
sig_dict[signal], name, pid, oom_score, vm_rss, vm_swap)
|
sig_dict[signal], name.strip(name_strip_string), pid, oom_score, vm_rss, vm_swap)
|
||||||
if root:
|
if root:
|
||||||
# отправляем уведомление всем залогиненным пользователям
|
# отправляем уведомление всем залогиненным пользователям
|
||||||
for uid in os.listdir('/run/user'):
|
for uid in os.listdir('/run/user'):
|
||||||
@ -227,7 +229,6 @@ def sleep_after_send_signal(signal):
|
|||||||
|
|
||||||
def find_victim_and_send_signal(signal):
|
def find_victim_and_send_signal(signal):
|
||||||
|
|
||||||
print('****')
|
|
||||||
print(mem_info)
|
print(mem_info)
|
||||||
|
|
||||||
# выставляем потолок для oom_score_adj всех процессов
|
# выставляем потолок для oom_score_adj всех процессов
|
||||||
@ -1320,7 +1321,7 @@ while True:
|
|||||||
# MEM SWAP KILL
|
# MEM SWAP KILL
|
||||||
if mem_available <= mem_min_sigkill_kb and swap_free <= swap_min_sigkill_kb:
|
if mem_available <= mem_min_sigkill_kb and swap_free <= swap_min_sigkill_kb:
|
||||||
|
|
||||||
mem_info = ' MemAvailable ({} MiB, {} %) < mem_min_sigkill ({} MiB, {} %)\n Swa' \
|
mem_info = '* MemAvailable ({} MiB, {} %) < mem_min_sigkill ({} MiB, {} %)\n Swa' \
|
||||||
'pFree ({} MiB, {} %) < swap_min_sigkill ({} MiB, {} %)'.format(
|
'pFree ({} MiB, {} %) < swap_min_sigkill ({} MiB, {} %)'.format(
|
||||||
kib_to_mib(mem_available),
|
kib_to_mib(mem_available),
|
||||||
percent(mem_available / mem_total),
|
percent(mem_available / mem_total),
|
||||||
@ -1339,7 +1340,7 @@ while True:
|
|||||||
# ZRAM KILL
|
# ZRAM KILL
|
||||||
elif mem_used_zram >= zram_max_sigkill_kb:
|
elif mem_used_zram >= zram_max_sigkill_kb:
|
||||||
|
|
||||||
mem_info = ' MemUsedZram ({} MiB, {} %) > zram_max_sigkill ({} MiB, {} %)'.format(
|
mem_info = '* MemUsedZram ({} MiB, {} %) > zram_max_sigkill ({} MiB, {} %)'.format(
|
||||||
kib_to_mib(mem_used_zram),
|
kib_to_mib(mem_used_zram),
|
||||||
percent(mem_used_zram / mem_total),
|
percent(mem_used_zram / mem_total),
|
||||||
kib_to_mib(zram_max_sigkill_kb),
|
kib_to_mib(zram_max_sigkill_kb),
|
||||||
@ -1350,7 +1351,7 @@ while True:
|
|||||||
# MEM SWAP TERM
|
# MEM SWAP TERM
|
||||||
elif mem_available <= mem_min_sigterm_kb and swap_free <= swap_min_sigterm_kb:
|
elif mem_available <= mem_min_sigterm_kb and swap_free <= swap_min_sigterm_kb:
|
||||||
|
|
||||||
mem_info = ' MemAvailable ({} MiB, {} %) < mem_min_sigterm ({} MiB, {} %)\n Sw' \
|
mem_info = '* MemAvailable ({} MiB, {} %) < mem_min_sigterm ({} MiB, {} %)\n Sw' \
|
||||||
'apFree ({} MiB, {} %) < swap_min_sigterm ({} MiB, {} %)'.format(
|
'apFree ({} MiB, {} %) < swap_min_sigterm ({} MiB, {} %)'.format(
|
||||||
kib_to_mib(mem_available),
|
kib_to_mib(mem_available),
|
||||||
percent(mem_available / mem_total),
|
percent(mem_available / mem_total),
|
||||||
@ -1374,7 +1375,7 @@ while True:
|
|||||||
# ZRAM TERM
|
# ZRAM TERM
|
||||||
elif mem_used_zram >= zram_max_sigterm_kb:
|
elif mem_used_zram >= zram_max_sigterm_kb:
|
||||||
|
|
||||||
mem_info = ' MemUsedZram ({} MiB, {} %) > zram_max_sigter' \
|
mem_info = '* MemUsedZram ({} MiB, {} %) > zram_max_sigter' \
|
||||||
'm ({} M, {} %)'.format(
|
'm ({} M, {} %)'.format(
|
||||||
kib_to_mib(mem_used_zram),
|
kib_to_mib(mem_used_zram),
|
||||||
percent(mem_used_zram / mem_total),
|
percent(mem_used_zram / mem_total),
|
||||||
|
40
nohang.conf
40
nohang.conf
@ -5,13 +5,12 @@
|
|||||||
|
|
||||||
The configuration includes the following sections:
|
The configuration includes the following sections:
|
||||||
|
|
||||||
* THRESHOLDS FOR SENDING SIGNALS
|
* THRESHOLDS FOR SENDING SIGNALS TO VICTIMS
|
||||||
* INTENSITY OF MONITORING (AND CPU USAGE)
|
* INTENSITY OF MONITORING (AND CPU USAGE)
|
||||||
* PREVENTION OF KILLING INNOCENT VICTIMS
|
* PREVENTION OF KILLING INNOCENT VICTIMS
|
||||||
* AVOID AND PREFER VICTIM NAMES VIA REGEX
|
* AVOID AND PREFER VICTIM NAMES VIA REGEX MATCHING
|
||||||
* EXECUTE THE COMMAND INSTEAD OF SENDING THE SIGTERM SIGNAL
|
* EXECUTE THE COMMAND INSTEAD OF SENDING THE SIGTERM SIGNAL
|
||||||
* GUI NOTIFICATIONS
|
* GUI NOTIFICATIONS: RESULTS OF PREVENTING OOM AND LOW MEMORY WARNINGS
|
||||||
* LOW MEMORY WARNINGS
|
|
||||||
* SELF-DEFENSE AND PREVENTING SLOWING DOWN THE PROGRAM
|
* SELF-DEFENSE AND PREVENTING SLOWING DOWN THE PROGRAM
|
||||||
* OUTPUT VERBOSITY
|
* OUTPUT VERBOSITY
|
||||||
|
|
||||||
@ -20,7 +19,7 @@
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
I. THRESHOLDS FOR SENDING SIGNALS
|
* THRESHOLDS FOR SENDING SIGNALS TO VICTIMS
|
||||||
|
|
||||||
Sets the available memory levels below which SIGTERM or SIGKILL
|
Sets the available memory levels below which SIGTERM or SIGKILL
|
||||||
signals are sent. The signal will be sent if MemAvailable and
|
signals are sent. The signal will be sent if MemAvailable and
|
||||||
@ -47,7 +46,7 @@ zram_max_sigkill = 60 %
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
II. INTENSITY OF MONITORING
|
* INTENSITY OF MONITORING (AND CPU USAGE)
|
||||||
|
|
||||||
Coefficients that affect the intensity of monitoring. Reducing
|
Coefficients that affect the intensity of monitoring. Reducing
|
||||||
the coefficients can reduce CPU usage and increase the periods
|
the coefficients can reduce CPU usage and increase the periods
|
||||||
@ -75,7 +74,7 @@ rate_zram = 1
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
III. PREVENTION OF KILLING INNOCENT VICTIMS
|
* PREVENTION OF KILLING INNOCENT VICTIMS
|
||||||
|
|
||||||
Минимальное значение oom_score, которым должен обладать
|
Минимальное значение oom_score, которым должен обладать
|
||||||
процесс для того, чтобы ему был отправлен сигнал.
|
процесс для того, чтобы ему был отправлен сигнал.
|
||||||
@ -114,7 +113,7 @@ oom_score_adj_max = 20
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
IV. AVOID AND PREFER VICTIM NAMES VIA REGEX
|
* AVOID AND PREFER VICTIM NAMES VIA REGEX MATCHING
|
||||||
|
|
||||||
Можно задать регулярные выражения (Perl-compatible regular
|
Можно задать регулярные выражения (Perl-compatible regular
|
||||||
expressions), которые будут использоваться для сопоставления с
|
expressions), которые будут использоваться для сопоставления с
|
||||||
@ -151,7 +150,7 @@ avoidlist_factor = 4
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
V. EXECUTE THE COMMAND INSTEAD OF SENDING THE SIGTERM SIGNAL
|
* EXECUTE THE COMMAND INSTEAD OF SENDING THE SIGTERM SIGNAL
|
||||||
|
|
||||||
Для процессов с определенным именем можно задать команду,
|
Для процессов с определенным именем можно задать команду,
|
||||||
которая будет выполняться вместо отправки сигнала SIGTERM
|
которая будет выполняться вместо отправки сигнала SIGTERM
|
||||||
@ -180,7 +179,9 @@ execute_the_command = False
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
VI. GUI NOTIFICATIONS
|
* GUI NOTIFICATIONS:
|
||||||
|
* RESULTS OF PREVENTING OOM
|
||||||
|
* LOW MEMORY WARNINGS
|
||||||
|
|
||||||
Включение этой опции требует наличия notify-send в системе.
|
Включение этой опции требует наличия notify-send в системе.
|
||||||
В Debian/Ubuntu это обеспечивается установкой пакета
|
В Debian/Ubuntu это обеспечивается установкой пакета
|
||||||
@ -193,9 +194,9 @@ execute_the_command = False
|
|||||||
|
|
||||||
desktop_notifications = False
|
desktop_notifications = False
|
||||||
|
|
||||||
Дополнительные опции для notify-send.
|
Additional options for notify-send.
|
||||||
См. notify-send --help и man notify-send
|
See `notify-send --help` and read `man notify-send`
|
||||||
Примеры:
|
For example:
|
||||||
notify_options = -u "critical"
|
notify_options = -u "critical"
|
||||||
notify_options = -t "20000" -i "dialog-warning"
|
notify_options = -t "20000" -i "dialog-warning"
|
||||||
|
|
||||||
@ -208,14 +209,8 @@ notify_options =
|
|||||||
|
|
||||||
root_display = :0
|
root_display = :0
|
||||||
|
|
||||||
#####################################################################
|
Enable GUI notifications about the low level of available memory.
|
||||||
|
|
||||||
VII. LOW MEMORY WARNINGS
|
|
||||||
|
|
||||||
Десктопные уведомления о низком уровне доступной памяти.
|
|
||||||
Для работы опции должны быть включены десктопные уведомления.
|
Для работы опции должны быть включены десктопные уведомления.
|
||||||
Возможно стоит этот раздел объединить с GUI NOTIFICATIONS.
|
|
||||||
|
|
||||||
Valid values are True and False.
|
Valid values are True and False.
|
||||||
|
|
||||||
low_memory_warnings = False
|
low_memory_warnings = False
|
||||||
@ -243,7 +238,7 @@ zram_max_warnings = 40 %
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
VIII. SELF-DEFENSE AND PREVENTING SLOWING DOWN THE PROGRAM
|
* SELF-DEFENSE AND PREVENTING SLOWING DOWN THE PROGRAM
|
||||||
|
|
||||||
True - заблокировать процесс в памяти для запрета его своппинга.
|
True - заблокировать процесс в памяти для запрета его своппинга.
|
||||||
False - не блокировать.
|
False - не блокировать.
|
||||||
@ -284,7 +279,7 @@ realtime_ionice_classdata = 5
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
IX. STANDARD OUTPUT VERBOSITY
|
* STANDARD OUTPUT VERBOSITY
|
||||||
|
|
||||||
Display the configuration when the program starts.
|
Display the configuration when the program starts.
|
||||||
Valid values are True and False.
|
Valid values are True and False.
|
||||||
@ -302,3 +297,4 @@ print_mem_check_results = False
|
|||||||
|
|
||||||
print_sleep_periods = False
|
print_sleep_periods = False
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user