mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
Merge branch 'net-psp-add-more-validation'
Jakub Kicinski says: ==================== net: psp: add more validation Address some AI code-scan issues with the PSP code. I don't think any of these are real bugs, but they may become bugs in the future. The two real bugs discovered were posted separately for net. AI reports 3 more which seem plain wrong (rx SPI "leak" on error etc.). ==================== Link: https://patch.msgid.link/20260428205352.1247325-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
776059b702
|
|
@ -90,6 +90,10 @@ psp_dev_create(struct net_device *netdev,
|
|||
mutex_lock(&psd->lock);
|
||||
mutex_unlock(&psp_devs_lock);
|
||||
|
||||
/* notify before netdev assignment
|
||||
* There's no strong reason for it, but thinking is to avoid creating
|
||||
* implicit expectations about the PSP dev <> netdev relationship.
|
||||
*/
|
||||
psp_nl_notify_dev(psd, PSP_CMD_DEV_ADD_NTF);
|
||||
|
||||
rcu_assign_pointer(netdev->psp_dev, psd);
|
||||
|
|
@ -228,6 +232,10 @@ bool psp_dev_encapsulate(struct net *net, struct sk_buff *skb, __be32 spi,
|
|||
u32 ethr_len = skb_mac_header_len(skb);
|
||||
u32 bufflen = ethr_len + network_len;
|
||||
|
||||
if (skb->protocol != htons(ETH_P_IP) &&
|
||||
skb->protocol != htons(ETH_P_IPV6))
|
||||
return false;
|
||||
|
||||
if (skb_cow_head(skb, PSP_ENCAP_HLEN))
|
||||
return false;
|
||||
|
||||
|
|
@ -243,11 +251,9 @@ bool psp_dev_encapsulate(struct net *net, struct sk_buff *skb, __be32 spi,
|
|||
ip_hdr(skb)->check = 0;
|
||||
ip_hdr(skb)->check =
|
||||
ip_fast_csum((u8 *)ip_hdr(skb), ip_hdr(skb)->ihl);
|
||||
} else if (skb->protocol == htons(ETH_P_IPV6)) {
|
||||
} else {
|
||||
ipv6_hdr(skb)->nexthdr = IPPROTO_UDP;
|
||||
be16_add_cpu(&ipv6_hdr(skb)->payload_len, PSP_ENCAP_HLEN);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
skb_set_inner_ipproto(skb, IPPROTO_TCP);
|
||||
|
|
@ -294,6 +300,9 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv)
|
|||
if (proto == htons(ETH_P_IP)) {
|
||||
struct iphdr *iph = (struct iphdr *)(skb->data + l2_hlen);
|
||||
|
||||
if (unlikely(iph->ihl < 5))
|
||||
return -EINVAL;
|
||||
|
||||
is_udp = iph->protocol == IPPROTO_UDP;
|
||||
l3_hlen = iph->ihl * 4;
|
||||
if (l3_hlen != sizeof(struct iphdr) &&
|
||||
|
|
@ -329,6 +338,9 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv)
|
|||
if (proto == htons(ETH_P_IP)) {
|
||||
struct iphdr *iph = (struct iphdr *)(skb->data + l2_hlen);
|
||||
|
||||
if (unlikely(ntohs(iph->tot_len) < l3_hlen + encap))
|
||||
return -EINVAL;
|
||||
|
||||
iph->protocol = psph->nexthdr;
|
||||
iph->tot_len = htons(ntohs(iph->tot_len) - encap);
|
||||
iph->check = 0;
|
||||
|
|
@ -336,6 +348,9 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv)
|
|||
} else {
|
||||
struct ipv6hdr *ipv6h = (struct ipv6hdr *)(skb->data + l2_hlen);
|
||||
|
||||
if (unlikely(ntohs(ipv6h->payload_len) < encap))
|
||||
return -EINVAL;
|
||||
|
||||
ipv6h->nexthdr = psph->nexthdr;
|
||||
ipv6h->payload_len = htons(ntohs(ipv6h->payload_len) - encap);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user