mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-05 19:31:57 -04:00
tipc: fix double-free in tipc_buf_append()
[ Upstream commit d293ca716e7d5dffdaecaf6b9b2f857a33dc3d3a ]
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.
Bug: 500022799
Fixes: d618d09a68 ("tipc: enforce valid ratio between skb truesize and contents")
Suggested-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[uli: backport to 4.19]
Signed-off-by: Ulrich Hecht <uli@kernel.org>
Reviewed-by: Pavel Machek <pavel@nabladev.com>
Reviewed-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>
Change-Id: I76d957597768652e2f05be3470bf960f6ff29085
This commit is contained in:
parent
1f9e522f94
commit
db44a74f9f
1 changed files with 13 additions and 1 deletions
|
|
@ -175,8 +175,20 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
|
|||
|
||||
if (fragid == LAST_FRAGMENT) {
|
||||
TIPC_SKB_CB(head)->validated = false;
|
||||
if (unlikely(!tipc_msg_validate(&head)))
|
||||
|
||||
/* If the reassembled skb has been freed in
|
||||
* tipc_msg_validate() because of an invalid truesize,
|
||||
* then head will point to a newly allocated reassembled
|
||||
* skb, while *headbuf points to freed reassembled skb.
|
||||
* In such cases, correct *headbuf for freeing the newly
|
||||
* allocated reassembled skb later.
|
||||
*/
|
||||
if (unlikely(!tipc_msg_validate(&head))) {
|
||||
if (head != *headbuf)
|
||||
*headbuf = head;
|
||||
goto err;
|
||||
}
|
||||
|
||||
*buf = head;
|
||||
TIPC_SKB_CB(head)->tail = NULL;
|
||||
*headbuf = NULL;
|
||||
|
|
|
|||
Loading…
Reference in a new issue