Skip to content

Commit 54abc68

Browse files
edumazetdavem330
authored andcommitted
net: add skb_to_full_sk() helper and use it in selinux_netlbl_skbuff_setsid()
Generalize selinux_skb_sk() added in commit 212cd08 ("selinux: fix random read in selinux_ip_postroute_compat()") so that we can use it other contexts. Use it right away in selinux_netlbl_skbuff_setsid() Fixes: ca6fb06 ("tcp: attach SYNACK messages to request sockets instead of listener") Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fb9a10d commit 54abc68

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎include/net/inet_sock.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ struct inet_sock {
210210
#define IP_CMSG_ORIGDSTADDR BIT(6)
211211
#define IP_CMSG_CHECKSUM BIT(7)
212212

213+
/* SYNACK messages might be attached to request sockets.
214+
* Some places want to reach the listener in this case.
215+
*/
216+
static inline struct sock *skb_to_full_sk(const struct sk_buff *skb)
217+
{
218+
struct sock *sk = skb->sk;
219+
220+
if (sk && sk->sk_state == TCP_NEW_SYN_RECV)
221+
sk = inet_reqsk(sk)->rsk_listener;
222+
return sk;
223+
}
224+
213225
static inline struct inet_sock *inet_sk(const struct sock *sk)
214226
{
215227
return (struct inet_sock *)sk;

‎security/selinux/hooks.c‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4931,23 +4931,11 @@ static unsigned int selinux_ipv4_output(void *priv,
49314931
return selinux_ip_output(skb, PF_INET);
49324932
}
49334933

4934-
/* SYNACK messages might be attached to request sockets.
4935-
* To get back to sk_security, we need to look at the listener.
4936-
*/
4937-
static struct sock *selinux_skb_sk(const struct sk_buff *skb)
4938-
{
4939-
struct sock *sk = skb->sk;
4940-
4941-
if (sk && sk->sk_state == TCP_NEW_SYN_RECV)
4942-
sk = inet_reqsk(sk)->rsk_listener;
4943-
return sk;
4944-
}
4945-
49464934
static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
49474935
int ifindex,
49484936
u16 family)
49494937
{
4950-
struct sock *sk = selinux_skb_sk(skb);
4938+
struct sock *sk = skb_to_full_sk(skb);
49514939
struct sk_security_struct *sksec;
49524940
struct common_audit_data ad;
49534941
struct lsm_network_audit net = {0,};
@@ -5002,7 +4990,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb,
50024990
if (!secmark_active && !peerlbl_active)
50034991
return NF_ACCEPT;
50044992

5005-
sk = selinux_skb_sk(skb);
4993+
sk = skb_to_full_sk(skb);
50064994

50074995
#ifdef CONFIG_XFRM
50084996
/* If skb->dst->xfrm is non-NULL then the packet is undergoing an IPsec

‎security/selinux/netlabel.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ int selinux_netlbl_skbuff_setsid(struct sk_buff *skb,
245245

246246
/* if this is a locally generated packet check to see if it is already
247247
* being labeled by it's parent socket, if it is just exit */
248-
sk = skb->sk;
248+
sk = skb_to_full_sk(skb);
249249
if (sk != NULL) {
250250
struct sk_security_struct *sksec = sk->sk_security;
251251
if (sksec->nlbl_state != NLBL_REQSKB)

0 commit comments

Comments
 (0)