tipc: fix double-free in tipc_buf_append()
Subsystems (3)
PATCH 1/1 tipc: fix double-free in tipc_buf_append()
The tipc_msg_validate() function 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 passing the caller's skb pointer-pointer directly to tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.
--- net/tipc/msg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/tipc/msg.c +2 -1
@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf; *buf = head;TIPC_SKB_CB (head)->tail =NULL ; *headbuf =NULL ;
Signature · 1 line
2.54.0.rc1.513.gad8abe7a5a-goog
Tung Quang Nguyen
maintainerSubject: [PATCH 1/1] tipc: fix double-free in tipc_buf_append()
Quoted 27 lines
The
tipc_msg_validate()function can potentially reallocate the skb it is validating, freeing the old one. Intipc_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 passing the caller's skb pointer-pointer directly to
tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.Fixes d618d09a68e4 ("tipc: enforce valid ratio between skb truesize andcontents")
Assisted-by Gemini:gemini-3.1-pro-previewSigned-off-by Lee Jones <[email protected]>---
net/tipc/msg.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/msg.c index 76284fc538eb..9f4f612ee027 renamed from net/tipc/msg.c +0
-0100644
net/tipc/msg.c int tipc_buf_append(struct sk_buff **headbuf, struct · line 183
Quoted 8 lines
net/tipc/msg.c +2
-1@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf;
This is a known issue and was reported via https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
The author did not respond to my comment.
Can you improve the fix by applying my patch?
net/tipc/msg.c +12 -1
@@ -177,8 +177,19 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (&head))) { +/* reassembled skb has been freed in +* tipc_msg_validate() because of invalid truesize. +* head now points to newly-allocated reassembled skb +* while *headbuf points to freed reassembled skb. +* So, correct *headbuf for freeing newly-allocated +* reassembled skb later. +*/ +if (head != *headbuf) + *headbuf = head; + goto err; + } *buf = head;TIPC_SKB_CB (head)->tail =NULL ; *headbuf =NULL ;
Quoted 6 lines
net/tipc/msg.c +0
-0*buf = head;TIPC_SKB_CB (head)->tail =NULL ;*headbuf = NULL;--
2.54.0.rc1.513.gad8abe7a5a-goog
Quoted 30 lines · Tung Quang Nguyen
Subject: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 29 lines
The
tipc_msg_validate()function can potentially reallocate the skb it is validating, freeing the old one. Intipc_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 passing the caller's skb pointer-pointer directly to
tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.Fixes d618d09a68e4 ("tipc: enforce valid ratio between skb truesize andcontents")
Assisted-by Gemini:gemini-3.1-pro-previewSigned-off-by Lee Jones <[email protected]>---
net/tipc/msg.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/msg.c index 76284fc538eb..9f4f612ee027 renamed from net/tipc/msg.c +0
-0100644
net/tipc/msg.c +0
-0@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
Quoted 9 lines
net/tipc/msg.c int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
Quoted 6 lines
net/tipc/msg.c +2
-1if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf;This is a known issue and was reported via https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
The author did not respond to my comment.
Can you improve the fix by applying my patch?
I'd be happy to make any required changes.
However, is this approach superior to simply passing a reference?
v1 appears to be simpler, easier to read and avoids the explanation.
Quoted 32 lines
net/tipc/msg.c +12
-1@@ -177,8 +177,19 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (&head))) { +/* reassembled skb has been freed in +* tipc_msg_validate() because of invalid truesize. +* head now points to newly-allocated reassembled skb +* while *headbuf points to freed reassembled skb. +* So, correct *headbuf for freeing newly-allocated +* reassembled skb later. +*/ +if (head != *headbuf) + *headbuf = head; + goto err; + } *buf = head;TIPC_SKB_CB (head)->tail =NULL ; *headbuf =NULL ;Quoted 6 lines
net/tipc/msg.c +0
-0*buf = head;TIPC_SKB_CB (head)->tail =NULL ;*headbuf = NULL;--
2.54.0.rc1.513.gad8abe7a5a-goog
Signature · 1 line
Lee Jones [李琼斯]
Tung Quang Nguyen
maintainerQuoted 45 lines
Quoted 5 lines
Subject: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 4 lines
The
tipc_msg_validate()function can potentially reallocate the skb it is validating, freeing the old one. Intipc_buf_append(), it was being called with a pointer to a local variable which was a copy of thecaller's skb pointer.
Quoted 27 lines
Quoted 27 lines
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 passing the caller's skb pointer-pointer directly to
tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.Fixes d618d09a68e4 ("tipc: enforce valid ratio between skb truesizeand
contents")Assisted-by Gemini:gemini-3.1-pro-previewSigned-off-by Lee Jones <[email protected]>---
net/tipc/msg.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/msg.c index renamed from net/tipc/msg.c +0
-0
76284fc538eb..9f4f612ee027
100644net/tipc/msg.c +0
-0@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)Quoted 11 lines
net/tipc/msg.c int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
Quoted 6 lines
net/tipc/msg.c +2
-1if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf;This is a known issue and was reported via
https://patchwork.kernel.org/project/netdevbpf/patch/20260330205313.24
[email protected]/ The author did not respond to my comment.
Can you improve the fix by applying my patch?
Quoted 6 lines
I'd be happy to make any required changes.
However, is this approach superior to simply passing a reference?
v1 appears to be simpler, easier to read and avoids the explanation.
As I explained, your fix adds extra overhead to normal path while the error path is corner case and it rarely happens. Whatever approach is applied, we need to add explanation to understand more easily the logic and hidden trick in tipc_msg_validate().
Quoted 36 lines
Quoted 25 lines
net/tipc/msg.c index renamed from net/tipc/msg.c +0
-0
76284fc538eb..01a693559589100644net/tipc/msg.c +12
-1@@ -177,8 +177,19 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (&head))) { +/* reassembled skb has been freed in +* tipc_msg_validate() because of invalid truesize. +* head now points to newly-allocated reassembled skb +* while *headbuf points to freed reassembled skb. +* So, correct *headbuf for freeing newly-allocated +* reassembled skb later. +*/ +if (head != *headbuf) + *headbuf = head; + goto err; + } *buf = head;TIPC_SKB_CB (head)->tail =NULL ;Quoted 8 lines
*headbuf = NULL;Quoted 6 lines
net/tipc/msg.c +0
-0*buf = head;TIPC_SKB_CB (head)->tail =NULL ;*headbuf = NULL;--
2.54.0.rc1.513.gad8abe7a5a-goog--
Lee Jones [李琼斯]
Quoted 45 lines · Tung Quang Nguyen
Quoted 45 lines
Quoted 5 lines
Subject: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 4 lines
The
tipc_msg_validate()function can potentially reallocate the skb it is validating, freeing the old one. Intipc_buf_append(), it was being called with a pointer to a local variable which was a copy of thecaller's skb pointer.
Quoted 38 lines
Quoted 25 lines
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 passing the caller's skb pointer-pointer directly to
tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.Fixes d618d09a68e4 ("tipc: enforce valid ratio between skb truesizeand
contents")Assisted-by Gemini:gemini-3.1-pro-previewSigned-off-by Lee Jones <[email protected]>---
net/tipc/msg.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/msg.c index renamed from net/tipc/msg.c +0
-0
76284fc538eb..9f4f612ee027
100644net/tipc/msg.c int tipc_buf_append(struct sk_buff **headbuf, · line 183
Quoted 8 lines
net/tipc/msg.c +2
-1@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf;This is a known issue and was reported via
https://patchwork.kernel.org/project/netdevbpf/patch/20260330205313.24
[email protected]/ The author did not respond to my comment.
Can you improve the fix by applying my patch?
Quoted 8 lines
Quoted 6 lines
I'd be happy to make any required changes.
However, is this approach superior to simply passing a reference?
v1 appears to be simpler, easier to read and avoids the explanation.
As I explained, your fix adds extra overhead to normal path while the error path is corner case and it rarely happens. Whatever approach is applied, we need to add explanation to understand more easily the logic and hidden trick in
tipc_msg_validate().
Very well. I have made the recommended changes.
The patch is currently in my build-test environment.
I will post v2, when everything has been satisfied.
Signature · 1 line
Lee Jones [李琼斯]
Quoted 53 lines · Lee Jones
Quoted 51 lines · Tung Quang Nguyen
Quoted 51 lines
Quoted 5 lines
Subject: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 4 lines
The
tipc_msg_validate()function can potentially reallocate the skb it is validating, freeing the old one. Intipc_buf_append(), it was being called with a pointer to a local variable which was a copy of thecaller's skb pointer.
Quoted 27 lines
Quoted 27 lines
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 passing the caller's skb pointer-pointer directly to
tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.Fixes d618d09a68e4 ("tipc: enforce valid ratio between skb truesizeand
contents")Assisted-by Gemini:gemini-3.1-pro-previewSigned-off-by Lee Jones <[email protected]>---
net/tipc/msg.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/msg.c index renamed from net/tipc/msg.c +0
-0
76284fc538eb..9f4f612ee027
100644net/tipc/msg.c +0
-0@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)Quoted 11 lines
net/tipc/msg.c int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
Quoted 6 lines
net/tipc/msg.c +2
-1if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf;This is a known issue and was reported via
https://patchwork.kernel.org/project/netdevbpf/patch/20260330205313.24
[email protected]/ The author did not respond to my comment.
Can you improve the fix by applying my patch?I'd be happy to make any required changes.
However, is this approach superior to simply passing a reference?
v1 appears to be simpler, easier to read and avoids the explanation.
Quoted 8 lines
Quoted 2 lines
As I explained, your fix adds extra overhead to normal path while the error path is corner case and it rarely happens. Whatever approach is applied, we need to add explanation to understand more easily the logic and hidden trick in
tipc_msg_validate().Very well. I have made the recommended changes.
The patch is currently in my build-test environment.
I will post v2, when everything has been satisfied.
Okay, I genuinely tried to apply your patch. It builds just fine, but Gemini (the AI I use to pre-review patches before submission) has some doubts that this is the correct approach:
Quoted 13 lines
(quoted diff) +8
-1@@ -177,8 +177,20 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf) if (fragid == LAST_FRAGMENT) { TIPC_SKB_CB(head)->validated = 0; - 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. + *
Review int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
Quoted 10 lines
(quoted diff) +9
-0+ * Note: It's done this way instead of passing &head // I added this part to give + * to avoid slowing down the happy path since this failure // the reviewer some additoinal + * is a rare event. // context + */ + if (unlikely(!tipc_msg_validate(headbuf))) { + if (head != *headbuf) + *headbuf = head; goto err; + } +
"It looks like this logic might re-introduce the double-free bug.
The call to tipc_msg_validate(headbuf) is correct, as it passes the pointer-to-pointer and allows the callee to update *headbuf if the skb is reallocated.
However, the subsequent check seems to undo this. If a reallocation happens, head will hold the pointer to the old, freed skb, while *headbuf will hold the new one. The condition head != *headbuf will be true, and the assignment *headbuf = head will restore the stale pointer, leading to a double-free on the err path.
The preceding comment also appears to have the pointer roles reversed.
Would it be simpler and more correct to remove the if (head != *headbuf) check and the large comment block? The change from &head to headbuf in the function call seems to be the only change required to fix the bug. Also, please update the commit message to reflect the corrected logic."
I suggest that we go with the original patch. Although I find it admirable that you are thinking about and attempting to protect the more common happy-path, I think the resultant single additional variable assignment is negligible and that the simplicity of the previous fix has greater benefits in terms of code readability and maintainability.
If you like, I can add a small comment, but I doubt even that is necessary.
Signature · 1 line
Lee Jones [李琼斯]
Tung Quang Nguyen
maintainerQuoted 89 lines
Subject: Re: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 48 lines · Lee Jones
Quoted 46 lines · Tung Quang Nguyen
Quoted 46 lines
Quoted 6 lines
Subject: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 5 lines
The
tipc_msg_validate()function can potentially reallocate the skb it is validating, freeing the old one. Intipc_buf_append(), it was being called with a pointer to a local variable which was a copy of thecaller's skb pointer.
Quoted 38 lines
Quoted 25 lines
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 passing the caller's skb pointer-pointer directly to
tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.Fixes d618d09a68e4 ("tipc: enforce valid ratio between skbtruesize and
contents")Assisted-by Gemini:gemini-3.1-pro-previewSigned-off-by Lee Jones <[email protected]>---
net/tipc/msg.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/msg.c index renamed from net/tipc/msg.c +0
-0
76284fc538eb..9f4f612ee027
100644net/tipc/msg.c int tipc_buf_append(struct sk_buff · line 183
Quoted 8 lines
net/tipc/msg.c +2
-1@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf;This is a known issue and was reported via
https://patchwork.kernel.org/project/netdevbpf/patch/202603302053
13.24 [email protected]/ The author did not respond to my comment.
Can you improve the fix by applying my patch?Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
I'd be happy to make any required changes.
However, is this approach superior to simply passing a reference?
v1 appears to be simpler, easier to read and avoids the explanation.
As I explained, your fix adds extra overhead to normal path while the error
path is corner case and it rarely happens.
Quoted 1 line
Quoted 1 line
Whatever approach is applied, we need to add explanation to understand
more easily the logic and hidden trick in
tipc_msg_validate().Quoted 6 lines
Very well. I have made the recommended changes.
The patch is currently in my build-test environment.
I will post v2, when everything has been satisfied.
Okay, I genuinely tried to apply your patch. It builds just fine, but Gemini (the AI I use to pre-review patches before submission) has some doubts that this is the correct approach:
Quoted 5 lines
(quoted diff) +0
-0@@ -177,8 +177,20 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf) if (fragid == LAST_FRAGMENT) { TIPC_SKB_CB(head)->validated = 0;Review int tipc_buf_append(struct sk_buff **headbuf, · line 189
Quoted 10 lines
(quoted diff) +9
-1- 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. + * + * Note: It's done this way instead of passing &head // I addedthis part to give
Quoted 5 lines
Review int tipc_buf_append(struct sk_buff **headbuf, · line 190
Quoted 1 line
(quoted diff) +1
-0+ * to avoid slowing down the happy path since this failure // thereviewer some additoinal
Quoted 3 lines
(quoted diff) +3
-0+ * is a rare event. // context + */ + if (unlikely(!tipc_msg_validate(headbuf))) {
You did NOT apply my patch correctly. I did not suggest passing headbuf to tipc_msg_validate(). My patch is very simple:
+ if (unlikely(!tipc_msg_validate(&head))) {
+ /* reassembled skb has been freed in
+ * tipc_msg_validate() because of invalid truesize.
+ * head now points to newly-allocated reassembled skb
+ * while *headbuf points to freed reassembled skb.
+ * So, correct *headbuf for freeing newly-allocated
+ * reassembled skb later.
+ */
+ if (head != *headbuf)
+ *headbuf = head;
+
goto err;+ }
Quoted 34 lines
net/tipc/msg.c int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
Quoted 5 lines
net/tipc/msg.c +4
-0+if (head != *headbuf) + *headbuf = head; goto err; + } +"It looks like this logic might re-introduce the double-free bug.
The call totipc_msg_validate(headbuf)is correct, as it passes the pointer-to-pointer and allows the callee to update*headbufif the skb is reallocated.However, the subsequent check seems to undo this. If a reallocation happens,
headwill hold the pointer to the old, freed skb, while*headbufwill hold the new one. The conditionhead != *headbufwill be true, and the assignment*headbuf = headwill restore the stale pointer, leading to a double-free on theerrpath.The preceding comment also appears to have the pointer roles reversed.
Would it be simpler and more correct to remove the
if (head != *headbuf)check and the large comment block? The change from&headtoheadbufin the function call seems to be the only change required to fix the bug. Also, please update the commit message to reflect the corrected logic."I suggest that we go with the original patch. Although I find it admirable that you are thinking about and attempting to protect the more common happy- path, I think the resultant single additional variable assignment is negligible and that the simplicity of the previous fix has greater benefits in terms of code readability and maintainability.
If you like, I can add a small comment, but I doubt even that is necessary.
--
Lee Jones [李琼斯]
Quoted 89 lines · Tung Quang Nguyen
Quoted 89 lines
Subject: Re: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 48 lines · Lee Jones
Quoted 46 lines · Tung Quang Nguyen
Quoted 46 lines
Quoted 6 lines
Subject: [PATCH 1/1] tipc: fix double-free in
tipc_buf_append()Quoted 5 lines
The
tipc_msg_validate()function can potentially reallocate the skb it is validating, freeing the old one. Intipc_buf_append(), it was being called with a pointer to a local variable which was a copy of thecaller's skb pointer.
Quoted 38 lines
Quoted 25 lines
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 passing the caller's skb pointer-pointer directly to
tipc_msg_validate(), ensuring any modification is reflected correctly. The local skb pointer is then updated from the (possibly modified) caller's pointer.Fixes d618d09a68e4 ("tipc: enforce valid ratio between skbtruesize and
contents")Assisted-by Gemini:gemini-3.1-pro-previewSigned-off-by Lee Jones <[email protected]>---
net/tipc/msg.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/msg.c index renamed from net/tipc/msg.c +0
-0
76284fc538eb..9f4f612ee027
100644net/tipc/msg.c int tipc_buf_append(struct sk_buff · line 183
Quoted 8 lines
net/tipc/msg.c +2
-1@@ -177,8 +177,9 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) +if (unlikely (!tipc_msg_validate (headbuf))) goto err; + head = *headbuf;This is a known issue and was reported via
https://patchwork.kernel.org/project/netdevbpf/patch/202603302053
13.24 [email protected]/ The author did not respond to my comment.
Can you improve the fix by applying my patch?Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
I'd be happy to make any required changes.
However, is this approach superior to simply passing a reference?
v1 appears to be simpler, easier to read and avoids the explanation.
As I explained, your fix adds extra overhead to normal path while the error
path is corner case and it rarely happens.
Quoted 1 line
Quoted 1 line
Whatever approach is applied, we need to add explanation to understand
more easily the logic and hidden trick in
tipc_msg_validate().Quoted 6 lines
Very well. I have made the recommended changes.
The patch is currently in my build-test environment.
I will post v2, when everything has been satisfied.
Okay, I genuinely tried to apply your patch. It builds just fine, but Gemini (the AI I use to pre-review patches before submission) has some doubts that this is the correct approach:
Quoted 5 lines
(quoted diff) +0
-0@@ -177,8 +177,20 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf) if (fragid == LAST_FRAGMENT) { TIPC_SKB_CB(head)->validated = 0;Review int tipc_buf_append(struct sk_buff **headbuf, · line 189
Quoted 10 lines
(quoted diff) +9
-1- 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. + * + * Note: It's done this way instead of passing &head // I addedthis part to give
Quoted 6 lines
Quoted 5 lines
Review int tipc_buf_append(struct sk_buff **headbuf, · line 190
Quoted 1 line
(quoted diff) +1
-0+ * to avoid slowing down the happy path since this failure // thereviewer some additoinal
Quoted 3 lines
(quoted diff) +3
-0+ * is a rare event. // context + */ + if (unlikely(!tipc_msg_validate(headbuf))) {You did NOT apply my patch correctly. I did not suggest passing headbuf to
tipc_msg_validate().
Ah, you're right. I missed that line change.
Let me revisit. Bear with.
Quoted 14 lines
My patch is very simple:
net/tipc/msg.c +12
-0+if (unlikely (!tipc_msg_validate (&head))) { +/* reassembled skb has been freed in +* tipc_msg_validate() because of invalid truesize. +* head now points to newly-allocated reassembled skb +* while *headbuf points to freed reassembled skb. +* So, correct *headbuf for freeing newly-allocated +* reassembled skb later. +*/ +if (head != *headbuf) + *headbuf = head; + goto err; + }
Signature · 1 line
Lee Jones [李琼斯]