Skip to content

Commit 61af143

Browse files
committed
Merge tag 'Smack-for-6.15' of https://github.com/cschaufler/smack-next
Pull smack updates from Casey Schaufler: "This is a larger set of patches than usual, consisting of a set of build clean-ups, a rework of error handling in setting up CIPSO label specification and a bug fix in network labeling" * tag 'Smack-for-6.15' of https://github.com/cschaufler/smack-next: smack: recognize ipv4 CIPSO w/o categories smack: Revert "smackfs: Added check catlen" smack: remove /smack/logging if audit is not configured smack: ipv4/ipv6: tcp/dccp/sctp: fix incorrect child socket label smack: dont compile ipv6 code unless ipv6 is configured Smack: fix typos and spelling errors
2 parents 59c017c + a158a93 commit 61af143

File tree

4 files changed

+43
-52
lines changed

4 files changed

+43
-52
lines changed

security/smack/smack.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
/*
4444
* This is the repository for labels seen so that it is
45-
* not necessary to keep allocating tiny chuncks of memory
45+
* not necessary to keep allocating tiny chunks of memory
4646
* and so that they can be shared.
4747
*
4848
* Labels are never modified in place. Anytime a label
@@ -152,6 +152,7 @@ struct smk_net4addr {
152152
struct smack_known *smk_label; /* label */
153153
};
154154

155+
#if IS_ENABLED(CONFIG_IPV6)
155156
/*
156157
* An entry in the table identifying IPv6 hosts.
157158
*/
@@ -162,7 +163,9 @@ struct smk_net6addr {
162163
int smk_masks; /* mask size */
163164
struct smack_known *smk_label; /* label */
164165
};
166+
#endif /* CONFIG_IPV6 */
165167

168+
#ifdef SMACK_IPV6_PORT_LABELING
166169
/*
167170
* An entry in the table identifying ports.
168171
*/
@@ -175,6 +178,7 @@ struct smk_port_label {
175178
short smk_sock_type; /* Socket type */
176179
short smk_can_reuse;
177180
};
181+
#endif /* SMACK_IPV6_PORT_LABELING */
178182

179183
struct smack_known_list_elem {
180184
struct list_head list;
@@ -315,7 +319,9 @@ extern struct smack_known smack_known_web;
315319
extern struct mutex smack_known_lock;
316320
extern struct list_head smack_known_list;
317321
extern struct list_head smk_net4addr_list;
322+
#if IS_ENABLED(CONFIG_IPV6)
318323
extern struct list_head smk_net6addr_list;
324+
#endif /* CONFIG_IPV6 */
319325

320326
extern struct mutex smack_onlycap_lock;
321327
extern struct list_head smack_onlycap_list;
@@ -426,19 +432,19 @@ static inline struct smack_known *smk_of_current(void)
426432
return smk_of_task(smack_cred(current_cred()));
427433
}
428434

435+
void smack_log(char *subject_label, char *object_label,
436+
int request,
437+
int result, struct smk_audit_info *auditdata);
438+
439+
#ifdef CONFIG_AUDIT
440+
429441
/*
430442
* logging functions
431443
*/
432444
#define SMACK_AUDIT_DENIED 0x1
433445
#define SMACK_AUDIT_ACCEPT 0x2
434446
extern int log_policy;
435447

436-
void smack_log(char *subject_label, char *object_label,
437-
int request,
438-
int result, struct smk_audit_info *auditdata);
439-
440-
#ifdef CONFIG_AUDIT
441-
442448
/*
443449
* some inline functions to set up audit data
444450
* they do nothing if CONFIG_AUDIT is not set

security/smack/smack_access.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ LIST_HEAD(smack_known_list);
4545
*/
4646
static u32 smack_next_secid = 10;
4747

48+
#ifdef CONFIG_AUDIT
4849
/*
4950
* what events do we log
5051
* can be overwritten at run-time by /smack/logging
5152
*/
5253
int log_policy = SMACK_AUDIT_DENIED;
54+
#endif /* CONFIG_AUDIT */
5355

5456
/**
5557
* smk_access_entry - look up matching access rule
@@ -242,7 +244,7 @@ int smk_tskacc(struct task_smack *tsp, struct smack_known *obj_known,
242244
}
243245

244246
/*
245-
* Allow for priviliged to override policy.
247+
* Allow for privileged to override policy.
246248
*/
247249
if (rc != 0 && smack_privileged(CAP_MAC_OVERRIDE))
248250
rc = 0;
@@ -276,7 +278,7 @@ int smk_curacc(struct smack_known *obj_known,
276278
}
277279

278280
/**
279-
* smack_str_from_perm : helper to transalate an int to a
281+
* smack_str_from_perm : helper to translate an int to a
280282
* readable string
281283
* @string : the string to fill
282284
* @access : the int

security/smack/smack_lsm.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ static int smack_file_send_sigiotask(struct task_struct *tsk,
19341934
*/
19351935
file = fown->file;
19361936

1937-
/* we don't log here as rc can be overriden */
1937+
/* we don't log here as rc can be overridden */
19381938
blob = smack_file(file);
19391939
skp = *blob;
19401940
rc = smk_access(skp, tkp, MAY_DELIVER, NULL);
@@ -2492,6 +2492,7 @@ static struct smack_known *smack_ipv4host_label(struct sockaddr_in *sip)
24922492
return NULL;
24932493
}
24942494

2495+
#if IS_ENABLED(CONFIG_IPV6)
24952496
/*
24962497
* smk_ipv6_localhost - Check for local ipv6 host address
24972498
* @sip: the address
@@ -2559,6 +2560,7 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip)
25592560

25602561
return NULL;
25612562
}
2563+
#endif /* CONFIG_IPV6 */
25622564

25632565
/**
25642566
* smack_netlbl_add - Set the secattr on a socket
@@ -2663,6 +2665,7 @@ static int smk_ipv4_check(struct sock *sk, struct sockaddr_in *sap)
26632665
return rc;
26642666
}
26652667

2668+
#if IS_ENABLED(CONFIG_IPV6)
26662669
/**
26672670
* smk_ipv6_check - check Smack access
26682671
* @subject: subject Smack label
@@ -2695,6 +2698,7 @@ static int smk_ipv6_check(struct smack_known *subject,
26952698
rc = smk_bu_note("IPv6 check", subject, object, MAY_WRITE, rc);
26962699
return rc;
26972700
}
2701+
#endif /* CONFIG_IPV6 */
26982702

26992703
#ifdef SMACK_IPV6_PORT_LABELING
27002704
/**
@@ -3027,7 +3031,9 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
30273031
return 0;
30283032
if (addrlen < offsetofend(struct sockaddr, sa_family))
30293033
return 0;
3030-
if (IS_ENABLED(CONFIG_IPV6) && sap->sa_family == AF_INET6) {
3034+
3035+
#if IS_ENABLED(CONFIG_IPV6)
3036+
if (sap->sa_family == AF_INET6) {
30313037
struct sockaddr_in6 *sip = (struct sockaddr_in6 *)sap;
30323038
struct smack_known *rsp = NULL;
30333039

@@ -3047,6 +3053,8 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
30473053

30483054
return rc;
30493055
}
3056+
#endif /* CONFIG_IPV6 */
3057+
30503058
if (sap->sa_family != AF_INET || addrlen < sizeof(struct sockaddr_in))
30513059
return 0;
30523060
rc = smk_ipv4_check(sock->sk, (struct sockaddr_in *)sap);
@@ -4195,7 +4203,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
41954203
/*
41964204
* Receiving a packet requires that the other end
41974205
* be able to write here. Read access is not required.
4198-
* This is the simplist possible security model
4206+
* This is the simplest possible security model
41994207
* for networking.
42004208
*/
42014209
rc = smk_access(skp, ssp->smk_in, MAY_WRITE, &ad);
@@ -4342,29 +4350,6 @@ static int smack_socket_getpeersec_dgram(struct socket *sock,
43424350
return 0;
43434351
}
43444352

4345-
/**
4346-
* smack_sock_graft - Initialize a newly created socket with an existing sock
4347-
* @sk: child sock
4348-
* @parent: parent socket
4349-
*
4350-
* Set the smk_{in,out} state of an existing sock based on the process that
4351-
* is creating the new socket.
4352-
*/
4353-
static void smack_sock_graft(struct sock *sk, struct socket *parent)
4354-
{
4355-
struct socket_smack *ssp;
4356-
struct smack_known *skp = smk_of_current();
4357-
4358-
if (sk == NULL ||
4359-
(sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
4360-
return;
4361-
4362-
ssp = smack_sock(sk);
4363-
ssp->smk_in = skp;
4364-
ssp->smk_out = skp;
4365-
/* cssp->smk_packet is already set in smack_inet_csk_clone() */
4366-
}
4367-
43684353
/**
43694354
* smack_inet_conn_request - Smack access check on connect
43704355
* @sk: socket involved
@@ -4701,7 +4686,7 @@ static int smack_post_notification(const struct cred *w_cred,
47014686
* @gfp: type of the memory for the allocation
47024687
*
47034688
* Prepare to audit cases where (@field @op @rulestr) is true.
4704-
* The label to be audited is created if necessay.
4689+
* The label to be audited is created if necessary.
47054690
*/
47064691
static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule,
47074692
gfp_t gfp)
@@ -5179,7 +5164,6 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
51795164
LSM_HOOK_INIT(sk_free_security, smack_sk_free_security),
51805165
#endif
51815166
LSM_HOOK_INIT(sk_clone_security, smack_sk_clone_security),
5182-
LSM_HOOK_INIT(sock_graft, smack_sock_graft),
51835167
LSM_HOOK_INIT(inet_conn_request, smack_inet_conn_request),
51845168
LSM_HOOK_INIT(inet_csk_clone, smack_inet_csk_clone),
51855169

security/smack/smackfs.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ enum smk_inos {
4141
SMK_AMBIENT = 7, /* internet ambient label */
4242
SMK_NET4ADDR = 8, /* single label hosts */
4343
SMK_ONLYCAP = 9, /* the only "capable" label */
44+
#ifdef CONFIG_AUDIT
4445
SMK_LOGGING = 10, /* logging */
46+
#endif /* CONFIG_AUDIT */
4547
SMK_LOAD_SELF = 11, /* task specific rules */
4648
SMK_ACCESSES = 12, /* access policy */
4749
SMK_MAPPED = 13, /* CIPSO level indicating mapped label */
@@ -165,7 +167,7 @@ static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
165167
#define SMK_LOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSLEN)
166168

167169
/*
168-
* Stricly for CIPSO level manipulation.
170+
* Strictly for CIPSO level manipulation.
169171
* Set the category bit number in a smack label sized buffer.
170172
*/
171173
static inline void smack_catset_bit(unsigned int cat, char *catsetp)
@@ -812,7 +814,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file)
812814
static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
813815
size_t count, loff_t *ppos, int format)
814816
{
815-
struct netlbl_lsm_catmap *old_cat, *new_cat = NULL;
817+
struct netlbl_lsm_catmap *old_cat;
816818
struct smack_known *skp;
817819
struct netlbl_lsm_secattr ncats;
818820
char mapcatset[SMK_CIPSOLEN];
@@ -899,22 +901,15 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
899901

900902
smack_catset_bit(cat, mapcatset);
901903
}
902-
ncats.flags = 0;
903-
if (catlen == 0) {
904-
ncats.attr.mls.cat = NULL;
905-
ncats.attr.mls.lvl = maplevel;
906-
new_cat = netlbl_catmap_alloc(GFP_ATOMIC);
907-
if (new_cat)
908-
new_cat->next = ncats.attr.mls.cat;
909-
ncats.attr.mls.cat = new_cat;
910-
skp->smk_netlabel.flags &= ~(1U << 3);
911-
rc = 0;
912-
} else {
913-
rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
914-
}
904+
905+
rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
915906
if (rc >= 0) {
916907
old_cat = skp->smk_netlabel.attr.mls.cat;
917908
rcu_assign_pointer(skp->smk_netlabel.attr.mls.cat, ncats.attr.mls.cat);
909+
if (ncats.attr.mls.cat)
910+
skp->smk_netlabel.flags |= NETLBL_SECATTR_MLS_CAT;
911+
else
912+
skp->smk_netlabel.flags &= ~(u32)NETLBL_SECATTR_MLS_CAT;
918913
skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
919914
synchronize_rcu();
920915
netlbl_catmap_free(old_cat);
@@ -2133,6 +2128,7 @@ static const struct file_operations smk_unconfined_ops = {
21332128
};
21342129
#endif /* CONFIG_SECURITY_SMACK_BRINGUP */
21352130

2131+
#ifdef CONFIG_AUDIT
21362132
/**
21372133
* smk_read_logging - read() for /smack/logging
21382134
* @filp: file pointer, not actually used
@@ -2197,6 +2193,7 @@ static const struct file_operations smk_logging_ops = {
21972193
.write = smk_write_logging,
21982194
.llseek = default_llseek,
21992195
};
2196+
#endif /* CONFIG_AUDIT */
22002197

22012198
/*
22022199
* Seq_file read operations for /smack/load-self
@@ -2883,8 +2880,10 @@ static int smk_fill_super(struct super_block *sb, struct fs_context *fc)
28832880
"netlabel", &smk_net4addr_ops, S_IRUGO|S_IWUSR},
28842881
[SMK_ONLYCAP] = {
28852882
"onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
2883+
#ifdef CONFIG_AUDIT
28862884
[SMK_LOGGING] = {
28872885
"logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
2886+
#endif /* CONFIG_AUDIT */
28882887
[SMK_LOAD_SELF] = {
28892888
"load-self", &smk_load_self_ops, S_IRUGO|S_IWUGO},
28902889
[SMK_ACCESSES] = {

0 commit comments

Comments
 (0)