1 |
kumaneko |
111 |
/* |
2 |
|
|
* fs/sakura_bind.c |
3 |
|
|
* |
4 |
|
|
* Implementation of the Domain-Free Mandatory Access Control. |
5 |
|
|
* |
6 |
kumaneko |
856 |
* Copyright (C) 2005-2008 NTT DATA CORPORATION |
7 |
kumaneko |
111 |
* |
8 |
kumaneko |
856 |
* Version: 1.5.3-pre 2008/01/03 |
9 |
kumaneko |
111 |
* |
10 |
|
|
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
11 |
|
|
* See README.ccs for ChangeLog. |
12 |
|
|
* |
13 |
|
|
*/ |
14 |
|
|
/***** SAKURA Linux start. *****/ |
15 |
|
|
|
16 |
|
|
#include <linux/ccs_common.h> |
17 |
|
|
#include <linux/sakura.h> |
18 |
|
|
#include <linux/realpath.h> |
19 |
|
|
|
20 |
|
|
/***** The structure for reserved ports. *****/ |
21 |
|
|
|
22 |
kumaneko |
214 |
struct reserved_entry { |
23 |
kumaneko |
722 |
struct list1_head list; |
24 |
kumaneko |
621 |
bool is_deleted; /* Delete flag. */ |
25 |
kumaneko |
111 |
u16 min_port; /* Start of port number range. */ |
26 |
|
|
u16 max_port; /* End of port number range. */ |
27 |
kumaneko |
214 |
}; |
28 |
kumaneko |
111 |
|
29 |
|
|
/************************* NETWORK RESERVED ACL HANDLER *************************/ |
30 |
|
|
|
31 |
kumaneko |
722 |
static LIST1_HEAD(reservedport_list); |
32 |
kumaneko |
111 |
|
33 |
kumaneko |
621 |
static int AddReservedEntry(const u16 min_port, const u16 max_port, const bool is_delete) |
34 |
kumaneko |
111 |
{ |
35 |
kumaneko |
214 |
struct reserved_entry *new_entry, *ptr; |
36 |
kumaneko |
652 |
static DEFINE_MUTEX(lock); |
37 |
kumaneko |
111 |
int error = -ENOMEM; |
38 |
kumaneko |
652 |
mutex_lock(&lock); |
39 |
kumaneko |
722 |
list1_for_each_entry(ptr, &reservedport_list, list) { |
40 |
kumaneko |
111 |
if (ptr->min_port == min_port && max_port == ptr->max_port) { |
41 |
|
|
ptr->is_deleted = is_delete; |
42 |
kumaneko |
746 |
error = 0; |
43 |
kumaneko |
111 |
goto out; |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
if (is_delete) { |
47 |
|
|
error = -ENOENT; |
48 |
|
|
goto out; |
49 |
|
|
} |
50 |
kumaneko |
214 |
if ((new_entry = alloc_element(sizeof(*new_entry))) == NULL) goto out; |
51 |
kumaneko |
111 |
new_entry->min_port = min_port; |
52 |
|
|
new_entry->max_port = max_port; |
53 |
kumaneko |
722 |
list1_add_tail_mb(&new_entry->list, &reservedport_list); |
54 |
kumaneko |
111 |
error = 0; |
55 |
|
|
out: |
56 |
kumaneko |
652 |
mutex_unlock(&lock); |
57 |
kumaneko |
111 |
return error; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
int SAKURA_MayAutobind(const u16 port) |
61 |
|
|
{ |
62 |
|
|
/* Must not sleep, for called inside spin_lock. */ |
63 |
kumaneko |
214 |
struct reserved_entry *ptr; |
64 |
kumaneko |
111 |
if (!CheckCCSFlags(CCS_SAKURA_RESTRICT_AUTOBIND)) return 0; |
65 |
kumaneko |
722 |
list1_for_each_entry(ptr, &reservedport_list, list) { |
66 |
kumaneko |
111 |
if (ptr->min_port <= port && port <= ptr->max_port && !ptr->is_deleted) return -EPERM; |
67 |
|
|
} |
68 |
|
|
return 0; |
69 |
|
|
} |
70 |
|
|
|
71 |
kumaneko |
621 |
int AddReservedPortPolicy(char *data, const bool is_delete) |
72 |
kumaneko |
111 |
{ |
73 |
|
|
unsigned int from, to; |
74 |
|
|
if (strchr(data, ' ')) goto out; |
75 |
|
|
if (sscanf(data, "%u-%u", &from, &to) == 2) { |
76 |
|
|
if (from <= to && to < 65536) return AddReservedEntry(from, to, is_delete); |
77 |
|
|
} else if (sscanf(data, "%u", &from) == 1) { |
78 |
|
|
if (from < 65536) return AddReservedEntry(from, from, is_delete); |
79 |
|
|
} |
80 |
|
|
out: |
81 |
|
|
printk("%s: ERROR: Invalid port range '%s'\n", __FUNCTION__, data); |
82 |
|
|
return -EINVAL; |
83 |
|
|
} |
84 |
|
|
|
85 |
kumaneko |
214 |
int ReadReservedPortPolicy(struct io_buffer *head) |
86 |
kumaneko |
111 |
{ |
87 |
kumaneko |
722 |
struct list1_head *pos; |
88 |
|
|
list1_for_each_cookie(pos, head->read_var2, &reservedport_list) { |
89 |
kumaneko |
708 |
struct reserved_entry *ptr; |
90 |
kumaneko |
722 |
ptr = list1_entry(pos, struct reserved_entry, list); |
91 |
kumaneko |
708 |
if (ptr->is_deleted) continue; |
92 |
|
|
if (ptr->min_port != ptr->max_port) { |
93 |
|
|
if (io_printf(head, KEYWORD_DENY_AUTOBIND "%u-%u\n", ptr->min_port, ptr->max_port)) return -ENOMEM; |
94 |
|
|
} else { |
95 |
|
|
if (io_printf(head, KEYWORD_DENY_AUTOBIND "%u\n", ptr->min_port)) return -ENOMEM; |
96 |
kumaneko |
111 |
} |
97 |
|
|
} |
98 |
kumaneko |
708 |
return 0; |
99 |
kumaneko |
111 |
} |
100 |
|
|
|
101 |
|
|
/***** SAKURA Linux end. *****/ |