Skip to contentSkip to conversation

moveconfig fixes

PATCH New Markus Klotzbuecher 4 participants 7 messages Feb 12, 2020 – Feb 25, 2020

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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.

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]>
---
 tools/moveconfig.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/moveconfig.py +3 -1
index 36160a3977..df20ec66af 100755
@@ -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
#2 lore raw

PATCH 1/2 moveconfig: replace unsafe eval with asteval

Quoted 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
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.

#3 lore raw

PATCH 1/2 moveconfig: replace unsafe eval with asteval

In reply to Markus Klotzbuecher
Quoted 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
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]>

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>
#4 lore raw

PATCH 2/2 moveconfig: convert ps.stderr to string

In reply to Markus Klotzbuecher

Printing the error message in verbose mode fails, since python3 doesn't implicitely convert bytes to strings.

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(-)
tools/moveconfig.py +1 -1
index df20ec66af..d8bf7fd071 100755
@@ -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
#5 lore raw

PATCH 2/2 moveconfig: convert ps.stderr to string

Quoted 11 lines · Markus Klotzbuecher

Printing the error message in verbose mode fails, since python3 doesn't implicitely convert bytes to strings.

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(-)
#6 lore raw

PATCH 2/2 moveconfig: convert ps.stderr to string

In reply to Markus Klotzbuecher
Quoted 8 lines · Markus Klotzbuecher

Printing the error message in verbose mode fails, since python3 doesn't implicitely convert bytes to strings.

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>