diff mbox series

[net-next] net: ipv4, ipv6: Fix incorrect skb->data_len caused by __ip_append_data

Message ID AM6PR03MB5848A1EE8F0EBA45D440F8EA99222@AM6PR03MB5848.eurprd03.prod.outlook.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: ipv4, ipv6: Fix incorrect skb->data_len caused by __ip_append_data | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 942 this patch: 942
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 958 this patch: 958
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-03-06--00-00 (tests: 874)

Commit Message

Juntong Deng March 5, 2024, 10:42 p.m. UTC
When __ip_append_data allocate the first skb in the queue, or when the
size of the data in the skb exceed the MTU and require a new fragment
and allocate a new skb, both cause the size of the data increased by
this __ip_append_data to not be added to skb->data_len.

This is because in the current __ip_append_data, skb_put is used when
putting in the data for the new skb, but skb_put only increase skb->len,
but not skb->data_len, resulting in skb->data_len missing this part of
the data size.

All skb processed by __ip_append_data are unable to obtain the accurate
data size based on skb->data_len for the above reason.

Also __ip6_append_data has the same problem.

This patch fixes the bug.

Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
---
 net/ipv4/ip_output.c  | 3 +++
 net/ipv6/ip6_output.c | 3 +++
 2 files changed, 6 insertions(+)

Comments

Jakub Kicinski March 6, 2024, 3:18 a.m. UTC | #1
On Tue,  5 Mar 2024 22:42:05 +0000 Juntong Deng wrote:
> When __ip_append_data allocate the first skb in the queue, or when the
> size of the data in the skb exceed the MTU and require a new fragment
> and allocate a new skb, both cause the size of the data increased by
> this __ip_append_data to not be added to skb->data_len.
> 
> This is because in the current __ip_append_data, skb_put is used when
> putting in the data for the new skb, but skb_put only increase skb->len,
> but not skb->data_len, resulting in skb->data_len missing this part of
> the data size.
> 
> All skb processed by __ip_append_data are unable to obtain the accurate
> data size based on skb->data_len for the above reason.
> 
> Also __ip6_append_data has the same problem.
> 
> This patch fixes the bug.

data_len is the amount of data in the non-linear parts of the skb.
Please run some tests before submitting patches.
diff mbox series

Patch

diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 1fe794967211..42686be0a843 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1171,6 +1171,9 @@  static int __ip_append_data(struct sock *sk,
 				copy = 0;
 			}
 
+			if (copy >= 0)
+				skb->data_len += copy;
+
 			offset += copy;
 			length -= copy + transhdrlen;
 			transhdrlen = 0;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 31b86fe661aa..2091b91513f0 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1689,6 +1689,9 @@  static int __ip6_append_data(struct sock *sk,
 				copy = 0;
 			}
 
+			if (copy >= 0)
+				skb->data_len += copy;
+
 			offset += copy;
 			length -= copy + transhdrlen;
 			transhdrlen = 0;