Re: [patch 1/3] lsm: add bsdjail module

Andrew Morton
2004-10-06T23:32:00Z

Serge Hallyn <serue@us.ibm.com> wrote:
>
>
> Attached is a patch against the security Kconfig and Makefile to support
> bsdjail, as well as the bsdjail.c file itself. bsdjail offers
> functionality similar to (but more limited than) the vserver patch.

I don't recall anyone requesting this feature. Tell me why we should add
it to Linux?

> +
> +#define in_use(x) (x->jail_flags & IN_USE)
> +#define set_in_use(x) (x->jail_flags |= IN_USE)
> +
> +#define got_network(x) (x->jail_flags & (GOT_IPV4 | GOT_IPV6))
> +#define got_ipv4(x) (x->jail_flags & (GOT_IPV4))
> +#define got_ipv6(x) (x->jail_flags & (GOT_IPV6))
> +#define set_ipv4(x) (x->jail_flags |= GOT_IPV4)
> +#define set_ipv6(x) (x->jail_flags |= GOT_IPV6)
> +#define unset_got_ipv4(x) (x->jail_flags &= ~GOT_IPV4)
> +#define unset_got_ipv6(x) (x->jail_flags &= ~GOT_IPV6)
> +#define get_task_security(task) (task->security)
> +#define get_inode_security(inode) (inode->i_security)
> +#define get_sock_security(sock) (sock->sk_security)
> +#define get_file_security(file) (file->f_security)
> +#define get_ipc_security(ipc) (ipc->security)
> +#define jail_of(proc) (get_task_security(proc))
> +

The above tricks may make the code easier to type, but I find they make the
code harder for others to read, and that's more important. We prefer to
open-code such things.

> + if (tsec->root_pathname)
> + kfree(tsec->root_pathname);
> + if (tsec->ip4_addr_name)
> + kfree(tsec->ip4_addr_name);
> + if (tsec->ip6_addr_name)
> + kfree(tsec->ip6_addr_name);

kfree(0) is permitted. Some people like to do the double test anyway but I
don't think it adds much here.

> + set_task_security(task,NULL);

whitespace nit: In some places you have spaces after the commas and in
others you do not.

> + kref_put(&tsec->kref, release_jail);

This is the preferred style.