tools/testing/selftests/x86/ioperm.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/x86/ioperm.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/x86/ioperm.c
Extension
.c
Size
3584 bytes
Lines
165
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 (ioperm(0x81, 1, 1) != 0) {
			printf("[FAIL]\tioperm(0x81, 1, 1) failed (%d)", errno);
			return 1;
		}
		printf("[RUN]\tchild: Drop permissions to 0x80\n");
		if (ioperm(0x80, 1, 0) != 0) {
			printf("[FAIL]\tioperm(0x80, 1, 0) failed (%d)", errno);
			return 1;
		}
		expect_gp(0x80);
		return 0;
	} else {
		int status;
		if (waitpid(child, &status, 0) != child ||
		    !WIFEXITED(status)) {
			printf("[FAIL]\tChild died\n");
			nerrs++;
		} else if (WEXITSTATUS(status) != 0) {
			printf("[FAIL]\tChild failed\n");
			nerrs++;
		} else {
			printf("[OK]\tChild succeeded\n");
		}
	}

	/* Verify that the child dropping 0x80 did not affect the parent */
	printf("\tVerify that unsharing the bitmap worked\n");
	expect_ok(0x80);

	/* Test the capability checks. */
	printf("\tDrop privileges\n");
	if (setresuid(1, 1, 1) != 0) {
		printf("[WARN]\tDropping privileges failed\n");
		return 0;
	}

	printf("[RUN]\tdisable 0x80\n");
	if (ioperm(0x80, 1, 0) != 0) {
		printf("[FAIL]\tioperm(0x80, 1, 0) failed (%d)", errno);
		return 1;
	}
	printf("[OK]\tit worked\n");

	printf("[RUN]\tenable 0x80 again\n");
	if (ioperm(0x80, 1, 1) == 0) {
		printf("[FAIL]\tit succeeded but should have failed.\n");
		return 1;
	}
	printf("[OK]\tit failed\n");
	return 0;
}

Annotation

Implementation Notes