Skip to content

Auto-generated .csproj for C# submissions includes <AllowUnsafeBlocks>true</AllowUnsafeBlocks> #39

Description

@FedorPortnoi

Summary

When compiling a .cs_net7 submission, the ECS runner auto-generates a project file that includes <AllowUnsafeBlocks>true</AllowUnsafeBlocks>. This enables unsafe code in all submitted C# solutions without restriction.

Affected File

ecs-runner/src/main/java/com/topcoder/runner/EcsRunnerMain.java, lines 3288–3301

Files.write(csproj, Arrays.asList(
    "<Project Sdk=\"Microsoft.NET.Sdk\">",
    "  <PropertyGroup>",
    "    <TargetFramework>net7.0</TargetFramework>",
    "    <OutputType>Exe</OutputType>",
    "    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>",   // ← here
    "  </PropertyGroup>",
    "</Project>"
), StandardCharsets.UTF_8);

Impact

With unsafe enabled, a C# submission can:

  1. Use raw pointer arithmetic — allows reading/writing arbitrary memory addresses within the process
  2. Call native code via P/Invoke — combined with unsafe blocks, the submission can invoke open, read, mmap, and other native syscalls that are not blocked by the seccomp filter (which only blocks socket() and socketpair())
  3. Enumerate /proc filesystem via native opendir/readdir calls without triggering any seccomp rule
  4. Read other files in the container (/tmp/mm-isolated-scorer-*.json, /tmp/tester-*.jar, etc.) using native file I/O even if managed I/O were somehow restricted

The seccomp filter in mm-net-isolate.c only blocks network socket creation. Enabling unsafe C# code opens a direct path to all other OS-level operations.

Expected

Remove <AllowUnsafeBlocks>true</AllowUnsafeBlocks> from the generated project file. Competitive programming problems do not require unsafe memory access. If a specific challenge needs it, it should be an explicit opt-in configured per-challenge rather than a global default.

Severity: Medium

Metadata

Metadata

Assignees

No one assigned

    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