tools/testing/selftests/filesystems/openat2/rename_attack_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/openat2/rename_attack_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/filesystems/openat2/rename_attack_test.c
Extension
.c
Size
3571 bytes
Lines
160
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (fd < 0) {
			if (fd == -EAGAIN)
				eagains++;
			else if (fd == -EXDEV)
				exdevs++;
			else if (fd == -ENOENT)
				escapes++; /* escaped outside and got ENOENT... */
			else
				other_errs++; /* unexpected error */
		} else {
			if (fdequal(_metadata, fd, self->afd, NULL))
				successes++;
			else
				escapes++; /* we got an unexpected fd */
		}
		if (fd >= 0)
			close(fd);
	}

	TH_LOG("non-escapes: EAGAIN=%d EXDEV=%d E<other>=%d success=%d",
	       eagains, exdevs, other_errs, successes);
	ASSERT_EQ(escapes, 0) {
		TH_LOG("rename attack with %s (%d runs, got %d escapes)",
		       variant->name, ROUNDS, escapes);
	}
}

TEST_HARNESS_MAIN

Annotation

Implementation Notes