diff options
author | Milton Miller <miltonm@us.ibm.com> | 2016-06-16 16:58:21 -0500 |
---|---|---|
committer | Milton Miller <miltonm@us.ibm.com> | 2016-06-30 14:46:44 -0500 |
commit | 08f66d08737cd6e35c8cff49acaff8d701eb8313 (patch) | |
tree | 86f8e9253e9a60f1584b574406ca6eb7a26ef925 | |
parent | f1cad11499f331d7822ee48f104959111ed2757a (diff) | |
download | talos-openbmc-08f66d08737cd6e35c8cff49acaff8d701eb8313.tar.gz talos-openbmc-08f66d08737cd6e35c8cff49acaff8d701eb8313.zip |
initfs: update: Sanitize whitelist directory entries
Repeatedly strip trailing "/" and "/." from whitelist entries
and fail if an entry includes "/../", ends with "/..", or doesn't
start with a "/". Also use the entries quoted to avoid any glob.
It was noticed the save code was saving directories that ended
in "/" into a subdirectory of the last component name. This was
traced the the code creating the directory just stripping the last
"/" and then copying to the directory.
Choose to sanitize the entry where possible for ease of use verses
a small performance penalty.
Signed-off-by: Milton Miller <miltonm@us.ibm.com>
-rwxr-xr-x | meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh index 97d4402ee..f0c41a74c 100755 --- a/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh +++ b/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-update.sh @@ -173,13 +173,24 @@ then while read f do - if ! test -e $upper/$f + # Entries shall start with /, no trailing /.. or embedded /../ + if test "/${f#/}" != "$f" -o "${f%/..}" != "${f#*/../}" + then + echo 1>&2 "WARNING: Skipping bad whitelist entry $f." + continue + fi + if ! test -e "$upper/$f" then continue fi d="$save/$f" + while test "${d%/}" != "${d%/.}" + do + d="${d%/.}" + d="${d%/}" + done mkdir -p "${d%/*}" - cp -rp $upper/$f "${d%/*}/" + cp -rp "$upper/$f" "${d%/*}/" done < $whitelist if test -n "$mounted" |