Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDFEA606A31A for ; Wed, 28 Oct 2026 05:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.u-boot-project.org header.i=@lists.u-boot-project.org header.a=rsa-sha256 header.s=default header.b=EZDQWAWY; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Pgzd/9cf Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C6A8380F1E; Wed, 28 Oct 2026 05:51:26 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id S0bxtehvaEMM; Wed, 28 Oct 2026 05:51:25 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 5AFFD80F3D Authentication-Results: smtp1.osuosl.org; arc=pass header.oldest-pass=0 smtp.remote-ip=140.211.166.142 ARC-Seal: i=2; d=osuosl.org; s=arc; a=rsa-sha256; cv=pass; t=1793166685; b=SCPXyUIEgxZMgMEqc+QyHc4UZDMbWx0fB7vo/7Qx4vATQU17Qf+KVLJWwBDM7W0o1oCn dHSFNOcM6viA85fRmt+bHWr3Wz7kp6+veNJwqzJGDvV7V34BO/GXpGvrOGEaFQ+SrXkzM ITvo9FsL5tV0AQ2rOXKGVHt0uu1uI8DmL6iId4ezsP9OVdAB9fRJ2Tp5QI2cv9M2amAk3 i/xGo0tVPbj6DB0iLNc7vF+yYp7yzVEQNMVcpv8oQhfdkMduO5m6SAlFUdlQmJuwz4Tdw FsiV3CGb+xbiYYcdv/FzJCbA0gt9edjyY+oZAnYglnX8m1veqVn4zB61nMLrEXZ13FA== ARC-Message-Signature: i=2; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1793166685; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg: X-Received:Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:X-BeenThere:X-Mailman-Version:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Errors-To; bh=/nyuYFtjwVd+F943mjZBxxaistO/TJ0cypvzCWey8RQ=; b=lv1AiwxMufBpEa8jU9MV27izogUhvKPzICNeUWI0kEoHuP0tsbNlHvA/jd1BcpSxqZJK WOfr2Dyg9iPGcoBu7akl58cEYZMB/1Zn0IGV9nw5ysQe72C11rZx+ZI41oZyOsBNQKgx6 gmRATkpcrE8OwOR7kGFzpRPv1I/N3RebqGu6DVEWDA54pJR0OatSgWB/3TLC7dq8XxnOV L4bW+nD54Tj+2U2JCmSCiRmF/yJEckgNymDoflz4V6iKdBj9kC64ynDHnAgeKCwHDRHFN z6aH6VxMNxijQNNzgn9LvOUJdd+R81G9ErNRi9C7xbbZOoNYnvSFukrFhDtWJzlRr2g== ARC-Authentication-Results: i=2; smtp1.osuosl.org; arc=pass header.oldest-pass=0 smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=u-boot-bounces@lists.u-boot-project.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.u-boot-project.org; s=default; t=1793166685; bh=/nyuYFtjwVd+F943mjZBxxaistO/TJ0cypvzCWey8RQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EZDQWAWYz9G+AI+VidVUe3BqjpOqCTlRygVe2zMP3uTLp3xwH+0kQlCjLjhHLD9Ve Z8PxIaqBw6CljXBB6R4H1fi8Op0zaV9gL3yle5/mT/ZpLIHS6g774OigCN8WtHYKXN bVV5vtLcMcGd8UgaLlAbCmhAmiTsFbvJYnrJpnmox8F2LPm3RQDoALmKSV+XJBqOfH VVc0CH+nEkJrFtsiktDo/kOpo7R/fWUX89X2bZu3flCnxfDufSTpfLA4D2gGOASQvH +DmfRmuIJwGB/HTsdMK7OslWAvVSHxmrDhTtvSfEDSBqH/8Y1XUuTrQGFZgdYfPc3D 4OEfsqGprSvfQ== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp1.osuosl.org (Postfix) with ESMTP id 5AFFD80F3D; Wed, 28 Oct 2026 05:51:25 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists1.osuosl.org (Postfix) with ESMTP id B39014D1 for ; Wed, 28 Oct 2026 05:51:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 98769606E3 for ; Wed, 28 Oct 2026 05:51:23 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id vsDNqIWz74oO for ; Wed, 28 Oct 2026 05:51:22 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org F409960770 Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip="2a00:1450:4864:20::32d" ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1793166682; b=pGBTPYxM5LVD8gij9jS/6//ytLVxSgpUKEoVo9LPb0zOp8U96d1rswEjJU60nsyHnoa6 v/yJK7CWS8OD/iemKTYgN+nkmk9ZPpv7ddzYSstYO2tl0llWD4iF0XTYDQDsIAmyeUph+ zbj64H1iIx0HRl2IMksxWW2dwjtNv7Y8AO3pZJ2wtZY0Djsw8NbWFlErG5tggbX0uC0fq R+L7ed4SyBTBMYBH7oUfmJs6ARqYIFnn0/551ryDYRGqy0f8WLgAJDM4uUS/gomciRcHB WdiqrsLI9UtnMD97rp88MMWNtdkL5Y2FaRyeW8FmyormDHF3rI1YAchznrNEynSKF8w== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1793166682; h=Received-SPF:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:In-Reply-To:References; bh=/nyuYFtjwVd+F943mjZBxxaistO/TJ0cypvzCWey8RQ=; b=bygvE5Txcm5WSA8u+rZswtzo29YbhIqwUn8JUx5VjVhFhdm27OGJFZML7ewZmxFTjia5 x6NeP/r8kMPHhEL1KgNk0Aek5npXbtCYvsk2D+WPyyI5yA2jDDEa4XA9HO1WQULzjTVHC yTFmemZ44ex0RTJb1WJSvJ39NYddgTOUhYpPzqGbtr+Xn+67kD5ZZSkuJFbiEB0MUxBtp usGdctfUic6kNB+ZQmXYHwLBr98GdXL/Kw3J41AO28KY/PB0jOoNwgW3L1j9zu76rh97W dHFx733d1+oUW/H0I8ImrzAS2vi/axZghPqbUd9XyjBIuFAE13wOr+iHKDvL57Tylxw== ARC-Authentication-Results: i=1; smtp3.osuosl.org; dmarc=pass header.from=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="Pgzd/9cf"; arc=none smtp.remote-ip="2a00:1450:4864:20::32d" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a00:1450:4864:20::32d; helo=mail-wm1-x32d.google.com; envelope-from=anabobillo3@gmail.com; receiver= Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Pgzd/9cf Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by smtp3.osuosl.org (Postfix) with ESMTPS id F409960770 for ; Wed, 28 Oct 2026 05:51:20 +0000 (UTC) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4a35d5d4a20so5724855e9.2 for ; Tue, 27 Oct 2026 22:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793166679; x=1793771479; darn=lists.u-boot-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=/nyuYFtjwVd+F943mjZBxxaistO/TJ0cypvzCWey8RQ=; b=Pgzd/9cfNATqQXR/k3jtcRvheF+hST9cZZgouRWyH2T2/3HnSBfIbSGRLgXTfrGLci xKdU9nQXW0kjPgK48T3snFkMmi71RC6FzzksHJLULItT8CG+Eayh4ofsHHoBcHq6Eh7a wsuyuAVHyf9a1v1hcI3wMliSF+lAW9+yRGbuixbUctmR4zbViZ4AtwG7gwSHcvbrF7Tt xH8pUs0WOlPiCMSxeJek5odl5baEX69J/z/H+bDfTkAp6ZTjGs36N+y+pEz0Yrt3NoTF 0iUSRWggE24/mZVx9yODWM0Za4RbFIiaX+RwShTvnZ9eUcWEhIKRcwrsZRUtiuqPIkyP TTCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793166679; x=1793771479; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/nyuYFtjwVd+F943mjZBxxaistO/TJ0cypvzCWey8RQ=; b=nI+yloOm38y8FKWcaPrebfL8jUngQz1MfXBiECxos3LfnaqMvnEngSj0pnD8DZrGds 17hSAwrXN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b1804b1-4a96667dd75mr21955545e9.11.1793166678810; Tue, 27 Oct 2026 22:51:18 -0700 (PDT) Received: from [127.0.0.1] ([85.204.204.133]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a94f5311bdsm21832325e9.5.2026.10.27.22.51.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Oct 2026 22:51:18 -0700 (PDT) From: Ana Bobillo To: Tom Rini Cc: u-boot@lists.u-boot-project.org, Tony Dinh , Simon Glass Subject: [PATCH v2 6/6] test: fs: ext4: add tests for corrupt on-disk indices Date: Wed, 28 Oct 2026 05:51:17 +0000 Message-ID: <497901c9-56b5-4e94-9f9d-7430c7cbafa1@gmail.com> In-Reply-To: <78892543-03de-412e-831f-de840765be59@gmail.com> References: <78892543-03de-412e-831f-de840765be59@gmail.com> X-BeenThere: u-boot@lists.u-boot-project.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: U-Boot discussion List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: From: Ana Bobillo Add tests that make a small ext4 image with mkfs.ext4 and check how U-Boot handles the on-disk indices that the previous patches check: - test_fs_ext_oob_extent_header: an extent header with more entries than the inode can hold must give "invalid extent block" - test_fs_ext_oob_extent_loop: an extent index node pointing back at itself must give "invalid extent block" rather than loop for ever - test_fs_ext_oob_triple_indirect: a sparse file must read back correctly through the second and third entries of its triple indirect block - test_fs_ext_oob_group_layout: writing to a filesystem with s_blocks_per_group of zero must be refused - test_fs_ext_oob_delete_block: replacing a file whose indirect block lies past the end of the filesystem must fail with "Invalid block number" - test_fs_ext_oob_delete_inode: replacing a file whose directory entry names an inode past the last block group, or the journal's inode, must fail with "Invalid inode number" - test_fs_ext_oob_last_inode: replacing a file whose inode is the last of its block group must work and leave the filesystem clean for e2fsck Each image is removed and host device 0 unbound even when a test fails. Signed-off-by: Ana Bobillo --- Changes in v2: - Say that some tests patch the image directly rather than with debugfs - Replace victim_field() with victim_has(), using DEVNULL - Remove the image and unbind host 0 even when a test fails - Use f-strings and record the new file's pylint score as 10.00 - Add tests for the extent depth check, the triple indirect lookup, the last inode of a group and a directory entry naming the journal's inode scripts/pylint.base | 1 + test/py/tests/test_fs/test_ext_oob.py | 310 ++++++++++++++++++++++++++ 2 files changed, 311 insertions(+) diff --git a/scripts/pylint.base b/scripts/pylint.base index bc39e2385a3..1905e32588f 100644 --- a/scripts/pylint.base +++ b/scripts/pylint.base @@ -50,6 +50,7 @@ test_tests_test_fs_fstest_helpers.py 4.29 test_tests_test_fs_test_basic.py 1.90 test_tests_test_fs_test_erofs.py 8.97 test_tests_test_fs_test_ext.py 1.48 +test_tests_test_fs_test_ext_oob.py 10.00 test_tests_test_fs_test_fs_cmd.py 8.00 test_tests_test_fs_test_fs_fat.py 2.50 test_tests_test_fs_test_mkdir.py 3.04 diff --git a/test/py/tests/test_fs/test_ext_oob.py b/test/py/tests/test_fs/test_ext_oob.py new file mode 100644 index 00000000000..12f4095c6e5 --- /dev/null +++ b/test/py/tests/test_fs/test_ext_oob.py @@ -0,0 +1,310 @@ +# SPDX-License-Identifier: GPL-2.0+ + +"""Test ext4 handling of corrupt on-disk indices + +Most tests make a small ext4 image with mkfs.ext4, corrupt one on-disk +field, with debugfs or by patching the image directly, and check that +U-Boot rejects the image and is still responsive afterwards. The others +check that U-Boot reads or replaces a valid file whose blocks or inode lie +at a boundary that it used to get wrong. +""" + +from contextlib import contextmanager +import os +import struct +from subprocess import run, check_output, DEVNULL +import zlib +import pytest +from fstest_defs import ADDR + +VICTIM = b'victim file\n' + + +@contextmanager +def ext4_image(ubman, prefix, opts=()): + """Make an 8 MiB ext4 image and remove it once the test is done + + mk_fs() takes no mkfs.ext4 options, which some tests need. When the with + block ends, whether or not the test passed, the image is removed and + host device 0, which the test may have bound to it, is unbound. + + Args: + ubman (ConsoleBase): U-Boot console + prefix (str): prefix of the image file name + opts (list of str): extra options for mkfs.ext4 + + Yields: + str: path of the image + """ + img = os.path.join(ubman.config.persistent_data_dir, f'{prefix}.ext4.img') + with open(img, 'wb') as fil: + fil.truncate(8 << 20) + try: + # U-Boot does not write to a filesystem with metadata checksums + run(['mkfs.ext4', '-q', '-F', '-O', '^metadata_csum', *opts, img], + check=True) + yield img + finally: + os.remove(img) + ubman.run_command('host unbind 0') + + +def debugfs(img, cmds): + """Run debugfs commands which write to an image + + Args: + img (str): path of the image + cmds (list of str): debugfs commands + """ + script = '\n'.join(cmds) + '\n' + run(['debugfs', '-w', '-f', '-', img], input=script.encode(), + capture_output=True, check=True) + + +def add_file(img, name, chunks): + """Write a file into the root directory of an image with debugfs + + Args: + img (str): path of the image + name (str): name of the file + chunks (dict): data of the file (bytes) by offset (int), the rest + of the file being left as holes + """ + src = f'{img}.{name}' + with open(src, 'wb') as fil: + for offset, data in chunks.items(): + fil.seek(offset) + fil.write(data) + try: + debugfs(img, [f'write {src} {name}']) + finally: + os.remove(src) + + +def read_at(img, offset, size): + """Read size bytes of the image at offset""" + with open(img, 'rb') as fil: + fil.seek(offset) + return fil.read(size) + + +def write_at(img, offset, data): + """Write data into the image at offset""" + with open(img, 'r+b') as fil: + fil.seek(offset) + fil.write(data) + + +def block_size(img): + """Get the block size of the filesystem in an image""" + return 1024 << struct.unpack(' {zlib.crc32(data):08x}' in out + assert 'alive' in ubman.run_command('echo alive') + + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_ext4_write') +@pytest.mark.requiredtool('debugfs') +def test_fs_ext_oob_group_layout(ubman): + """ext4fs_init(): a superblock with zero blocks per group must make + writes fail rather than divide by zero""" + with ext4_image(ubman, 'ext_oob_geo') as img: + # s_blocks_per_group is at offset 32 of the superblock at byte 1024 + write_at(img, 1024 + 32, struct.pack(' {zlib.crc32(b"A" * 0x1000):08x}' in out + assert 'alive' in ubman.run_command('echo alive') + run(['e2fsck', '-fn', img], capture_output=True, check=True)