---
title: "CWE-243: Creation of chroot Jail Without Changing Working Directory"
url: https://radicalnotion.ai/cwe/cwe-243
type: cwe
description: "The product uses the chroot() system call to create a jail, but it does not change the working directory afterward."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-243: Creation of chroot Jail Without Changing Working Directory

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 0
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

The product uses the chroot() system call to create a jail, but it does not change the working directory afterward.

## Background

The chroot() system call allows a process to change its perception of the root directory of the file system. After properly invoking chroot(), a process cannot access any files outside the directory tree defined by the new root directory. Such an environment is called a chroot jail and is commonly used to prevent the possibility that a process could be subverted and used to access unauthorized files. For instance, many FTP servers run in chroot jails to prevent an attacker who discovers a new vulnerability in the server from being able to download the password file or other sensitive files on the system.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |

## Applicable platforms

**Languages:** C (Undetermined), C++ (Undetermined)

**Operating systems:** Unix (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Confidentiality, Integrity | Read Files or Directories, Modify Files or Directories | If the working directory is not changed after the chroot() call, relative paths may still refer to file system resources outside of the jail. Attackers may be able to read or write to files outside of the jail. |

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

Consider the following source code from a (hypothetical) FTP server:

Bad code:

```c
chroot("/var/ftproot");
...
fgets(filename, sizeof(filename), network);
localfile = fopen(filename, "r");
while ((len = fread(buf, 1, sizeof(buf), localfile)) != EOF) {
    fwrite(buf, 1, sizeof(buf), network);
}
fclose(localfile);
```

This code is responsible for reading a filename from the network, opening the corresponding file on the local machine, and sending the contents over the network. This code could be used to implement the FTP GET command. The FTP server calls chroot() in its initialization routines in an attempt to prevent access to files outside of /var/ftproot. But because the server does not change the current working directory by calling chdir("/"), an attacker could request the file "../../../../../etc/passwd" and obtain a copy of the system password file.

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-573](https://radicalnotion.ai/cwe/cwe-573) | Improper Following of Specification by Caller |
| Parent | [CWE-669](https://radicalnotion.ai/cwe/cwe-669) | Incorrect Resource Transfer Between Spheres |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Directory Restriction | - | - |
| Software Fault Patterns | Failed chroot jail | SFP17 | - |

## Frequently asked questions

### What is CWE-243?

The product uses the chroot() system call to create a jail, but it does not change the working directory afterward.

### How is CWE-243 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-243?

Exploiting CWE-243 can lead to: Read Files or Directories, Modify Files or Directories.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/243.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-243). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
