Skip to content

dd if=/dev/zero of=sealed shows I/O error only #13403

Description

@pajod

IO errors on output should spell out the filename (and, whenever ambiguous: the operation, not only writes can fail!)

dd: writing to '/dev/stdout': Operation not permitted
dd: failed to truncate to 512 bytes in output file '/dev/stdout': Operation not permitted

Not merely a bland error:

dd: IO error: Permission denied

Repro:

import subprocess, fcntl, os
fd = os.memfd_create("repro", os.MFD_ALLOW_SEALING)
try:
    os.ftruncate(fd, 512*4)
    fcntl.fcntl(fd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_SHRINK)
    s = lambda *arg: subprocess.run(["/usr/bin/dd", "status=none", "if=/dev/zero", "seek=1", *arg], stdout=fd).returncode
    subprocess.run(["/usr/bin/dd", "--version"])
    EXPECT_OK, EXPECT_FOOTGUN, EXPECT_FAIL = 0, 0, 1
    print(EXPECT_FOOTGUN == s("count=1"))
    print(EXPECT_OK == s("count=1", "of=/dev/stdout", "conv=notrunc"))
    print(EXPECT_FAIL == s("count=1", "of=/dev/stdout"))
    fcntl.fcntl(fd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_GROW)
    print(EXPECT_FAIL == s("count=5"))
    print(EXPECT_FAIL == s("count=5", "of=/dev/stdout", "conv=notrunc"))
finally:
    os.close(fd)
  • I would not worry too much about the first one, maybe GNU implementations can be convinced that this is, and always was, undocumented and unintended, all the way back to 1997
  • drop the status=none and a test like this covers most of what is missed from not checking tests/dd/fail-ftruncate-fstat.sh
  • Related: dd if=/proc/self/mem of=/dev/null shows I/O error only #10579

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions