Skip to content

Commit cdac74d

Browse files
author
James Morris
committed
Merge branch 'smack-for-4.13' of git://github.com/cschaufler/smack-next into next
2 parents e4b0852 + f28e783 commit cdac74d

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

security/smack/smack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ int smk_netlbl_mls(int, char *, struct netlbl_lsm_secattr *, int);
320320
struct smack_known *smk_import_entry(const char *, int);
321321
void smk_insert_entry(struct smack_known *skp);
322322
struct smack_known *smk_find_entry(const char *);
323-
int smack_privileged(int cap);
323+
bool smack_privileged(int cap);
324324
void smk_destroy_label_list(struct list_head *list);
325325

326326
/*

security/smack/smack_access.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,35 +627,38 @@ DEFINE_MUTEX(smack_onlycap_lock);
627627
* Is the task privileged and allowed to be privileged
628628
* by the onlycap rule.
629629
*
630-
* Returns 1 if the task is allowed to be privileged, 0 if it's not.
630+
* Returns true if the task is allowed to be privileged, false if it's not.
631631
*/
632-
int smack_privileged(int cap)
632+
bool smack_privileged(int cap)
633633
{
634634
struct smack_known *skp = smk_of_current();
635635
struct smack_known_list_elem *sklep;
636+
int rc;
636637

637638
/*
638639
* All kernel tasks are privileged
639640
*/
640641
if (unlikely(current->flags & PF_KTHREAD))
641-
return 1;
642+
return true;
642643

643-
if (!capable(cap))
644-
return 0;
644+
rc = cap_capable(current_cred(), &init_user_ns, cap,
645+
SECURITY_CAP_AUDIT);
646+
if (rc)
647+
return false;
645648

646649
rcu_read_lock();
647650
if (list_empty(&smack_onlycap_list)) {
648651
rcu_read_unlock();
649-
return 1;
652+
return true;
650653
}
651654

652655
list_for_each_entry_rcu(sklep, &smack_onlycap_list, list) {
653656
if (sklep->smk_label == skp) {
654657
rcu_read_unlock();
655-
return 1;
658+
return true;
656659
}
657660
}
658661
rcu_read_unlock();
659662

660-
return 0;
663+
return false;
661664
}

security/smack/smack_lsm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ static int smack_file_receive(struct file *file)
19151915
smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
19161916
smk_ad_setfield_u_fs_path(&ad, file->f_path);
19171917

1918-
if (S_ISSOCK(inode->i_mode)) {
1918+
if (inode->i_sb->s_magic == SOCKFS_MAGIC) {
19191919
sock = SOCKET_I(inode);
19201920
ssp = sock->sk->sk_security;
19211921
tsp = current_security();

security/smack/smack_netfilter.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/netfilter_ipv6.h>
1919
#include <linux/netdevice.h>
2020
#include <net/inet_sock.h>
21+
#include <net/net_namespace.h>
2122
#include "smack.h"
2223

2324
#if IS_ENABLED(CONFIG_IPV6)
@@ -74,20 +75,29 @@ static struct nf_hook_ops smack_nf_ops[] = {
7475
#endif /* IPV6 */
7576
};
7677

77-
static int __init smack_nf_ip_init(void)
78+
static int __net_init smack_nf_register(struct net *net)
79+
{
80+
return nf_register_net_hooks(net, smack_nf_ops,
81+
ARRAY_SIZE(smack_nf_ops));
82+
}
83+
84+
static void __net_exit smack_nf_unregister(struct net *net)
7885
{
79-
int err;
86+
nf_unregister_net_hooks(net, smack_nf_ops, ARRAY_SIZE(smack_nf_ops));
87+
}
8088

89+
static struct pernet_operations smack_net_ops = {
90+
.init = smack_nf_register,
91+
.exit = smack_nf_unregister,
92+
};
93+
94+
static int __init smack_nf_ip_init(void)
95+
{
8196
if (smack_enabled == 0)
8297
return 0;
8398

8499
printk(KERN_DEBUG "Smack: Registering netfilter hooks\n");
85-
86-
err = nf_register_hooks(smack_nf_ops, ARRAY_SIZE(smack_nf_ops));
87-
if (err)
88-
pr_info("Smack: nf_register_hooks: error %d\n", err);
89-
90-
return 0;
100+
return register_pernet_subsys(&smack_net_ops);
91101
}
92102

93103
__initcall(smack_nf_ip_init);

0 commit comments

Comments
 (0)