Skip to content

Commit c3c8f7f

Browse files
rodnymolinalguohan
authored andcommitted
Fix for bash's memory-leak (#1879)
* Fix for bash's memory-leak Memory leak is observed during the execution of scripts that make use of bash-arrays. In scenarios where the offending script is executed on a regular basis (e.g. fancontrol), the leaking process may end up consuming most of the system resources. In this PR i'm replacing bash in all the contexts where it executes (both host and dockers). The official patch for this issue is here: https://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-040 * Fixing minor issue during code-merge Signed-off-by: Rodny Molina <[email protected]>
1 parent 77b899b commit c3c8f7f

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

files/build_templates/sonic_debian_extension.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/python-click*_all.deb || \
100100
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/python-sonic-utilities_*.deb || \
101101
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
102102

103+
# Install customized bash version to patch memory-leak issue. This instruction shall be removed
104+
# once the migration to Debian-9 (Stretch) is completed.
105+
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/bash_*.deb || \
106+
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
107+
103108
# SONiC utilities installs bash-completion as a dependency. However, it is disabled by default
104109
# in bash.bashrc, so we copy a version of the file with it enabled here.
105110
sudo cp -f $IMAGE_CONFIGS/bash/bash.bashrc $FILESYSTEM_ROOT/etc/

rules/bash.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# bash package
2+
#
3+
# Created to patch memory-leak issue in the bash-package included in Debian-8 (Jessie)
4+
# release. This rule file, and the associated building-infra created to solve this
5+
# bug (src/bash/), should be eliminated once the migration to Debian-9 (Stretch) is
6+
# completed.
7+
8+
# Bash major release-number corresponding to Debian-8 (Jessie)
9+
BASH_VERSION_MAJOR = 4.3
10+
# Bash complete release-number. This image contains all 4.3 fixes up to patch '42'.
11+
BASH_VERSION_FULL = $(BASH_VERSION_MAJOR)-14
12+
13+
export BASH_VERSION_MAJOR BASH_VERSION_FULL
14+
15+
BASH = bash_$(BASH_VERSION_FULL)_amd64.deb
16+
$(BASH)_SRC_PATH = $(SRC_PATH)/bash
17+
SONIC_MAKE_DEBS += $(BASH)

rules/docker-base.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ DOCKER_BASE = docker-base.gz
44
$(DOCKER_BASE)_PATH = $(DOCKERS_PATH)/docker-base
55
$(DOCKER_BASE)_DEPENDS += $(SUPERVISOR)
66
$(DOCKER_BASE)_DEPENDS += $(LIBWRAP)
7+
$(DOCKER_BASE)_DEPENDS += $(BASH)
78

89
ifeq ($(SONIC_INSTALL_DEBUG_TOOLS),y)
910
GDB = gdb

slave.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
458458
$(SONIC_DEVICE_DATA) \
459459
$(PYTHON_CLICK) \
460460
$(SONIC_UTILS) \
461+
$(BASH) \
461462
$(LIBWRAP) \
462463
$(LIBPAM_TACPLUS) \
463464
$(LIBNSS_TACPLUS)) \

sonic-slave/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ RUN apt-get update && apt-get install -y \
226226
python3-docutils \
227227
python3-requests \
228228
python3-pytest \
229-
python3-colorama
229+
python3-colorama \
230+
# For bash
231+
texi2html
232+
230233

231234
# For linux build
232235
RUN apt-get -y build-dep linux

src/bash/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SHELL = /bin/bash
2+
.ONESHELL:
3+
.SHELLFLAGS += -e
4+
5+
MAIN_TARGET = bash_$(BASH_VERSION_FULL)_amd64.deb
6+
7+
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
8+
rm -rf bash-$(BASH_VERSION_MAJOR)
9+
10+
dget -u https://launchpad.net/debian/+archive/primary/+sourcefiles/bash/$(BASH_VERSION_FULL)/bash_$(BASH_VERSION_FULL).dsc
11+
12+
pushd bash-$(BASH_VERSION_MAJOR)
13+
DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -us -uc -b -j$(SONIC_CONFIG_MAKE_JOBS)
14+
popd
15+
16+
mv $* $(DEST)/

0 commit comments

Comments
 (0)