@@ -5692,38 +5692,38 @@ static int selinux_tun_dev_open(void *security)
5692
5692
static unsigned int selinux_ip_forward (void * priv , struct sk_buff * skb ,
5693
5693
const struct nf_hook_state * state )
5694
5694
{
5695
- const struct net_device * indev = state -> in ;
5696
- u16 family = state -> pf ;
5697
- int err ;
5695
+ int ifindex ;
5696
+ u16 family ;
5698
5697
char * addrp ;
5699
5698
u32 peer_sid ;
5700
5699
struct common_audit_data ad ;
5701
5700
struct lsm_network_audit net = {0 ,};
5702
- u8 secmark_active ;
5703
- u8 netlbl_active ;
5704
- u8 peerlbl_active ;
5701
+ int secmark_active , peerlbl_active ;
5705
5702
5706
5703
if (!selinux_policycap_netpeer ())
5707
5704
return NF_ACCEPT ;
5708
5705
5709
5706
secmark_active = selinux_secmark_enabled ();
5710
- netlbl_active = netlbl_enabled ();
5711
5707
peerlbl_active = selinux_peerlbl_enabled ();
5712
5708
if (!secmark_active && !peerlbl_active )
5713
5709
return NF_ACCEPT ;
5714
5710
5711
+ family = state -> pf ;
5715
5712
if (selinux_skb_peerlbl_sid (skb , family , & peer_sid ) != 0 )
5716
5713
return NF_DROP ;
5717
5714
5715
+ ifindex = state -> in -> ifindex ;
5718
5716
ad .type = LSM_AUDIT_DATA_NET ;
5719
5717
ad .u .net = & net ;
5720
- ad .u .net -> netif = indev -> ifindex ;
5718
+ ad .u .net -> netif = ifindex ;
5721
5719
ad .u .net -> family = family ;
5722
5720
if (selinux_parse_skb (skb , & ad , & addrp , 1 , NULL ) != 0 )
5723
5721
return NF_DROP ;
5724
5722
5725
5723
if (peerlbl_active ) {
5726
- err = selinux_inet_sys_rcv_skb (dev_net (indev ), indev -> ifindex ,
5724
+ int err ;
5725
+
5726
+ err = selinux_inet_sys_rcv_skb (state -> net , ifindex ,
5727
5727
addrp , family , peer_sid , & ad );
5728
5728
if (err ) {
5729
5729
selinux_netlbl_err (skb , family , err , 1 );
@@ -5737,7 +5737,7 @@ static unsigned int selinux_ip_forward(void *priv, struct sk_buff *skb,
5737
5737
SECCLASS_PACKET , PACKET__FORWARD_IN , & ad ))
5738
5738
return NF_DROP ;
5739
5739
5740
- if (netlbl_active )
5740
+ if (netlbl_enabled () )
5741
5741
/* we do this in the FORWARD path and not the POST_ROUTING
5742
5742
* path because we want to make sure we apply the necessary
5743
5743
* labeling before IPsec is applied so we can leverage AH
@@ -5751,7 +5751,6 @@ static unsigned int selinux_ip_forward(void *priv, struct sk_buff *skb,
5751
5751
static unsigned int selinux_ip_output (void * priv , struct sk_buff * skb ,
5752
5752
const struct nf_hook_state * state )
5753
5753
{
5754
- u16 family = state -> pf ;
5755
5754
struct sock * sk ;
5756
5755
u32 sid ;
5757
5756
@@ -5785,33 +5784,32 @@ static unsigned int selinux_ip_output(void *priv, struct sk_buff *skb,
5785
5784
sid = sksec -> sid ;
5786
5785
} else
5787
5786
sid = SECINITSID_KERNEL ;
5788
- if (selinux_netlbl_skbuff_setsid (skb , family , sid ) != 0 )
5787
+ if (selinux_netlbl_skbuff_setsid (skb , state -> pf , sid ) != 0 )
5789
5788
return NF_DROP ;
5790
5789
5791
5790
return NF_ACCEPT ;
5792
5791
}
5793
5792
5794
5793
5795
5794
static unsigned int selinux_ip_postroute_compat (struct sk_buff * skb ,
5796
- int ifindex ,
5797
- u16 family )
5795
+ const struct nf_hook_state * state )
5798
5796
{
5799
- struct sock * sk = skb_to_full_sk ( skb ) ;
5797
+ struct sock * sk ;
5800
5798
struct sk_security_struct * sksec ;
5801
5799
struct common_audit_data ad ;
5802
5800
struct lsm_network_audit net = {0 ,};
5803
- char * addrp ;
5804
5801
u8 proto ;
5805
5802
5806
- if (sk == NULL )
5803
+ if (state -> sk == NULL )
5807
5804
return NF_ACCEPT ;
5805
+ sk = skb_to_full_sk (skb );
5808
5806
sksec = sk -> sk_security ;
5809
5807
5810
5808
ad .type = LSM_AUDIT_DATA_NET ;
5811
5809
ad .u .net = & net ;
5812
- ad .u .net -> netif = ifindex ;
5813
- ad .u .net -> family = family ;
5814
- if (selinux_parse_skb (skb , & ad , & addrp , 0 , & proto ))
5810
+ ad .u .net -> netif = state -> out -> ifindex ;
5811
+ ad .u .net -> family = state -> pf ;
5812
+ if (selinux_parse_skb (skb , & ad , NULL , 0 , & proto ))
5815
5813
return NF_DROP ;
5816
5814
5817
5815
if (selinux_secmark_enabled ())
@@ -5830,24 +5828,22 @@ static unsigned int selinux_ip_postroute(void *priv,
5830
5828
struct sk_buff * skb ,
5831
5829
const struct nf_hook_state * state )
5832
5830
{
5833
- const struct net_device * outdev = state -> out ;
5834
- u16 family = state -> pf ;
5831
+ u16 family ;
5835
5832
u32 secmark_perm ;
5836
5833
u32 peer_sid ;
5837
- int ifindex = outdev -> ifindex ;
5834
+ int ifindex ;
5838
5835
struct sock * sk ;
5839
5836
struct common_audit_data ad ;
5840
5837
struct lsm_network_audit net = {0 ,};
5841
5838
char * addrp ;
5842
- u8 secmark_active ;
5843
- u8 peerlbl_active ;
5839
+ int secmark_active , peerlbl_active ;
5844
5840
5845
5841
/* If any sort of compatibility mode is enabled then handoff processing
5846
5842
* to the selinux_ip_postroute_compat() function to deal with the
5847
5843
* special handling. We do this in an attempt to keep this function
5848
5844
* as fast and as clean as possible. */
5849
5845
if (!selinux_policycap_netpeer ())
5850
- return selinux_ip_postroute_compat (skb , ifindex , family );
5846
+ return selinux_ip_postroute_compat (skb , state );
5851
5847
5852
5848
secmark_active = selinux_secmark_enabled ();
5853
5849
peerlbl_active = selinux_peerlbl_enabled ();
@@ -5873,6 +5869,7 @@ static unsigned int selinux_ip_postroute(void *priv,
5873
5869
return NF_ACCEPT ;
5874
5870
#endif
5875
5871
5872
+ family = state -> pf ;
5876
5873
if (sk == NULL ) {
5877
5874
/* Without an associated socket the packet is either coming
5878
5875
* from the kernel or it is being forwarded; check the packet
@@ -5933,6 +5930,7 @@ static unsigned int selinux_ip_postroute(void *priv,
5933
5930
secmark_perm = PACKET__SEND ;
5934
5931
}
5935
5932
5933
+ ifindex = state -> out -> ifindex ;
5936
5934
ad .type = LSM_AUDIT_DATA_NET ;
5937
5935
ad .u .net = & net ;
5938
5936
ad .u .net -> netif = ifindex ;
@@ -5950,7 +5948,7 @@ static unsigned int selinux_ip_postroute(void *priv,
5950
5948
u32 if_sid ;
5951
5949
u32 node_sid ;
5952
5950
5953
- if (sel_netif_sid (dev_net ( outdev ) , ifindex , & if_sid ))
5951
+ if (sel_netif_sid (state -> net , ifindex , & if_sid ))
5954
5952
return NF_DROP ;
5955
5953
if (avc_has_perm (& selinux_state ,
5956
5954
peer_sid , if_sid ,
0 commit comments