Skip to content

Commit 817eff7

Browse files
committed
selinux: look for IPsec labels on both inbound and outbound packets
Previously selinux_skb_peerlbl_sid() would only check for labeled IPsec security labels on inbound packets, this patch enables it to check both inbound and outbound traffic for labeled IPsec security labels. Reported-by: Janak Desai <Janak.Desai@gtri.gatech.edu> Cc: stable@vger.kernel.org Signed-off-by: Paul Moore <pmoore@redhat.com>
1 parent 446b802 commit 817eff7

3 files changed

Lines changed: 47 additions & 14 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3829,7 +3829,7 @@ static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u16 family, u32 *sid)
38293829
u32 nlbl_sid;
38303830
u32 nlbl_type;
38313831

3832-
err = selinux_skb_xfrm_sid(skb, &xfrm_sid);
3832+
err = selinux_xfrm_skb_sid(skb, &xfrm_sid);
38333833
if (unlikely(err))
38343834
return -EACCES;
38353835
err = selinux_netlbl_skbuff_getsid(skb, family, &nlbl_type, &nlbl_sid);

‎security/selinux/include/xfrm.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb,
3939
int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb,
4040
struct common_audit_data *ad, u8 proto);
4141
int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
42+
int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid);
4243

4344
static inline void selinux_xfrm_notify_policyload(void)
4445
{
@@ -79,11 +80,12 @@ static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid,
7980
static inline void selinux_xfrm_notify_policyload(void)
8081
{
8182
}
82-
#endif
8383

84-
static inline int selinux_skb_xfrm_sid(struct sk_buff *skb, u32 *sid)
84+
static inline int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid)
8585
{
86-
return selinux_xfrm_decode_session(skb, sid, 0);
86+
*sid = SECSID_NULL;
87+
return 0;
8788
}
89+
#endif
8890

8991
#endif /* _SELINUX_XFRM_H_ */

‎security/selinux/xfrm.c‎

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,26 @@ int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x,
209209
NULL) ? 0 : 1);
210210
}
211211

212-
/*
213-
* LSM hook implementation that checks and/or returns the xfrm sid for the
214-
* incoming packet.
215-
*/
216-
int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
212+
static u32 selinux_xfrm_skb_sid_egress(struct sk_buff *skb)
217213
{
218-
u32 sid_session = SECSID_NULL;
219-
struct sec_path *sp;
214+
struct dst_entry *dst = skb_dst(skb);
215+
struct xfrm_state *x;
220216

221-
if (skb == NULL)
222-
goto out;
217+
if (dst == NULL)
218+
return SECSID_NULL;
219+
x = dst->xfrm;
220+
if (x == NULL || !selinux_authorizable_xfrm(x))
221+
return SECSID_NULL;
222+
223+
return x->security->ctx_sid;
224+
}
225+
226+
static int selinux_xfrm_skb_sid_ingress(struct sk_buff *skb,
227+
u32 *sid, int ckall)
228+
{
229+
u32 sid_session = SECSID_NULL;
230+
struct sec_path *sp = skb->sp;
223231

224-
sp = skb->sp;
225232
if (sp) {
226233
int i;
227234

@@ -247,6 +254,30 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
247254
return 0;
248255
}
249256

257+
/*
258+
* LSM hook implementation that checks and/or returns the xfrm sid for the
259+
* incoming packet.
260+
*/
261+
int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
262+
{
263+
if (skb == NULL) {
264+
*sid = SECSID_NULL;
265+
return 0;
266+
}
267+
return selinux_xfrm_skb_sid_ingress(skb, sid, ckall);
268+
}
269+
270+
int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid)
271+
{
272+
int rc;
273+
274+
rc = selinux_xfrm_skb_sid_ingress(skb, sid, 0);
275+
if (rc == 0 && *sid == SECSID_NULL)
276+
*sid = selinux_xfrm_skb_sid_egress(skb);
277+
278+
return rc;
279+
}
280+
250281
/*
251282
* LSM hook implementation that allocs and transfers uctx spec to xfrm_policy.
252283
*/

0 commit comments

Comments
 (0)