Skip to content

Commit ca913f1

Browse files
can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem leak
If the rx-offload skb_queue is full can_rx_offload_queue_sorted() will not queue the skb and return with an error. None of the callers of this function, issue a kfree_skb() to free the not queued skb. This results in a memory leak. This patch fixes the problem by freeing the skb in case of a full queue. The return value is adjusted to -ENOBUFS to better reflect the actual problem. The device stats handling is left to the callers, as this function might be used in both the rx and tx path. Fixes: 55059f2 ("can: rx-offload: introduce can_rx_offload_get_echo_skb() and can_rx_offload_queue_sorted() functions") Cc: linux-stable <[email protected]> Cc: Martin Hundebøll <[email protected]> Reported-by: Martin Hundebøll <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 659680b commit ca913f1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/can/rx-offload.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ int can_rx_offload_queue_sorted(struct can_rx_offload *offload,
207207
unsigned long flags;
208208

209209
if (skb_queue_len(&offload->skb_queue) >
210-
offload->skb_queue_len_max)
211-
return -ENOMEM;
210+
offload->skb_queue_len_max) {
211+
kfree_skb(skb);
212+
return -ENOBUFS;
213+
}
212214

213215
cb = can_rx_offload_get_cb(skb);
214216
cb->timestamp = timestamp;

0 commit comments

Comments
 (0)