Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C7B4C433EF for ; Sun, 27 Mar 2022 15:33:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B2A7F83A34; Sun, 27 Mar 2022 17:33:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LBseYZP/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C6AC3836A9; Sun, 27 Mar 2022 17:32:36 +0200 (CEST) Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 03FB383981 for ; Sun, 27 Mar 2022 17:32:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ej1-x62a.google.com with SMTP id qa43so23943189ejc.12 for ; Sun, 27 Mar 2022 08:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tGwfkg5My1s9WbGMVuc2RpeNotGY8kEuBcJkL+RcZHE=; b=LBseYZP/XoUwIQUiC2crx40aCR2VgMI2G8p7OkhcksbcthxGasRZmCphTNdg+hW2uU 9fRfkxV4WIrGScpvPH/FXnRIvk8chVokG75q+nMDEfs+7kQGWQh32hGCXWenu6wZIBdk y1S9PO+pSkiFahaB07ZWDR9k6hz+uA8Z4SRl0pY9TA1Ol8kDTbW0bjTfrS2bdjpEX6tI ky3PQAqUz4aotcOtONWFLAh2G8zvsKYeCTjAAb0Xwu1IiowJqFAnnV1fACvi0CcIGcSu VD3Cv+0F4WtPbioBmjwPvNmywCaF+bfoAHzp7QEBV7X3Rkqu/47I2Eugj83648GXxaC/ G2Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tGwfkg5My1s9WbGMVuc2RpeNotGY8kEuBcJkL+RcZHE=; b=esYbTvezdJ5Mpuy6Z4OkC4HXzvS5pdBdgHryp9V5/hfj1u7y7WjPdYj+MEAI92O/dV cw0iNT0oxPs1OTa4YlZu8dVr6GFChvbXtmjxzT2ji+IvF80Lc5HqPl+e08PFGbIERi/B tiNpE6B3caEPr1pdqRF3l+gQswQQ4wzGlI0bJj64E24DzmHc3LMmMvF6fb+aP4zzartM svAgY30Z6L7MaVFRYxBb3+PGQyCD9LyT6axWc4LgMmNVO4st/WpD1UOgNm2pcbJMMcfC Hp0WNQQ/37Zfu6MpRONYGQdT47H3mp0VGgHXyf0Wdw9eTGNaCieHQQxAySzm9oUGKkXC M8NA== X-Gm-Message-State: AOAM531MSKYJVWUxqxC39FXSFgWRyw95KURDFfXWhaOvNnWbGMUTDgWF ukW9EXt4oKJR5DEcLLWNf8kNSsz8aKY= X-Google-Smtp-Source: ABdhPJwkdDAhwpo9MuUTGjojf47/cJ66AH0i9nn/Chn4kKjjsW9g0BH98Mz+guZCD9/jJVb01URw6w== X-Received: by 2002:a17:907:62a1:b0:6da:7952:d4d2 with SMTP id nd33-20020a17090762a100b006da7952d4d2mr22480120ejc.260.1648395146650; Sun, 27 Mar 2022 08:32:26 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:26 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 7/7] binman: Refuse to replace sections for now Date: Sun, 27 Mar 2022 18:31:50 +0300 Message-Id: <20220327153151.15912-8-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Binman interfaces allow attempts to replace any entry in the image with arbitrary data. When trying to replace sections, the changes in the section entry's data are not propagated to its child entries. This, combined with how sections rebuild their contents from its children, eventually causes the replaced contents to be silently overwritten by rebuilt contents equivalent to the original data. Add a simple test for replacing a section that is currently failing due to this behaviour, and mark it as an expected failure. Also, raise an error when replacing a section instead of silently pretending it was replaced. Signed-off-by: Alper Nebi Yasak --- tools/binman/etype/section.py | 3 +++ tools/binman/ftest.py | 9 ++++++++ .../test/234_replace_section_simple.dts | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tools/binman/test/234_replace_section_simple.dts diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index ccac658c1831..bd67238b9199 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -788,6 +788,9 @@ def ReadChildData(self, child, decomp=True, alt_format=None): data = new_data return data + def WriteData(self, data, decomp=True): + self.Raise("Replacing sections is not implemented yet") + def WriteChildData(self, child): return True diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 43bec4a88841..058651cc18a0 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5641,6 +5641,15 @@ def testReplaceFitSubentryLeafSmallerSize(self): self.assertIsNotNone(path) self.assertEqual(expected_fdtmap, fdtmap) + @unittest.expectedFailure + def testReplaceSectionSimple(self): + """Test replacing a simple section with arbitrary data""" + new_data = b'w' * len(COMPRESS_DATA + U_BOOT_DATA) + data, expected_fdtmap, _ = self._RunReplaceCmd( + 'section', new_data, + dts='234_replace_section_simple.dts') + self.assertEqual(new_data, data) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/234_replace_section_simple.dts b/tools/binman/test/234_replace_section_simple.dts new file mode 100644 index 000000000000..c9d5c3285615 --- /dev/null +++ b/tools/binman/test/234_replace_section_simple.dts @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/dts-v1/; + +/ { + binman { + allow-repack; + + u-boot-dtb { + }; + + section { + blob { + filename = "compress"; + }; + + u-boot { + }; + }; + + fdtmap { + }; + }; +}; -- 2.35.1