Skip to content

Commit d293ca7

Browse files
lag-linarokuba-moo
authored andcommitted
tipc: fix double-free in tipc_buf_append()
tipc_msg_validate() can potentially reallocate the skb it is validating, freeing the old one. In tipc_buf_append(), it was being called with a pointer to a local variable which was a copy of the caller's skb pointer. If the skb was reallocated and validation subsequently failed, the error handling path would free the original skb pointer, which had already been freed, leading to double-free. Fix this by checking if head now points to a newly allocated reassembled skb. If it does, reassign *headbuf for later freeing operations. Fixes: d618d09 ("tipc: enforce valid ratio between skb truesize and contents") Suggested-by: Tung Nguyen <[email protected]> Signed-off-by: Lee Jones <[email protected]> Reviewed-by: Tung Nguyen <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 864ba40 commit d293ca7

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

net/tipc/msg.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,20 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
177177

178178
if (fragid == LAST_FRAGMENT) {
179179
TIPC_SKB_CB(head)->validated = 0;
180-
if (unlikely(!tipc_msg_validate(&head)))
180+
181+
/* If the reassembled skb has been freed in
182+
* tipc_msg_validate() because of an invalid truesize,
183+
* then head will point to a newly allocated reassembled
184+
* skb, while *headbuf points to freed reassembled skb.
185+
* In such cases, correct *headbuf for freeing the newly
186+
* allocated reassembled skb later.
187+
*/
188+
if (unlikely(!tipc_msg_validate(&head))) {
189+
if (head != *headbuf)
190+
*headbuf = head;
181191
goto err;
192+
}
193+
182194
*buf = head;
183195
TIPC_SKB_CB(head)->tail = NULL;
184196
*headbuf = NULL;

0 commit comments

Comments
 (0)