672705831f
As motivation for this; we have had two breakouts of dib in recent memory. One was a failure to unmount through symlinks in the core code (I335316019ef948758392b03e91f9869102a472b9) and the other was removing host keys on the build-system (Ib01d71ff9415a0ae04d963f6e380aab9ac2260ce). For the most part, dib runs unprivileged. Bits of the core code are hopefully well tested (modulo bugs like the first one!). We give free reign inside the chroot (although there is still some potential there for adverse external affects via bind mounts). Where we could be a bit safer (and could have prevented at least the second of these breakouts) is with some better checking that the "sudo" calls *outside* the chroot at least looked sane. This adds a basic check that we're using chroot or image paths when calling sudo in those parts of elements that run *outside* the chroot. Various files are updated to accomodate this check; mostly by just ignoring it for existing code (I have not audited these calls). Nobody is pretending this type of checking makes dib magically safe, or removes the issues with it needing to do things as root during the build. But this can help find egregious errors like the key removal. Change-Id: I161a5aea1d29dcdc7236f70d372c53246ec73749
49 lines
1.3 KiB
Bash
Executable File
49 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
# dib-lint: disable=safe_sudo
|
|
|
|
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
|
|
set -x
|
|
fi
|
|
set -eu
|
|
set -o pipefail
|
|
|
|
[ -n "$TARGET_ROOT" ]
|
|
|
|
source $_LIB/img-functions
|
|
|
|
if [ -d $TARGET_ROOT/boot/extlinux ] ; then
|
|
CONF=$TARGET_ROOT/boot/extlinux/extlinux.conf
|
|
elif [ -d $TARGET_ROOT/boot/syslinux ] ; then
|
|
CONF=$TARGET_ROOT/boot/syslinux/syslinux.cfg
|
|
else
|
|
exit 0
|
|
fi
|
|
|
|
# Dig up the initrd and kernel to use.
|
|
select_boot_kernel_initrd $TARGET_ROOT
|
|
|
|
sudo sh -c "cat > $CONF <<_EOF_
|
|
DEFAULT linux
|
|
|
|
LABEL linux
|
|
KERNEL /boot/$KERNEL
|
|
APPEND ro root=LABEL=${DIB_ROOT_LABEL} console=tty0 console=ttyS0,115200 nofb nomodeset vga=normal
|
|
INITRD /boot/$RAMDISK
|
|
_EOF_"
|