moveconfig fixes
cover moveconfig fixes
Two fixes to moveconfig: the first addresses a potential security issue reported by Heinrich Schuchardt caused by using the Python built-in eval to expand CONFIG_ value expressions. Running moveconfig on a maliciously prepared CONFIG could lead to execution of arbitrary Python code. The second is a Python3 bugfix.
Markus Klotzbuecher (2):
moveconfig: replace unsafe eval with asteval
moveconfig: convert ps.stderr to string
tools/moveconfig.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.0
PATCH 1/2 moveconfig: replace unsafe eval with asteval
Commit b237d358b "moveconfig: expand simple expressions" added support for expanding expressions in configs, but used the unsafe python built-in "eval". This patch fixes this by replacing eval with the asteval module.
--- tools/moveconfig.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/moveconfig.py +3 -1
@@ -295,6 +295,7 @@ To see the complete list of supported options, run """ +import asteval import collections import copy import difflib
@@ -808,10 +809,11 @@ def try_expand(line): return line try: + aeval = asteval.Interpreter( usersyms=SIZES, minimal=True ) cfg, val = re.split("=", line) val= val.strip('\"') if re.search("[*+-/]|<<|SZ_+|\(([^\)]+)\)", val): - newval = hex(eval(val, SIZES)) + newval = hex(aeval(val)) print("\tExpanded expression %s to %s" % (val, newval)) return cfg+'='+newval except:
Signature · 1 line
2.25.0
PATCH 2/2 moveconfig: convert ps.stderr to string
In reply to Markus KlotzbuecherPrinting the error message in verbose mode fails, since python3 doesn't implicitely convert bytes to strings.
--- tools/moveconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/moveconfig.py +1 -1
@@ -1217,7 +1217,7 @@ class Slot: "Failed to process.\n") if self.options.verbose: self.log += color_text(self.options.color, COLOR_LIGHT_CYAN, - self.ps.stderr.read()) + self.ps.stderr.read().decode()) self.finish(False) def do_defconfig(self):
Signature · 1 line
2.25.0
PATCH 1/2 moveconfig: replace unsafe eval with asteval
In reply to Markus KlotzbuecherQuoted 5 lines · Markus Klotzbuecher
Commit
b237d358b"moveconfig: expand simple expressions" added support for expanding expressions in configs, but used the unsafe python built-in "eval". This patch fixes this by replacing eval with the asteval module.
Quoted 7 lines
Signed-off-by Markus Klotzbuecher <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Joe Hershberger <[email protected]>Cc Masahiro Yamada <[email protected]>
Thanks for addressing this concern.
PATCH 2/2 moveconfig: convert ps.stderr to string
In reply to Markus KlotzbuecherQuoted 11 lines · Markus Klotzbuecher
Printing the error message in verbose mode fails, since python3 doesn't implicitely convert bytes to strings.
Signed-off-by Markus Klotzbuecher <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Masahiro Yamada <[email protected]>--- tools/moveconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 1/2 moveconfig: replace unsafe eval with asteval
In reply to Markus KlotzbuecherQuoted 5 lines · Markus Klotzbuecher
Commit
b237d358b"moveconfig: expand simple expressions" added support for expanding expressions in configs, but used the unsafe python built-in "eval". This patch fixes this by replacing eval with the asteval module.
Quoted 8 lines
Signed-off-by Markus Klotzbuecher <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Heiko Schocher <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>Cc Joe Hershberger <[email protected]>Cc Masahiro Yamada <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200225/bc67fb60/attachment.sig>
PATCH 2/2 moveconfig: convert ps.stderr to string
In reply to Markus KlotzbuecherQuoted 8 lines · Markus Klotzbuecher
Printing the error message in verbose mode fails, since python3 doesn't implicitely convert bytes to strings.
Signed-off-by Markus Klotzbuecher <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Masahiro Yamada <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200225/b6898bab/attachment.sig>