-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisable_global_preload_linux.sh
More file actions
executable file
·123 lines (108 loc) · 3.18 KB
/
Copy pathdisable_global_preload_linux.sh
File metadata and controls
executable file
·123 lines (108 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh
#####################################################################################
## The script for disable non-system allocator global preload. Linux version.
##
## Version 1.3
## Written by Y.Voinov (C) 2025-2026
#####################################################################################
# Variables
# Global preload config
PRELOAD_CONF="/etc/ld.so.preload"
# Set bitness for allocator. 64 by default
BITNESS=64
# Allocator library search prefix: from where to find
LIBRARY_PREFIX="/usr/local"
# Set library name to preload
LIBRARY_NAME="*alloc.so"
# Find allocator lib(s)
# We assume that there is only one allocator in a given path and it has a corresponding name pattern.
ALLOCATOR_SYMLINK_PATH="`find $LIBRARY_PREFIX -name $LIBRARY_NAME -exec file {} \; | grep $BITNESS | cut -d':' -f1`"
# Subroutines
usage_note()
{
echo "The script for disable non-system allocator global preload."
echo "Must be run as root."
echo "Usage: `basename $0` [options]"
echo "Options:"
echo " -h, -H, --help show this help"
echo " -u, -U unlink hard link if exists"
echo " -32 disable 32 bit allocator preload on 32 bit OS"
echo
echo "Note: A hard link to the allocator in the system directory"
echo " is required for services restricted by the sandbox."
exit 0
}
check_os()
{
if [ "`uname`" != "Linux" ]; then
echo "ERROR: Unsupported OS."
exit 1
fi
}
check_root()
{
if [ -z "`id | grep 'uid=0(root)'`" ]; then
echo "ERROR: Must be run as root."
exit 2
fi
}
disable_global_preload()
{
remove_link=$1
if [ "$remove_link" = "1" ]; then
get_lib_name="`readlink -f $ALLOCATOR_SYMLINK_PATH`"
get_dirname="`find /usr -name 'libc.so.*' -exec file {} \; | grep $BITNESS | grep 'ELF' | cut -d: -f1 | { read f && dirname "$f"; }`"
get_link_name="`basename $get_lib_name | cut -d'.' -f1-3`"
allocator_link="$get_dirname/$get_link_name"
else
allocator_link="$ALLOCATOR_SYMLINK_PATH"
fi
if [ -f $PRELOAD_CONF ] && [ -z "`cat $PRELOAD_CONF | grep $allocator_link`" ]; then
echo "$PRELOAD_CONF contents: `cat $PRELOAD_CONF`"
echo "Disabled already or not enabled."
elif [ -f $PRELOAD_CONF ] && [ ! -z "`cat $PRELOAD_CONF | grep $allocator_link`" ]; then
chattr -i $PRELOAD_CONF
mv $PRELOAD_CONF $PRELOAD_CONF.orig
echo "File $PRELOAD_CONF renamed to $PRELOAD_CONF.orig."
else
echo "File $PRELOAD_CONF not exists."
echo "Disabled already or not enabled."
fi
if [ "$remove_link" = "1" ]; then
if [ -f "$get_dirname/$get_link_name" ]; then
unlink $get_dirname/$get_link_name
echo "Hard link $get_dirname/$get_link_name unlinked."
else
echo "Hard link $get_dirname/$get_link_name not found."
fi
fi
}
# Main
# Defaults
unlink_hard_link="0"
# Parse command line
if [ "x$*" != "x" ]; then
arg_list=$*
# Read arguments
for i in $arg_list
do
case $i in
-h|-H|--help)
usage_note
;;
-u|-U)
unlink_hard_link="1"
;;
-32)
BITNESS=32
;;
*) shift
;;
esac
done
fi
check_os
check_root
disable_global_preload $unlink_hard_link
echo "Completed. Reboot now to apply changes globally."
exit 0