Commit d55d87fd authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller
Browse files

net: Move rx skb_orphan call to where needed

In order to get the tun driver to account packets, we need to be
able to receive packets with destructors set.  To be on the safe
side, I added an skb_orphan call for all protocols by default since
some of them (IP in particular) cannot handle receiving packets
destructors properly.

Now it seems that at least one protocol (CAN) expects to be able
to pass skb->sk through the rx path without getting clobbered.

So this patch attempts to fix this properly by moving the skb_orphan
call to where it's actually needed.  In particular, I've added it
to skb_set_owner_[rw] which is what most users of skb->destructor

This is actually an improvement for tun too since it means that
we only give back the amount charged to the socket when the skb
is passed to another socket that will also be charged accordingly.
Signed-off-by: default avatarHerbert Xu <>
Tested-by: default avatarOliver Hartkopp <>
Signed-off-by: default avatarDavid S. Miller <>
parent d5fdd6ba
......@@ -448,6 +448,7 @@ static inline void sctp_skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
struct sctp_ulpevent *event = sctp_skb2event(skb);
skb->sk = sk;
skb->destructor = sctp_sock_rfree;
atomic_add(event->rmem_len, &sk->sk_rmem_alloc);
......@@ -1250,6 +1250,7 @@ static inline int sk_has_allocations(const struct sock *sk)
static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
skb->sk = sk;
skb->destructor = sock_wfree;
......@@ -1262,6 +1263,7 @@ static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
skb->sk = sk;
skb->destructor = sock_rfree;
atomic_add(skb->truesize, &sk->sk_rmem_alloc);
......@@ -437,8 +437,7 @@ free:
int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *ptype, struct net_device *orig_dev)
skb->sk = NULL; /* Initially we don't know who it's for */
skb->destructor = NULL; /* Who initializes this, dammit?! */
if (!net_eq(dev_net(dev), &init_net)) {
......@@ -2310,8 +2310,6 @@ ncls:
if (!skb)
goto out;
type = skb->protocol;
&ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) {
......@@ -913,9 +913,6 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
/* Clean up the original one to keep it in listen state */
/* Wow ! What is that ? Jean II */
skb->sk = NULL;
skb->destructor = NULL;
......@@ -196,6 +196,7 @@ static int ircomm_lmp_data_request(struct ircomm_cb *self,
/* Don't forget to refcount it - see ircomm_tty_do_softint() */
skb->destructor = ircomm_lmp_flow_control;
if ((self->pkt_count++ > 7) && (self->flow_status == FLOW_START)) {
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