Skip to content

Commit 8af43b6

Browse files
cgzonespcmoore
authored andcommitted
selinux: support wildcard network interface names
Add support for wildcard matching of network interface names. This is useful for auto-generated interfaces, for example podman creates network interfaces for containers with the naming scheme podman0, podman1, podman2, ... To maintain backward compatibility guard this feature with a new policy capability 'netif_wildcard'. Netifcon definitions are compared against in the order given by the policy, so userspace tools should sort them in a reasonable order. Signed-off-by: Christian Göttsche <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 6ae0042 commit 8af43b6

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

security/selinux/include/policycap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum {
1515
POLICYDB_CAP_IOCTL_SKIP_CLOEXEC,
1616
POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT,
1717
POLICYDB_CAP_NETLINK_XPERM,
18+
POLICYDB_CAP_NETIF_WILDCARD,
1819
__POLICYDB_CAP_MAX
1920
};
2021
#define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)

security/selinux/include/policycap_names.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const char *const selinux_policycap_names[__POLICYDB_CAP_MAX] = {
1818
"ioctl_skip_cloexec",
1919
"userspace_initial_context",
2020
"netlink_xperm",
21+
"netif_wildcard",
2122
};
2223
/* clang-format on */
2324

security/selinux/include/security.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ static inline bool selinux_policycap_netlink_xperm(void)
202202
selinux_state.policycap[POLICYDB_CAP_NETLINK_XPERM]);
203203
}
204204

205+
static inline bool selinux_policycap_netif_wildcard(void)
206+
{
207+
return READ_ONCE(
208+
selinux_state.policycap[POLICYDB_CAP_NETIF_WILDCARD]);
209+
}
210+
205211
struct selinux_policy_convert_data;
206212

207213
struct selinux_load_state {
@@ -301,7 +307,7 @@ int security_ib_pkey_sid(u64 subnet_prefix, u16 pkey_num, u32 *out_sid);
301307

302308
int security_ib_endport_sid(const char *dev_name, u8 port_num, u32 *out_sid);
303309

304-
int security_netif_sid(char *name, u32 *if_sid);
310+
int security_netif_sid(const char *name, u32 *if_sid);
305311

306312
int security_node_sid(u16 domain, void *addr, u32 addrlen, u32 *out_sid);
307313

security/selinux/ss/services.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <linux/in.h>
4747
#include <linux/sched.h>
4848
#include <linux/audit.h>
49+
#include <linux/parser.h>
4950
#include <linux/vmalloc.h>
5051
#include <linux/lsm_hooks.h>
5152
#include <net/netlabel.h>
@@ -2572,19 +2573,22 @@ int security_ib_endport_sid(const char *dev_name, u8 port_num, u32 *out_sid)
25722573
* @name: interface name
25732574
* @if_sid: interface SID
25742575
*/
2575-
int security_netif_sid(char *name, u32 *if_sid)
2576+
int security_netif_sid(const char *name, u32 *if_sid)
25762577
{
25772578
struct selinux_policy *policy;
25782579
struct policydb *policydb;
25792580
struct sidtab *sidtab;
25802581
int rc;
25812582
struct ocontext *c;
2583+
bool wildcard_support;
25822584

25832585
if (!selinux_initialized()) {
25842586
*if_sid = SECINITSID_NETIF;
25852587
return 0;
25862588
}
25872589

2590+
wildcard_support = selinux_policycap_netif_wildcard();
2591+
25882592
retry:
25892593
rc = 0;
25902594
rcu_read_lock();
@@ -2594,8 +2598,14 @@ int security_netif_sid(char *name, u32 *if_sid)
25942598

25952599
c = policydb->ocontexts[OCON_NETIF];
25962600
while (c) {
2597-
if (strcmp(name, c->u.name) == 0)
2598-
break;
2601+
if (wildcard_support) {
2602+
if (match_wildcard(c->u.name, name))
2603+
break;
2604+
} else {
2605+
if (strcmp(c->u.name, name) == 0)
2606+
break;
2607+
}
2608+
25992609
c = c->next;
26002610
}
26012611

0 commit comments

Comments
 (0)