Skip to content

Commit 21abb1e

Browse files
committed
Smack: IPv6 host labeling
IPv6 appears to be (finally) coming of age with the influx of autonomous devices. In support of this, add the ability to associate a Smack label with IPv6 addresses. This patch also cleans up some of the conditional compilation associated with the introduction of secmark processing. It's now more obvious which bit of code goes with which feature. Signed-off-by: Casey Schaufler <[email protected]>
1 parent ca70d27 commit 21abb1e

File tree

4 files changed

+604
-161
lines changed

4 files changed

+604
-161
lines changed

Documentation/security/Smack.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Smack kernels use the CIPSO IP option. Some network
2828
configurations are intolerant of IP options and can impede
2929
access to systems that use them as Smack does.
3030

31+
Smack is used in the Tizen operating system. Please
32+
go to http://wiki.tizen.org for information about how
33+
Smack is used in Tizen.
34+
3135
The current git repository for Smack user space is:
3236

3337
git://github.com/smack-team/smack.git
@@ -108,6 +112,8 @@ in the smackfs filesystem. This pseudo-filesystem is mounted
108112
on /sys/fs/smackfs.
109113

110114
access
115+
Provided for backward compatibility. The access2 interface
116+
is preferred and should be used instead.
111117
This interface reports whether a subject with the specified
112118
Smack label has a particular access to an object with a
113119
specified Smack label. Write a fixed format access rule to
@@ -136,6 +142,8 @@ change-rule
136142
those in the fourth string. If there is no such rule it will be
137143
created using the access specified in the third and the fourth strings.
138144
cipso
145+
Provided for backward compatibility. The cipso2 interface
146+
is preferred and should be used instead.
139147
This interface allows a specific CIPSO header to be assigned
140148
to a Smack label. The format accepted on write is:
141149
"%24s%4d%4d"["%4d"]...
@@ -157,7 +165,19 @@ direct
157165
doi
158166
This contains the CIPSO domain of interpretation used in
159167
network packets.
168+
ipv6host
169+
This interface allows specific IPv6 internet addresses to be
170+
treated as single label hosts. Packets are sent to single
171+
label hosts only from processes that have Smack write access
172+
to the host label. All packets received from single label hosts
173+
are given the specified label. The format accepted on write is:
174+
"%h:%h:%h:%h:%h:%h:%h:%h label" or
175+
"%h:%h:%h:%h:%h:%h:%h:%h/%d label".
176+
The "::" address shortcut is not supported.
177+
If label is "-DELETE" a matched entry will be deleted.
160178
load
179+
Provided for backward compatibility. The load2 interface
180+
is preferred and should be used instead.
161181
This interface allows access control rules in addition to
162182
the system defined rules to be specified. The format accepted
163183
on write is:
@@ -181,6 +201,8 @@ load2
181201
permissions that are not allowed. The string "r-x--" would
182202
specify read and execute access.
183203
load-self
204+
Provided for backward compatibility. The load-self2 interface
205+
is preferred and should be used instead.
184206
This interface allows process specific access rules to be
185207
defined. These rules are only consulted if access would
186208
otherwise be permitted, and are intended to provide additional
@@ -205,6 +227,8 @@ netlabel
205227
received from single label hosts are given the specified
206228
label. The format accepted on write is:
207229
"%d.%d.%d.%d label" or "%d.%d.%d.%d/%d label".
230+
If the label specified is "-CIPSO" the address is treated
231+
as a host that supports CIPSO headers.
208232
onlycap
209233
This contains labels processes must have for CAP_MAC_ADMIN
210234
and CAP_MAC_OVERRIDE to be effective. If this file is empty
@@ -232,7 +256,8 @@ unconfined
232256
is dangerous and can ruin the proper labeling of your system.
233257
It should never be used in production.
234258

235-
You can add access rules in /etc/smack/accesses. They take the form:
259+
If you are using the smackload utility
260+
you can add access rules in /etc/smack/accesses. They take the form:
236261

237262
subjectlabel objectlabel access
238263

security/smack/smack.h

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,26 @@
1717
#include <linux/spinlock.h>
1818
#include <linux/lsm_hooks.h>
1919
#include <linux/in.h>
20+
#if IS_ENABLED(CONFIG_IPV6)
21+
#include <linux/in6.h>
22+
#endif /* CONFIG_IPV6 */
2023
#include <net/netlabel.h>
2124
#include <linux/list.h>
2225
#include <linux/rculist.h>
2326
#include <linux/lsm_audit.h>
2427

28+
/*
29+
* Use IPv6 port labeling if IPv6 is enabled and secmarks
30+
* are not being used.
31+
*/
32+
#if IS_ENABLED(CONFIG_IPV6) && !defined(CONFIG_SECURITY_SMACK_NETFILTER)
33+
#define SMACK_IPV6_PORT_LABELING 1
34+
#endif
35+
36+
#if IS_ENABLED(CONFIG_IPV6) && defined(CONFIG_SECURITY_SMACK_NETFILTER)
37+
#define SMACK_IPV6_SECMARK_LABELING 1
38+
#endif
39+
2540
/*
2641
* Smack labels were limited to 23 characters for a long time.
2742
*/
@@ -118,15 +133,30 @@ struct smack_rule {
118133
};
119134

120135
/*
121-
* An entry in the table identifying hosts.
136+
* An entry in the table identifying IPv4 hosts.
122137
*/
123-
struct smk_netlbladdr {
138+
struct smk_net4addr {
124139
struct list_head list;
125-
struct sockaddr_in smk_host; /* network address */
140+
struct in_addr smk_host; /* network address */
126141
struct in_addr smk_mask; /* network mask */
142+
int smk_masks; /* mask size */
143+
struct smack_known *smk_label; /* label */
144+
};
145+
146+
#if IS_ENABLED(CONFIG_IPV6)
147+
/*
148+
* An entry in the table identifying IPv6 hosts.
149+
*/
150+
struct smk_net6addr {
151+
struct list_head list;
152+
struct in6_addr smk_host; /* network address */
153+
struct in6_addr smk_mask; /* network mask */
154+
int smk_masks; /* mask size */
127155
struct smack_known *smk_label; /* label */
128156
};
157+
#endif /* CONFIG_IPV6 */
129158

159+
#ifdef SMACK_IPV6_PORT_LABELING
130160
/*
131161
* An entry in the table identifying ports.
132162
*/
@@ -137,6 +167,7 @@ struct smk_port_label {
137167
struct smack_known *smk_in; /* inbound label */
138168
struct smack_known *smk_out; /* outgoing label */
139169
};
170+
#endif /* SMACK_IPV6_PORT_LABELING */
140171

141172
struct smack_onlycap {
142173
struct list_head list;
@@ -170,6 +201,7 @@ enum {
170201
#define SMK_FSROOT "smackfsroot="
171202
#define SMK_FSTRANS "smackfstransmute="
172203

204+
#define SMACK_DELETE_OPTION "-DELETE"
173205
#define SMACK_CIPSO_OPTION "-CIPSO"
174206

175207
/*
@@ -252,10 +284,6 @@ struct smk_audit_info {
252284
struct smack_audit_data sad;
253285
#endif
254286
};
255-
/*
256-
* These functions are in smack_lsm.c
257-
*/
258-
struct inode_smack *new_inode_smack(struct smack_known *);
259287

260288
/*
261289
* These functions are in smack_access.c
@@ -285,7 +313,6 @@ extern struct smack_known *smack_syslog_label;
285313
#ifdef CONFIG_SECURITY_SMACK_BRINGUP
286314
extern struct smack_known *smack_unconfined;
287315
#endif
288-
extern struct smack_known smack_cipso_option;
289316
extern int smack_ptrace_rule;
290317

291318
extern struct smack_known smack_known_floor;
@@ -297,7 +324,10 @@ extern struct smack_known smack_known_web;
297324

298325
extern struct mutex smack_known_lock;
299326
extern struct list_head smack_known_list;
300-
extern struct list_head smk_netlbladdr_list;
327+
extern struct list_head smk_net4addr_list;
328+
#if IS_ENABLED(CONFIG_IPV6)
329+
extern struct list_head smk_net6addr_list;
330+
#endif /* CONFIG_IPV6 */
301331

302332
extern struct mutex smack_onlycap_lock;
303333
extern struct list_head smack_onlycap_list;

0 commit comments

Comments
 (0)