Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: scripts/image_signing/ensure_secure_kernelparams.sh

Issue 6538034: Fix issue where params which are sub-strings of other params caused problems e.g. ro and cros_secure (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Fixes for nits Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Abort on error. 7 # Abort on error.
8 set -e 8 set -e
9 9
10 # Load common constants and variables. 10 # Load common constants and variables.
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 # Given a dm param string which includes a long and unpredictable 27 # Given a dm param string which includes a long and unpredictable
28 # sha1 hash, return the same string with the sha1 hash replaced 28 # sha1 hash, return the same string with the sha1 hash replaced
29 # with a magic placeholder. This same magic placeholder is used 29 # with a magic placeholder. This same magic placeholder is used
30 # in the config file, for comparison purposes. 30 # in the config file, for comparison purposes.
31 dmparams_mangle_sha1() { 31 dmparams_mangle_sha1() {
32 echo "$1" | sed 's/sha1 [0-9a-fA-F]*/sha1 MAGIC_HASH/' 32 echo "$1" | sed 's/sha1 [0-9a-fA-F]*/sha1 MAGIC_HASH/'
33 } 33 }
34 34
35 # This escapes any non-alphanum character, since many such characters
36 # are regex metacharacters.
37 escape_regexmetas() {
38 echo "$1" | sed 's/\([^a-zA-Z0-9]\)/\\\1/g'
39 }
40
35 usage() { 41 usage() {
36 echo "Usage $PROG image [config]" 42 echo "Usage $PROG image [config]"
37 } 43 }
38 44
39 main() { 45 main() {
40 # We want to catch all the discrepancies, not just the first one. 46 # We want to catch all the discrepancies, not just the first one.
41 # So, any time we find one, we set testfail=1 and continue. 47 # So, any time we find one, we set testfail=1 and continue.
42 # When finished we will use testfail to determine our exit value. 48 # When finished we will use testfail to determine our exit value.
43 local testfail=0 49 local testfail=0
44 50
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 85
80 # Special-case handling of the dm= param: 86 # Special-case handling of the dm= param:
81 if [[ "$dmparams" != "$required_dmparams" ]]; then 87 if [[ "$dmparams" != "$required_dmparams" ]]; then
82 echo "Kernel dm= parameter does not match expected value!" 88 echo "Kernel dm= parameter does not match expected value!"
83 echo "Expected: $required_dmparams" 89 echo "Expected: $required_dmparams"
84 echo "Actual: $dmparams" 90 echo "Actual: $dmparams"
85 testfail=1 91 testfail=1
86 fi 92 fi
87 93
88 # Ensure all other required params are present. 94 # Ensure all other required params are present.
89 for param in ${required_kparams[@]}; do : 95 for param in ${required_kparams[@]}; do
90 if [[ "$kparams_nodm" != *$param* ]]; then 96 if [[ "$kparams_nodm" != *$param* ]]; then
91 echo "Kernel parameters missing required value: $param" 97 echo "Kernel parameters missing required value: $param"
92 testfail=1 98 testfail=1
93 else 99 else
94 # Remove matched params as we go. If all goes well, kparams_nodm 100 # Remove matched params as we go. If all goes well, kparams_nodm
95 # will be nothing left but whitespace by the end. 101 # will be nothing left but whitespace by the end.
96 kparams_nodm=${kparams_nodm/$param/} 102 param=$(escape_regexmetas "$param")
103 kparams_nodm=$(echo "$kparams_nodm" | sed "s/\b$param\b//")
97 fi 104 fi
98 done 105 done
99 106
100 # Check-off each of the allowed-but-optional params that were present. 107 # Check-off each of the allowed-but-optional params that were present.
101 for param in ${optional_kparams[@]}; do : 108 for param in ${optional_kparams[@]}; do
102 kparams_nodm=${kparams_nodm/$param/} 109 param=$(escape_regexmetas "$param")
110 kparams_nodm=$(echo "$kparams_nodm" | sed "s/\b$param\b//")
103 done 111 done
104 112
105 # This section enforces the default-deny for any unexpected params 113 # This section enforces the default-deny for any unexpected params
106 # not already processed by one of the above loops. 114 # not already processed by one of the above loops.
107 if [[ ! -z ${kparams_nodm// /} ]]; then 115 if [[ ! -z ${kparams_nodm// /} ]]; then
108 echo "Unexpected kernel parameters found: $kparams_nodm" 116 echo "Unexpected kernel parameters found: $kparams_nodm"
109 testfail=1 117 testfail=1
110 fi 118 fi
111 119
112 exit $testfail 120 exit $testfail
113 } 121 }
114 122
115 main $@ 123 main $@
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698