Commit e1af4779 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by John Johansen

apparmor: add #ifdef checks for secmark filtering

The newly added code fails to build when either SECMARK or
NETFILTER are disabled:

security/apparmor/lsm.c: In function 'apparmor_socket_sock_rcv_skb':
security/apparmor/lsm.c:1138:12: error: 'struct sk_buff' has no member named 'secmark'; did you mean 'mark'?

security/apparmor/lsm.c:1671:21: error: 'struct nf_hook_state' declared inside parameter list will not be visible outside of this definition or declaration [-Werror]

Add a set of #ifdef checks around it to only enable the code that
we can compile and that makes sense in that configuration.

Fixes: ab9f2115 ("apparmor: Allow filtering based on secmark policy")
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
parent 250f2da4
...@@ -1022,6 +1022,7 @@ static int apparmor_socket_shutdown(struct socket *sock, int how) ...@@ -1022,6 +1022,7 @@ static int apparmor_socket_shutdown(struct socket *sock, int how)
return aa_sock_perm(OP_SHUTDOWN, AA_MAY_SHUTDOWN, sock); return aa_sock_perm(OP_SHUTDOWN, AA_MAY_SHUTDOWN, sock);
} }
#ifdef CONFIG_NETWORK_SECMARK
/** /**
* apparmor_socket_sock_recv_skb - check perms before associating skb to sk * apparmor_socket_sock_recv_skb - check perms before associating skb to sk
* *
...@@ -1040,6 +1041,7 @@ static int apparmor_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) ...@@ -1040,6 +1041,7 @@ static int apparmor_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
return apparmor_secmark_check(ctx->label, OP_RECVMSG, AA_MAY_RECEIVE, return apparmor_secmark_check(ctx->label, OP_RECVMSG, AA_MAY_RECEIVE,
skb->secmark, sk); skb->secmark, sk);
} }
#endif
static struct aa_label *sk_peer_label(struct sock *sk) static struct aa_label *sk_peer_label(struct sock *sk)
...@@ -1134,6 +1136,7 @@ static void apparmor_sock_graft(struct sock *sk, struct socket *parent) ...@@ -1134,6 +1136,7 @@ static void apparmor_sock_graft(struct sock *sk, struct socket *parent)
ctx->label = aa_get_current_label(); ctx->label = aa_get_current_label();
} }
#ifdef CONFIG_NETWORK_SECMARK
static int apparmor_inet_conn_request(struct sock *sk, struct sk_buff *skb, static int apparmor_inet_conn_request(struct sock *sk, struct sk_buff *skb,
struct request_sock *req) struct request_sock *req)
{ {
...@@ -1145,6 +1148,7 @@ static int apparmor_inet_conn_request(struct sock *sk, struct sk_buff *skb, ...@@ -1145,6 +1148,7 @@ static int apparmor_inet_conn_request(struct sock *sk, struct sk_buff *skb,
return apparmor_secmark_check(ctx->label, OP_CONNECT, AA_MAY_CONNECT, return apparmor_secmark_check(ctx->label, OP_CONNECT, AA_MAY_CONNECT,
skb->secmark, sk); skb->secmark, sk);
} }
#endif
static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = { static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {
LSM_HOOK_INIT(ptrace_access_check, apparmor_ptrace_access_check), LSM_HOOK_INIT(ptrace_access_check, apparmor_ptrace_access_check),
...@@ -1197,13 +1201,17 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = { ...@@ -1197,13 +1201,17 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {
LSM_HOOK_INIT(socket_getsockopt, apparmor_socket_getsockopt), LSM_HOOK_INIT(socket_getsockopt, apparmor_socket_getsockopt),
LSM_HOOK_INIT(socket_setsockopt, apparmor_socket_setsockopt), LSM_HOOK_INIT(socket_setsockopt, apparmor_socket_setsockopt),
LSM_HOOK_INIT(socket_shutdown, apparmor_socket_shutdown), LSM_HOOK_INIT(socket_shutdown, apparmor_socket_shutdown),
#ifdef CONFIG_NETWORK_SECMARK
LSM_HOOK_INIT(socket_sock_rcv_skb, apparmor_socket_sock_rcv_skb), LSM_HOOK_INIT(socket_sock_rcv_skb, apparmor_socket_sock_rcv_skb),
#endif
LSM_HOOK_INIT(socket_getpeersec_stream, LSM_HOOK_INIT(socket_getpeersec_stream,
apparmor_socket_getpeersec_stream), apparmor_socket_getpeersec_stream),
LSM_HOOK_INIT(socket_getpeersec_dgram, LSM_HOOK_INIT(socket_getpeersec_dgram,
apparmor_socket_getpeersec_dgram), apparmor_socket_getpeersec_dgram),
LSM_HOOK_INIT(sock_graft, apparmor_sock_graft), LSM_HOOK_INIT(sock_graft, apparmor_sock_graft),
#ifdef CONFIG_NETWORK_SECMARK
LSM_HOOK_INIT(inet_conn_request, apparmor_inet_conn_request), LSM_HOOK_INIT(inet_conn_request, apparmor_inet_conn_request),
#endif
LSM_HOOK_INIT(cred_alloc_blank, apparmor_cred_alloc_blank), LSM_HOOK_INIT(cred_alloc_blank, apparmor_cred_alloc_blank),
LSM_HOOK_INIT(cred_free, apparmor_cred_free), LSM_HOOK_INIT(cred_free, apparmor_cred_free),
...@@ -1559,6 +1567,7 @@ static inline int apparmor_init_sysctl(void) ...@@ -1559,6 +1567,7 @@ static inline int apparmor_init_sysctl(void)
} }
#endif /* CONFIG_SYSCTL */ #endif /* CONFIG_SYSCTL */
#if defined(CONFIG_NETFILTER) && defined(CONFIG_NETWORK_SECMARK)
static unsigned int apparmor_ip_postroute(void *priv, static unsigned int apparmor_ip_postroute(void *priv,
struct sk_buff *skb, struct sk_buff *skb,
const struct nf_hook_state *state) const struct nf_hook_state *state)
...@@ -1647,6 +1656,7 @@ static int __init apparmor_nf_ip_init(void) ...@@ -1647,6 +1656,7 @@ static int __init apparmor_nf_ip_init(void)
return 0; return 0;
} }
__initcall(apparmor_nf_ip_init); __initcall(apparmor_nf_ip_init);
#endif
static int __init apparmor_init(void) static int __init apparmor_init(void)
{ {
......
...@@ -190,6 +190,7 @@ int aa_sock_file_perm(struct aa_label *label, const char *op, u32 request, ...@@ -190,6 +190,7 @@ int aa_sock_file_perm(struct aa_label *label, const char *op, u32 request,
return aa_label_sk_perm(label, op, request, sock->sk); return aa_label_sk_perm(label, op, request, sock->sk);
} }
#ifdef CONFIG_NETWORK_SECMARK
static int apparmor_secmark_init(struct aa_secmark *secmark) static int apparmor_secmark_init(struct aa_secmark *secmark)
{ {
struct aa_label *label; struct aa_label *label;
...@@ -254,3 +255,4 @@ int apparmor_secmark_check(struct aa_label *label, char *op, u32 request, ...@@ -254,3 +255,4 @@ int apparmor_secmark_check(struct aa_label *label, char *op, u32 request,
aa_secmark_perm(profile, request, secid, aa_secmark_perm(profile, request, secid,
&sa, sk)); &sa, sk));
} }
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment