Skip to content

Commit

Permalink
net: selftests: initialize TCP header and skb payload with zero
Browse files Browse the repository at this point in the history
Zero-initialize TCP header via memset() to avoid garbage values that
may affect checksum or behavior during test transmission.

Also zero-fill allocated payload and padding regions using memset()
after skb_put(), ensuring deterministic content for all outgoing
test packets.

Fixes: 3e1e58d ("net: add generic selftest support")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: stable@vger.kernel.org
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250416160125.2914724-1-o.rempel@pengutronix.de
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Oleksij Rempel authored and Paolo Abeni committed Apr 22, 2025
1 parent 30a41ed commit 9e8d101
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions net/core/selftests.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ static struct sk_buff *net_test_get_skb(struct net_device *ndev,
ehdr->h_proto = htons(ETH_P_IP);

if (attr->tcp) {
memset(thdr, 0, sizeof(*thdr));
thdr->source = htons(attr->sport);
thdr->dest = htons(attr->dport);
thdr->doff = sizeof(struct tcphdr) / 4;
thdr->check = 0;
} else {
uhdr->source = htons(attr->sport);
uhdr->dest = htons(attr->dport);
Expand Down Expand Up @@ -144,10 +144,18 @@ static struct sk_buff *net_test_get_skb(struct net_device *ndev,
attr->id = net_test_next_id;
shdr->id = net_test_next_id++;

if (attr->size)
skb_put(skb, attr->size);
if (attr->max_size && attr->max_size > skb->len)
skb_put(skb, attr->max_size - skb->len);
if (attr->size) {
void *payload = skb_put(skb, attr->size);

memset(payload, 0, attr->size);
}

if (attr->max_size && attr->max_size > skb->len) {
size_t pad_len = attr->max_size - skb->len;
void *pad = skb_put(skb, pad_len);

memset(pad, 0, pad_len);
}

skb->csum = 0;
skb->ip_summed = CHECKSUM_PARTIAL;
Expand Down

0 comments on commit 9e8d101

Please sign in to comment.