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

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: 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 escape_regexmetas() {
gauravsh 2011/02/18 00:11:56 add comment saying this escapes non-alphanumeric c
36 echo "$1" | sed 's/\([^a-zA-Z0-9]\)/\\\1/g'
37 }
38
35 usage() { 39 usage() {
36 echo "Usage $PROG image [config]" 40 echo "Usage $PROG image [config]"
37 } 41 }
38 42
39 main() { 43 main() {
40 # We want to catch all the discrepancies, not just the first one. 44 # 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. 45 # So, any time we find one, we set testfail=1 and continue.
42 # When finished we will use testfail to determine our exit value. 46 # When finished we will use testfail to determine our exit value.
43 local testfail=0 47 local testfail=0
44 48
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 83
80 # Special-case handling of the dm= param: 84 # Special-case handling of the dm= param:
81 if [[ "$dmparams" != "$required_dmparams" ]]; then 85 if [[ "$dmparams" != "$required_dmparams" ]]; then
82 echo "Kernel dm= parameter does not match expected value!" 86 echo "Kernel dm= parameter does not match expected value!"
83 echo "Expected: $required_dmparams" 87 echo "Expected: $required_dmparams"
84 echo "Actual: $dmparams" 88 echo "Actual: $dmparams"
85 testfail=1 89 testfail=1
86 fi 90 fi
87 91
88 # Ensure all other required params are present. 92 # Ensure all other required params are present.
89 for param in ${required_kparams[@]}; do : 93 for param in ${required_kparams[@]}; do :
gauravsh 2011/02/18 00:11:56 remove unnecessary colon at the end
90 if [[ "$kparams_nodm" != *$param* ]]; then 94 if [[ "$kparams_nodm" != *$param* ]]; then
91 echo "Kernel parameters missing required value: $param" 95 echo "Kernel parameters missing required value: $param"
92 testfail=1 96 testfail=1
93 else 97 else
94 # Remove matched params as we go. If all goes well, kparams_nodm 98 # Remove matched params as we go. If all goes well, kparams_nodm
95 # will be nothing left but whitespace by the end. 99 # will be nothing left but whitespace by the end.
96 kparams_nodm=${kparams_nodm/$param/} 100 param=$(escape_regexmetas "$param")
101 kparams_nodm=$(echo "$kparams_nodm" | sed "s/\b$param\b//")
97 fi 102 fi
98 done 103 done
99 104
100 # Check-off each of the allowed-but-optional params that were present. 105 # Check-off each of the allowed-but-optional params that were present.
101 for param in ${optional_kparams[@]}; do : 106 for param in ${optional_kparams[@]}; do :
gauravsh 2011/02/18 00:11:56 remove unnecessary colon at the end
102 kparams_nodm=${kparams_nodm/$param/} 107 param=$(escape_regexmetas "$param")
108 kparams_nodm=$(echo "$kparams_nodm" | sed "s/\b$param\b//")
103 done 109 done
104 110
105 # This section enforces the default-deny for any unexpected params 111 # This section enforces the default-deny for any unexpected params
106 # not already processed by one of the above loops. 112 # not already processed by one of the above loops.
107 if [[ ! -z ${kparams_nodm// /} ]]; then 113 if [[ ! -z ${kparams_nodm// /} ]]; then
108 echo "Unexpected kernel parameters found: $kparams_nodm" 114 echo "Unexpected kernel parameters found: $kparams_nodm"
109 testfail=1 115 testfail=1
110 fi 116 fi
111 117
112 exit $testfail 118 exit $testfail
113 } 119 }
114 120
115 main $@ 121 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