Skip to contentSkip to conversation

Correct data pointer offset calculation

PATCH In review Dan Smith 2 participants 2 messages Nov 18, 2009 – Nov 25, 2009 1 message not in the archive Networking

lore
Share & tools
lore

Dan Smith

author
#0 lore raw

PATCH 1/1 Correct data pointer offset calculation

The current data pointer offset calculation is not correct in all cases. This patch records the offset and resets it on restore. With this patch, all of my test cases now pass and behave as they should.

---
 include/linux/checkpoint_hdr.h |    1 +
 net/checkpoint.c               |   11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
include/linux/checkpoint_hdr.h +1 -0
index 95ea3dd..4e57d37 100644
@@ -605,6 +605,7 @@ struct ckpt_hdr_socket_buffer {
 	__u32 skb_len; /* Length of skb (adjusted) */
 	__u32 hdr_len; /* Length of skipped header */
 	__u32 mac_len;
+	__u32 data_offset; /* Offset of data pointer from head */
 	__s32 sk_objref;
 	__s32 pr_objref;
 	__u16 protocol;
net/checkpoint.c +10 -1
index c9d5b1e..2ac6a42 100644
@@ -100,6 +100,8 @@ static void sock_record_header_info(struct sk_buff *skb,
 	h->lin_len = (skb->tail - skb->head);
 	h->frg_len = skb->data_len;
 
+	h->data_offset = (skb->data - skb->head);
+
 #ifdef NET_SKBUFF_DATA_USES_OFFSET
 	h->transport_header = skb->transport_hdr;
 	h->network_header = skb->network_header;
@@ -140,6 +142,13 @@ int sock_restore_header_info(struct ckpt_ctx *ctx,
 		return -EINVAL;
 	}
 
+	if (h->data_offset > h->lin_len) {
+		ckpt_err(ctx, -EINVAL,
+			 "skb data offset %u > linear length %u\n",
+			 h->data_offset, h->lin_len);
+		return -EINVAL;
+	}
+
 	if (h->skb_len > SKB_MAX_ALLOC) {
 		ckpt_err(ctx, -EINVAL,
 			 "skb total length %u larger than max of %lu\n",
@@ -161,7 +170,7 @@ int sock_restore_header_info(struct ckpt_ctx *ctx,
 	 */
 	memcpy(skb->cb, h->cb, sizeof(skb->cb));
 
-	skb->data = skb->head + skb->hdr_len;
+	skb->data = skb->head + h->data_offset;
 	skb->len = h->skb_len;
 
 	skb_shinfo(skb)->gso_type = sk->sk_gso_type;
Signature · 1 line
1.6.2.5
#2 lore raw
In reply to a message not in the archive

... for v19-rc2, too. Thanks.

Oren.

Quoted 58 lines · Dan Smith

The current data pointer offset calculation is not correct in all cases. This patch records the offset and resets it on restore. With this patch, all of my test cases now pass and behave as they should.

---
 include/linux/checkpoint_hdr.h |    1 +
 net/checkpoint.c               |   11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
include/linux/checkpoint_hdr.h +1 -0
index 95ea3dd..4e57d37 100644
@@ -605,6 +605,7 @@ struct ckpt_hdr_socket_buffer {
 	__u32 skb_len; /* Length of skb (adjusted) */
 	__u32 hdr_len; /* Length of skipped header */
 	__u32 mac_len;
+	__u32 data_offset; /* Offset of data pointer from head */
 	__s32 sk_objref;
 	__s32 pr_objref;
 	__u16 protocol;
net/checkpoint.c +10 -1
index c9d5b1e..2ac6a42 100644
@@ -100,6 +100,8 @@ static void sock_record_header_info(struct sk_buff *skb,
 	h->lin_len = (skb->tail - skb->head);
 	h->frg_len = skb->data_len;
 
+	h->data_offset = (skb->data - skb->head);
+
 #ifdef NET_SKBUFF_DATA_USES_OFFSET
 	h->transport_header = skb->transport_hdr;
 	h->network_header = skb->network_header;
@@ -140,6 +142,13 @@ int sock_restore_header_info(struct ckpt_ctx *ctx,
 		return -EINVAL;
 	}
 
+	if (h->data_offset > h->lin_len) {
+		ckpt_err(ctx, -EINVAL,
+			 "skb data offset %u > linear length %u\n",
+			 h->data_offset, h->lin_len);
+		return -EINVAL;
+	}
+
 	if (h->skb_len > SKB_MAX_ALLOC) {
 		ckpt_err(ctx, -EINVAL,
 			 "skb total length %u larger than max of %lu\n",
@@ -161,7 +170,7 @@ int sock_restore_header_info(struct ckpt_ctx *ctx,
 	 */
 	memcpy(skb->cb, h->cb, sizeof(skb->cb));
 
-	skb->data = skb->head + skb->hdr_len;
+	skb->data = skb->head + h->data_offset;
 	skb->len = h->skb_len;
 
 	skb_shinfo(skb)->gso_type = sk->sk_gso_type;