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 00898C433EF for ; Sun, 27 Mar 2022 15:32:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A9FC68394E; Sun, 27 Mar 2022 17:32:20 +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="qHUEQDka"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D6A8583937; Sun, 27 Mar 2022 17:32:12 +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 1FA6A83919 for ; Sun, 27 Mar 2022 17:32:09 +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 r13so23973780ejd.5 for ; Sun, 27 Mar 2022 08:32:09 -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=Wqc9BIw+9InuFUKR233B49RU2i4BJUydgQOjGqEwg08=; b=qHUEQDkauAO+IKh1v1/nO7AUsMdm5NMcbuu2IclM6d30LUKhLqbEVguM+l63RRp/Rf Tv7YoASxZ5qA6oqTVm3AlEnhV2t6D1SZQ8vYOXTo0RdTjY5PKjgdudvVspbQSiNJXIsW InHCQzHHTITuDg5jAZ37O9Lu1/hy7OoVcR6LP62jqIM/SFI2/ynXb2byaNMQz1AwkkH+ gJ9ufpxIQjqhw6gLI4htohwakG/YNid8aTbTyAOSO3lRTvoMGeoeWfFPjRI7Fgj6Kk5H F6iHU4PqZig8qjEzIr0JcS4LvKcF6nAtZCICtdubqgJfSlUm1BPMtGW8anveWCZj6Fey 2dhQ== 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=Wqc9BIw+9InuFUKR233B49RU2i4BJUydgQOjGqEwg08=; b=dteOZwnAfzLoRcHRo+EXzQ0m+PNL8VQneJaH/Y68i6CchJeoTU9gooGhXDw6iJwjvV JX0kZhlhO7Oovgdq0KdfkOC+rUdzMWL+4uAhYacJ7dEnfPm7qgVv0BIyc0/f84xNuGZL DAjv+NEXu0y38501vYuCgfiMqKlTN68b4Nj/1kaGD3/FgK5kIiPYm5uew3IAonhu9Ah7 ibwhmW1Arltrb7wjxFL50qMb9rv+A1K9qfgkMGZ0yayDwRSgq4GAJD+gsPlP4NeySkLW 9aJXx2vw+Hh3uluU2OBgsX32EiOeXPuTm7POikBybrPg6JYq7ujkNGvp1x/i8x9e8rpC eu3A== X-Gm-Message-State: AOAM530UlsiIr4tekCYLeiQxsY5OX924h8NW7HxZ8u6SZ4zNk2MFnAS1 g1AFZ182tFtQT32GHJl4bKKs4fSAKwI= X-Google-Smtp-Source: ABdhPJw7vHKvtNnkHtM8Plco9pwCsZJDFbRYswpLX9brpHQBaDnfyQuZ0Ts8e96RuWrzMPxnn/86Jg== X-Received: by 2002:a17:906:7304:b0:6e0:6918:ef6f with SMTP id di4-20020a170906730400b006e06918ef6fmr22272362ejc.370.1648395128746; Sun, 27 Mar 2022 08:32:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:08 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 1/7] binman: Fix unique names having '/.' for images read from files Date: Sun, 27 Mar 2022 18:31:44 +0300 Message-Id: <20220327153151.15912-2-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 can embed a copy of the image description into the images it builds as a fdtmap entry, but it omits the /binman/ prefix from the node paths while doing so. When reading an already-built image file, entries are reconstructed using this fdtmap and their associated nodes still lack that prefix. Some entries like fit and vblock create intermediate files whose names are based on an entry unique name. This name is constructed from their node's path by concatenating the parents with dots up to the binman node, e.g. /binman/image/foo/bar becomes 'image.foo.bar'. However, we don't have this /binman/image prefix when replacing entries in such an image. The /foo/bar entry we read when doing so erroneously has the unique name of '/.foo.bar', causing permission errors when the entry attempts to create files based on that. Fix the unique-name generation by stopping at the '/' node like how it stops at the binman node. As the unique names are used as filenames, add tests that check if they're safe to use as filenames. Signed-off-by: Alper Nebi Yasak --- tools/binman/entry.py | 2 +- tools/binman/ftest.py | 31 ++++++++++++++++ tools/binman/test/230_unique_names.dts | 34 ++++++++++++++++++ tools/binman/test/231_unique_names_multi.dts | 38 ++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/230_unique_names.dts create mode 100644 tools/binman/test/231_unique_names_multi.dts diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 18a7a3510548..a07a5888643a 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -775,7 +775,7 @@ def GetUniqueName(self): node = self._node while node.parent: node = node.parent - if node.name == 'binman': + if node.name in ('binman', '/'): break name = '%s.%s' % (node.name, name) return name diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 876953f11324..e6f0159a229f 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5471,6 +5471,37 @@ def testFitSplitElfFaked(self): err, "Image '.*' is missing external blobs and is non-functional: .*") + def _CheckSafeUniqueNames(self, *images): + """Check all entries of given images for unsafe unique names""" + for image in images: + entries = {} + image._CollectEntries(entries, {}, image) + for entry in entries.values(): + uniq = entry.GetUniqueName() + + # Used as part of a filename, so must not be absolute paths. + self.assertFalse(os.path.isabs(uniq)) + + def testSafeUniqueNames(self): + """Test entry unique names are safe in single image configuration""" + data = self._DoReadFileRealDtb('230_unique_names.dts') + + orig_image = control.images['image'] + image_fname = tools.get_output_filename('image.bin') + image = Image.FromFile(image_fname) + + self._CheckSafeUniqueNames(orig_image, image) + + def testSafeUniqueNamesMulti(self): + """Test entry unique names are safe with multiple images""" + data = self._DoReadFileRealDtb('231_unique_names_multi.dts') + + orig_image = control.images['image'] + image_fname = tools.get_output_filename('image.bin') + image = Image.FromFile(image_fname) + + self._CheckSafeUniqueNames(orig_image, image) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/230_unique_names.dts b/tools/binman/test/230_unique_names.dts new file mode 100644 index 000000000000..6780d37f71f4 --- /dev/null +++ b/tools/binman/test/230_unique_names.dts @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0xc00>; + allow-repack; + + u-boot { + }; + + fdtmap { + }; + + u-boot2 { + type = "u-boot"; + }; + + text { + text = "some text"; + }; + + u-boot-dtb { + }; + + image-header { + location = "end"; + }; + }; +}; diff --git a/tools/binman/test/231_unique_names_multi.dts b/tools/binman/test/231_unique_names_multi.dts new file mode 100644 index 000000000000..db63afb445e0 --- /dev/null +++ b/tools/binman/test/231_unique_names_multi.dts @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + multiple-images; + + image { + size = <0xc00>; + allow-repack; + + u-boot { + }; + + fdtmap { + }; + + u-boot2 { + type = "u-boot"; + }; + + text { + text = "some text"; + }; + + u-boot-dtb { + }; + + image-header { + location = "end"; + }; + }; + }; +}; -- 2.35.1