public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Markus Klotzbuecher <mk@mkio.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/9] moveconfig: expand simple expressions
Date: Wed, 29 Jan 2020 09:44:19 +0100	[thread overview]
Message-ID: <20200129084419.GA4161132@e495> (raw)
In-Reply-To: <4cb03cb2-9214-ebf9-e1cd-2fe8c5ee4c43@gmx.de>

Hi Heinrich

On Sat, Jan 25, 2020 at 10:46:04PM +0100, Heinrich Schuchardt wrote:
>On 5/15/19 3:15 PM, Markus Klotzbuecher wrote:
>> From: Markus Klotzbuecher <markus.klotzbuecher@kistler.com>
>> 
>> Add support for expanding simple expressions and sizes such as
>> "(4 * 1024)", "(512 << 10)" or "(SZ_256K)".
>> 
>> This can help to significantly reduce the number of "suspicious"
>> moves, such as
>> 
>>   'CONFIG_ENV_SIZE="(64 << 10)"' was removed by savedefconfig.
>> 
>> If the expansion fails, it falls back to the original string.
>> 
>> Signed-off-by: Markus Klotzbuecher <markus.klotzbuecher@kistler.com>
>> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Cc: Heiko Schocher <hs@denx.de>
>> ---
>> Changes for v2: new patch
>> 
>>   tools/moveconfig.py | 41 +++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 41 insertions(+)
>> 
>> diff --git a/tools/moveconfig.py b/tools/moveconfig.py
>> index 1a214c5605..0bbc7c1991 100755
>> --- a/tools/moveconfig.py
>> +++ b/tools/moveconfig.py
>> @@ -354,6 +354,26 @@ CONFIG_DATABASE = 'moveconfig.db'
>> 
>>   CONFIG_LEN = len('CONFIG_')
>> 
>> +SIZES = {
>> +    "SZ_1":    0x00000001, "SZ_2":    0x00000002,
>> +    "SZ_4":    0x00000004, "SZ_8":    0x00000008,
>> +    "SZ_16":   0x00000010, "SZ_32":   0x00000020,
>> +    "SZ_64":   0x00000040, "SZ_128":  0x00000080,
>> +    "SZ_256":  0x00000100, "SZ_512":  0x00000200,
>> +    "SZ_1K":   0x00000400, "SZ_2K":   0x00000800,
>> +    "SZ_4K":   0x00001000, "SZ_8K":   0x00002000,
>> +    "SZ_16K":  0x00004000, "SZ_32K":  0x00008000,
>> +    "SZ_64K":  0x00010000, "SZ_128K": 0x00020000,
>> +    "SZ_256K": 0x00040000, "SZ_512K": 0x00080000,
>> +    "SZ_1M":   0x00100000, "SZ_2M":   0x00200000,
>> +    "SZ_4M":   0x00400000, "SZ_8M":   0x00800000,
>> +    "SZ_16M":  0x01000000, "SZ_32M":  0x02000000,
>> +    "SZ_64M":  0x04000000, "SZ_128M": 0x08000000,
>> +    "SZ_256M": 0x10000000, "SZ_512M": 0x20000000,
>> +    "SZ_1G":   0x40000000, "SZ_2G":   0x80000000,
>> +    "SZ_4G":  0x100000000
>> +}
>> +
>>   ### helper functions ###
>>   def get_devnull():
>>       """Get the file object of '/dev/null' device."""
>> @@ -777,6 +797,25 @@ def cleanup_readme(configs, options):
>>       with open('README', 'w') as f:
>>           f.write(''.join(newlines))
>> 
>> +def try_expand(line):
>> +    """If value looks like an expression, try expanding it
>> +    Otherwise just return the existing value
>> +    """
>> +    if line.find('=') == -1:
>> +        return line
>> +
>> +    try:
>> +        cfg, val = re.split("=", line)
>> +        val= val.strip('\"')
>> +        if re.search("[*+-/]|<<|SZ_+|\(([^\)]+)\)", val):
>> +            newval = hex(eval(val, SIZES))
>
>The if clause evaluates to true for values like:
>
>    val = "os.execl('/sbin/fdisk')"
>
>As eval() can be used to execute arbitrary commands this patch should be
>corrected.

Fair point. I took a quick look at python sandboxing, and apparently
it's difficult to be done in a secure way (see pysandbox). As
introducing a CONFIG with something like the above clearly has
malicious intent, just preventing "accidential" execution will not be
sufficient. Perhaps we can use ast.literal_eval instead. I'll take a
closer look.

Best regards
Markus

-- 
Markus Klotzbuecher
Freelancer Embedded, Distributed & Real-time Systems
Am See 28, 78465 Konstanz, Germany
www.mkio.de

  reply	other threads:[~2020-01-29  8:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-15 13:15 [U-Boot] [PATCH v2 0/9] miscellaneous ubispl and ubi improvements Markus Klotzbuecher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 1/9] moveconfig: expand simple expressions Markus Klotzbuecher
2019-06-13  3:30   ` Heiko Schocher
2020-01-25 21:46   ` Heinrich Schuchardt
2020-01-29  8:44     ` Markus Klotzbuecher [this message]
2020-01-29 11:54       ` Heinrich Schuchardt
2019-05-15 13:15 ` [U-Boot] [PATCH v2 2/9] env: ubi: KConfig: add CONFIG_ENV_UBI_VOLUME_REDUND Markus Klotzbuecher
2019-06-13  3:31   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 3/9] at91, omap2plus: configs: migrate CONFIG_ENV_ to defconfigs Markus Klotzbuecher
2019-06-13  3:31   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 4/9] env: ubi: support configurable VID offset Markus Klotzbuecher
2019-06-13  3:31   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 5/9] ubi: fix UBI_SILENCE_MSG Markus Klotzbuecher
2019-06-13  3:32   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 6/9] ubispl: migrate configuration to Kconfig Markus Klotzbuecher
2019-06-13  3:32   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 7/9] configs: migrate ubispl boards to KConfig Markus Klotzbuecher
2019-05-20 20:50   ` Enric Balletbo Serra
2019-06-13  3:32   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 8/9] ubispl: add support for loading volumes by name Markus Klotzbuecher
2019-06-13  3:33   ` Heiko Schocher
2019-05-15 13:16 ` [U-Boot] [PATCH v2 9/9] ubispl: introduce separate CONFIG_UBI_SPL_SILENCE_MSG Markus Klotzbuecher
2019-06-13  3:33   ` Heiko Schocher
2019-06-05 10:39 ` [U-Boot] [PATCH v2 0/9] miscellaneous ubispl and ubi improvements Markus Klotzbuecher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200129084419.GA4161132@e495 \
    --to=mk@mkio.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox