8 #include <linux/slab.h>
52 u8 *
const min = ptr->
ip[0].in6_u.u6_addr8;
53 u8 *
const max = ptr->
ip[1].in6_u.u6_addr8;
57 if (!
strchr(address,
':') &&
58 in4_pton(address, -1, min,
'-', &end) > 0) {
61 ptr->
ip[1].s6_addr32[0] = ptr->
ip[0].s6_addr32[0];
62 else if (*end++ !=
'-' ||
63 in4_pton(end, -1, max,
'\0', &end) <= 0 || *end)
67 if (
in6_pton(address, -1, min,
'-', &end) > 0) {
71 else if (*end++ !=
'-' ||
72 in6_pton(end, -1, max,
'\0', &end) <= 0 || *end)
89 static void tomoyo_print_ipv4(
char *
buffer,
const unsigned int buffer_len,
92 snprintf(buffer, buffer_len,
"%pI4%c%pI4", min_ip,
93 *min_ip == *max_ip ?
'\0' :
'-', max_ip);
106 static void tomoyo_print_ipv6(
char *
buffer,
const unsigned int buffer_len,
110 snprintf(buffer, buffer_len,
"%pI6c%c%pI6c", min_ip,
111 !
memcmp(min_ip, max_ip, 16) ?
'\0' :
'-', max_ip);
127 tomoyo_print_ipv6(buf, size, &ptr->
ip[0], &ptr->
ip[1]);
129 tomoyo_print_ipv4(buf, size, &ptr->
ip[0].s6_addr32[0],
130 &ptr->
ip[1].s6_addr32[0]);
137 static const u8 tomoyo_inet2mac
160 static const u8 tomoyo_unix2mac
199 tomoyo_same_number_union(&p1->
port, &p2->
port);
217 tomoyo_same_name_union(&p1->
name, &p2->
name);
231 const bool is_delete)
257 const bool is_delete)
297 if (param->
data[0] ==
'@') {
308 e.
port.values[1] > 65535)
311 tomoyo_same_inet_acl,
312 tomoyo_merge_inet_acl);
314 tomoyo_put_group(e.
address.group);
345 tomoyo_same_unix_acl,
346 tomoyo_merge_unix_acl);
385 tomoyo_print_ipv6(buf,
sizeof(buf), (
const struct in6_addr *)
386 address, (
const struct in6_addr *) address);
388 tomoyo_print_ipv4(buf,
sizeof(buf), address, address);
390 snprintf(buf + len,
sizeof(buf) - len,
" %u",
437 &acl->
address.ip[1], size) <= 0;
468 const int idx = tomoyo_read_lock();
483 error = tomoyo_audit_inet_log(&r);
486 tomoyo_read_unlock(idx);
500 static int tomoyo_check_inet_address(
const struct sockaddr *
addr,
501 const unsigned int addr_len,
529 return tomoyo_inet_entry(address);
543 const int idx = tomoyo_read_lock();
550 char *buf = address->
unix0.addr;
571 error = tomoyo_audit_unix_log(&r);
577 tomoyo_read_unlock(idx);
590 static int tomoyo_check_unix_address(
struct sockaddr *addr,
591 const unsigned int addr_len,
600 return tomoyo_unix_entry(address);
608 static bool tomoyo_kernel_service(
void)
621 static u8 tomoyo_sock_family(
struct sock *
sk)
625 if (tomoyo_kernel_service())
627 family = sk->sk_family;
648 const u8 family = tomoyo_sock_family(sock->
sk);
649 const unsigned int type = sock->
type;
656 const int error = sock->
ops->getname(sock, (
struct sockaddr *)
657 &addr, &addr_len, 0);
665 return tomoyo_check_unix_address((
struct sockaddr *) &addr,
667 return tomoyo_check_inet_address((
struct sockaddr *) &addr, addr_len,
681 struct sockaddr *addr,
int addr_len)
684 const u8 family = tomoyo_sock_family(sock->
sk);
685 const unsigned int type = sock->
type;
703 return tomoyo_check_unix_address(addr, addr_len, &address);
704 return tomoyo_check_inet_address(addr, addr_len, sock->
sk->sk_protocol,
721 const u8 family = tomoyo_sock_family(sock->
sk);
722 const unsigned int type = sock->
type;
738 return tomoyo_check_unix_address(addr, addr_len, &address);
739 return tomoyo_check_inet_address(addr, addr_len, sock->
sk->sk_protocol,
756 const u8 family = tomoyo_sock_family(sock->
sk);
757 const unsigned int type = sock->
type;
765 return tomoyo_check_unix_address((
struct sockaddr *)
770 sock->
sk->sk_protocol, &address);