Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netlink: add netlink_skb_set_owner_r()

For mmap'ed I/O a netlink specific skb destructor needs to be invoked
after the final kfree_skb() to clean up state. This doesn't work currently
since the skb's ownership is transfered to the receiving socket using
skb_set_owner_r(), which orphans the skb, thereby invoking the destructor
prematurely.

Since netlink doesn't account skbs to the originating socket, there's no
need to orphan the skb. Add a netlink specific skb_set_owner_r() variant
that does not orphan the skb and use a netlink specific destructor to
call sock_rfree().

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Patrick McHardy and committed by
David S. Miller
cf0a018a 1298ca46

+17 -3
+17 -3
net/netlink/af_netlink.c
··· 119 119 kfree(cb); 120 120 } 121 121 122 + static void netlink_skb_destructor(struct sk_buff *skb) 123 + { 124 + sock_rfree(skb); 125 + } 126 + 127 + static void netlink_skb_set_owner_r(struct sk_buff *skb, struct sock *sk) 128 + { 129 + WARN_ON(skb->sk != NULL); 130 + skb->sk = sk; 131 + skb->destructor = netlink_skb_destructor; 132 + atomic_add(skb->truesize, &sk->sk_rmem_alloc); 133 + sk_mem_charge(sk, skb->truesize); 134 + } 135 + 122 136 static void netlink_sock_destruct(struct sock *sk) 123 137 { 124 138 struct netlink_sock *nlk = nlk_sk(sk); ··· 834 820 } 835 821 return 1; 836 822 } 837 - skb_set_owner_r(skb, sk); 823 + netlink_skb_set_owner_r(skb, sk); 838 824 return 0; 839 825 } 840 826 ··· 904 890 ret = -ECONNREFUSED; 905 891 if (nlk->netlink_rcv != NULL) { 906 892 ret = skb->len; 907 - skb_set_owner_r(skb, sk); 893 + netlink_skb_set_owner_r(skb, sk); 908 894 NETLINK_CB(skb).sk = ssk; 909 895 nlk->netlink_rcv(skb); 910 896 consume_skb(skb); ··· 976 962 977 963 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf && 978 964 !test_bit(NETLINK_CONGESTED, &nlk->state)) { 979 - skb_set_owner_r(skb, sk); 965 + netlink_skb_set_owner_r(skb, sk); 980 966 __netlink_sendskb(sk, skb); 981 967 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1); 982 968 }