Page MenuHomeFreeBSD

jail: declare argument structure of jail(2) with const fields
Needs ReviewPublic

Authored by glebius on Sat, Oct 3, 4:39 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 9, 10:46 AM
Unknown Object (File)
Fri, Oct 9, 1:14 AM
Unknown Object (File)
Thu, Oct 8, 1:19 AM
Unknown Object (File)
Wed, Oct 7, 5:44 AM
Unknown Object (File)
Wed, Oct 7, 3:00 AM
Unknown Object (File)
Tue, Oct 6, 9:27 PM
Unknown Object (File)
Tue, Oct 6, 6:32 PM
Unknown Object (File)
Tue, Oct 6, 5:39 PM
Subscribers

Details

Reviewers
jamie
kevans
Group Reviewers
Jails
Summary

The syscall doesn't modify this memory. With added 'const' one can use
string literals and const IP addresses to initialize a jail. Example:

const struct in_addr laddr = { htonl(INADDR_LOOPBACK) };
struct jail jconf = {

		.version = JAIL_API_VERSION,
		.path =  "/",
		.hostname = "test",
		.ip4s = 1,
		.ip4 = &laddr,

};
error = jail(&jconf);

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77680
Build 74563: arc lint + arc unit

Event Timeline

The const strings seem unlike to cause any trouble, but I wonder what code is out there along the lines of:

struct jail j;
...
j.ip4 = calloc(nip4, sizeof(struct in_addr));
for (int i = 0; i < nip4; ++i)
    inet_aton(ip4_arg[i], &j.ip4[i]);

Yeah, that's true. I can also imagine a program that would modify a string as a member of struct jail before passing to jail(2). :(