Skip to content

Commit 36453c8

Browse files
ebiggersJakub Kicinski
authored andcommitted
llc: fix sk_buff refcounting in llc_conn_state_process()
If llc_conn_state_process() sees that llc_conn_service() put the skb on a list, it will drop one fewer references to it. This is wrong because the current behavior is that llc_conn_service() never consumes a reference to the skb. The code also makes the number of skb references being dropped conditional on which of ind_prim and cfm_prim are nonzero, yet neither of these affects how many references are *acquired*. So there is extra code that tries to fix this up by sometimes taking another reference. Remove the unnecessary/broken refcounting logic and instead just add an skb_get() before the only two places where an extra reference is actually consumed. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
1 parent fc8d5db commit 36453c8

1 file changed

Lines changed: 6 additions & 27 deletions

File tree

‎net/llc/llc_conn.c‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,19 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
6464
struct llc_sock *llc = llc_sk(skb->sk);
6565
struct llc_conn_state_ev *ev = llc_conn_ev(skb);
6666

67-
/*
68-
* We have to hold the skb, because llc_conn_service will kfree it in
69-
* the sending path and we need to look at the skb->cb, where we encode
70-
* llc_conn_state_ev.
71-
*/
72-
skb_get(skb);
7367
ev->ind_prim = ev->cfm_prim = 0;
7468
/*
7569
* Send event to state machine
7670
*/
7771
rc = llc_conn_service(skb->sk, skb);
7872
if (unlikely(rc != 0)) {
7973
printk(KERN_ERR "%s: llc_conn_service failed\n", __func__);
80-
goto out_kfree_skb;
81-
}
82-
83-
if (unlikely(!ev->ind_prim && !ev->cfm_prim)) {
84-
/* indicate or confirm not required */
85-
if (!skb->next)
86-
goto out_kfree_skb;
8774
goto out_skb_put;
8875
}
8976

90-
if (unlikely(ev->ind_prim && ev->cfm_prim)) /* Paranoia */
91-
skb_get(skb);
92-
9377
switch (ev->ind_prim) {
9478
case LLC_DATA_PRIM:
79+
skb_get(skb);
9580
llc_save_primitive(sk, skb, LLC_DATA_PRIM);
9681
if (unlikely(sock_queue_rcv_skb(sk, skb))) {
9782
/*
@@ -108,6 +93,7 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
10893
* skb->sk pointing to the newly created struct sock in
10994
* llc_conn_handler. -acme
11095
*/
96+
skb_get(skb);
11197
skb_queue_tail(&sk->sk_receive_queue, skb);
11298
sk->sk_state_change(sk);
11399
break;
@@ -123,7 +109,6 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
123109
sk->sk_state_change(sk);
124110
}
125111
}
126-
kfree_skb(skb);
127112
sock_put(sk);
128113
break;
129114
case LLC_RESET_PRIM:
@@ -132,14 +117,11 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
132117
* RESET is not being notified to upper layers for now
133118
*/
134119
printk(KERN_INFO "%s: received a reset ind!\n", __func__);
135-
kfree_skb(skb);
136120
break;
137121
default:
138-
if (ev->ind_prim) {
122+
if (ev->ind_prim)
139123
printk(KERN_INFO "%s: received unknown %d prim!\n",
140124
__func__, ev->ind_prim);
141-
kfree_skb(skb);
142-
}
143125
/* No indication */
144126
break;
145127
}
@@ -181,15 +163,12 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
181163
printk(KERN_INFO "%s: received a reset conf!\n", __func__);
182164
break;
183165
default:
184-
if (ev->cfm_prim) {
166+
if (ev->cfm_prim)
185167
printk(KERN_INFO "%s: received unknown %d prim!\n",
186168
__func__, ev->cfm_prim);
187-
break;
188-
}
189-
goto out_skb_put; /* No confirmation */
169+
/* No confirmation */
170+
break;
190171
}
191-
out_kfree_skb:
192-
kfree_skb(skb);
193172
out_skb_put:
194173
kfree_skb(skb);
195174
return rc;

0 commit comments

Comments
 (0)