Backport fix for CVE-2024-38538
Subsystems (4)
cover Backport fix for CVE-2024-38538
The 2nd patch fixes CVE-2024-38538, but it requires the helper function pskb_may_pull_reason which is defined in the 1st patch. Backport both together.
Eric Dumazet (1):
net: add pskb_may_pull_reason() helper
Nikolay Aleksandrov (1):
net: bridge: xmit: make sure we have at least eth header len bytes
include/linux/skbuff.h | 19 +++++++++++++++---- net/bridge/br_device.c | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-)
Signature · 1 line
2.46.0
PATCH 1/2 net: add pskb_may_pull_reason() helper
From: Eric Dumazet <[email protected]>
[ Upstream commit 1fb2d41501f38192d8a19da585cd441cf8845697 ]
pskb_may_pull() can fail for two different reasons.
Provide pskb_may_pull_reason() helper to distinguish between these reasons.
It returns:
SKB_NOT_DROPPED_YET : SuccessSKB_DROP_REASON_PKT_TOO_SMALL : packet too smallSKB_DROP_REASON_NOMEM : skb->head could not be resized
Stable-dep-of: 8bd67ebb50c0 ("net: bridge: xmit: make sure we have at least eth header len bytes")
[Sherry: bp to 5.15.y. Minor conflicts due to missing commit d427c8999b07 ("net-next: skbuff: refactor pskb_pull") which is not necessary in 5.15.y. Ignore context change.
--- include/linux/skbuff.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
include/linux/skbuff.h +15 -4
@@ -2465,13 +2465,24 @@ static inline void *pskb_pull(struct sk_buff *skb, unsigned int len)return unlikely (len > skb->len) ?NULL :__pskb_pull (skb, len); } -static inline bool pskb_may_pull (struct sk_buff *skb,unsigned int len) +static inline enum skb_drop_reason +pskb_may_pull_reason (struct sk_buff *skb,unsigned int len) {if (likely (len <=skb_headlen (skb))) -return true; +return SKB_NOT_DROPPED_YET ; +if (unlikely (len > skb->len)) -return false; -return __pskb_pull_tail (skb, len -skb_headlen (skb)) !=NULL ; +return SKB_DROP_REASON_PKT_TOO_SMALL ; + +if (unlikely (!__pskb_pull_tail (skb, len -skb_headlen (skb)))) +return SKB_DROP_REASON_NOMEM ; + +return SKB_NOT_DROPPED_YET ; +} + +static inline bool pskb_may_pull (struct sk_buff *skb,unsigned int len) +{ +return pskb_may_pull_reason (skb, len) ==SKB_NOT_DROPPED_YET ; }void skb_condense (struct sk_buff *skb);
Signature · 1 line
2.46.0
Greg KH
maintainerRe: [PATCH 5.15.y 1/2] net: add pskb_may_pull_reason() helper
Quoted 65 lines · Sherry Yang
From: Eric Dumazet <[email protected]>
[ Upstream commit
1fb2d41501f38192d8a19da585cd441cf8845697]
pskb_may_pull()can fail for two different reasons.Provide
pskb_may_pull_reason()helper to distinguish between these reasons.It returns:
SKB_NOT_DROPPED_YET: SuccessSKB_DROP_REASON_PKT_TOO_SMALL: packet too smallSKB_DROP_REASON_NOMEM:skb->headcould not be resizedSigned-off-by Eric Dumazet <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>Stable-dep-of:
8bd67ebb50c0("net: bridge: xmit: make sure we have at least eth header len bytes")Signed-off-by Sasha Levin <[email protected]>[Sherry: bp to 5.15.y. Minor conflicts due to missing commit
d427c8999b07("net-next: skbuff: refactorpskb_pull") which is not necessary in 5.15.y. Ignore context change.Signed-off-by Sherry Yang <[email protected]>--- include/linux/skbuff.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)include/linux/skbuff.h +15
-4@@ -2465,13 +2465,24 @@ static inline void *pskb_pull(struct sk_buff *skb, unsigned int len)return unlikely (len > skb->len) ?NULL :__pskb_pull (skb, len); } -static inline bool pskb_may_pull (struct sk_buff *skb,unsigned int len) +static inline enum skb_drop_reason +pskb_may_pull_reason (struct sk_buff *skb,unsigned int len) {if (likely (len <=skb_headlen (skb))) -return true; +return SKB_NOT_DROPPED_YET ; +if (unlikely (len > skb->len)) -return false; -return __pskb_pull_tail (skb, len -skb_headlen (skb)) !=NULL ; +return SKB_DROP_REASON_PKT_TOO_SMALL ; + +if (unlikely (!__pskb_pull_tail (skb, len -skb_headlen (skb)))) +return SKB_DROP_REASON_NOMEM ; + +return SKB_NOT_DROPPED_YET ; +} + +static inline bool pskb_may_pull (struct sk_buff *skb,unsigned int len) +{ +return pskb_may_pull_reason (skb, len) ==SKB_NOT_DROPPED_YET ; }void skb_condense (struct sk_buff *skb);Signature · 1 line
2.46.0
Any specific reason why you didn't test build this patch?
It breaks the build into thousands of tiny pieces.
greg k-h
Re: [PATCH 5.15.y 1/2] net: add pskb_may_pull_reason() helper
Hi Greg,
Quoted 71 lines · Greg KH
Quoted 65 lines · Sherry Yang
From: Eric Dumazet <[email protected]>
[ Upstream commit
1fb2d41501f38192d8a19da585cd441cf8845697]
pskb_may_pull()can fail for two different reasons.Provide
pskb_may_pull_reason()helper to distinguish between these reasons.It returns:
SKB_NOT_DROPPED_YET: SuccessSKB_DROP_REASON_PKT_TOO_SMALL: packet too smallSKB_DROP_REASON_NOMEM:skb->headcould not be resizedSigned-off-by Eric Dumazet <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>Stable-dep-of:
8bd67ebb50c0("net: bridge: xmit: make sure we have at least eth header len bytes")Signed-off-by Sasha Levin <[email protected]>[Sherry: bp to 5.15.y. Minor conflicts due to missing commit
d427c8999b07("net-next: skbuff: refactorpskb_pull") which is not necessary in 5.15.y. Ignore context change.Signed-off-by Sherry Yang <[email protected]>---
include/linux/skbuff.h| 19 +++++++++++++++----1 file changed, 15 insertions(+), 4 deletions(-)include/linux/skbuff.h +15
-4@@ -2465,13 +2465,24 @@ static inline void *pskb_pull(struct sk_buff *skb, unsigned int len)return unlikely (len > skb->len) ?NULL :__pskb_pull (skb, len); } -static inline bool pskb_may_pull (struct sk_buff *skb,unsigned int len) +static inline enum skb_drop_reason +pskb_may_pull_reason (struct sk_buff *skb,unsigned int len) {if (likely (len <=skb_headlen (skb))) -return true; +return SKB_NOT_DROPPED_YET ; +if (unlikely (len > skb->len)) -return false; -return __pskb_pull_tail (skb, len -skb_headlen (skb)) !=NULL ; +return SKB_DROP_REASON_PKT_TOO_SMALL ; + +if (unlikely (!__pskb_pull_tail (skb, len -skb_headlen (skb)))) +return SKB_DROP_REASON_NOMEM ; + +return SKB_NOT_DROPPED_YET ; +} + +static inline bool pskb_may_pull (struct sk_buff *skb,unsigned int len) +{ +return pskb_may_pull_reason (skb, len) ==SKB_NOT_DROPPED_YET ; }void skb_condense (struct sk_buff *skb);Signature · 1 line
2.46.0Any specific reason why you didn't test build this patch?
Quoted 1 line
It breaks the build into thousands of tiny pieces.
Sorry about the build failure. We have a branch which was forked from 5.15.y, and I did build and some smoke tests there. The build and smoke tests passed on our branch. However, I didn’t notice our branch backported prerequisite commits which made it diverge from linux-stable 5.15.y. I will apply the patch to upstream/linux-stable and build there before I send patch to upstream/linux-stable next time.
Sorry about the inconvenience.
Sherry
Quoted 2 lines
greg k-h
PATCH 2/2 net: bridge: xmit: make sure we have at least eth header len bytes
In reply to Sherry YangFrom: Nikolay Aleksandrov <[email protected]>
[ Upstream commit 8bd67ebb50c0145fd2ca8681ab65eb7e8cde1afc ]
syzbot triggered an uninit value[1] error in bridge device's xmit path by sending a short (less than ETH_HLEN bytes) skb. To fix it check if we can actually pull that amount instead of assuming.
Tested with dropwatch:
drop at: br_dev_xmit+0xb93/0x12d0 [bridge] (0xffffffffc06739b3)
origin: software
timestamp: Mon May 13 11:31:53 2024 778214037 nsec
protocol: 0x88a8
length: 2
original length: 2
drop reason: PKT_TOO_SMALL
[1]
BUG: KMSAN: uninit-value in br_dev_xmit+0x61d/0x1cb0 net/bridge/br_device.c:65 br_dev_xmit+0x61d/0x1cb0 net/bridge/br_device.c:65 __netdev_start_xmit include/linux/netdevice.h:4903 [inline] netdev_start_xmit include/linux/netdevice.h:4917 [inline] xmit_one net/core/dev.c:3531 [inline] dev_hard_start_xmit+0x247/0xa20 net/core/dev.c:3547 __dev_queue_xmit+0x34db/0x5350 net/core/dev.c:4341 dev_queue_xmit include/linux/netdevice.h:3091 [inline] __bpf_tx_skb net/core/filter.c:2136 [inline] __bpf_redirect_common net/core/filter.c:2180 [inline] __bpf_redirect+0x14a6/0x1620 net/core/filter.c:2187 ____bpf_clone_redirect net/core/filter.c:2460 [inline] bpf_clone_redirect+0x328/0x470 net/core/filter.c:2432 ___bpf_prog_run+0x13fe/0xe0f0 kernel/bpf/core.c:1997 __bpf_prog_run512+0xb5/0xe0 kernel/bpf/core.c:2238 bpf_dispatcher_nop_func include/linux/bpf.h:1234 [inline] __bpf_prog_run include/linux/filter.h:657 [inline] bpf_prog_run include/linux/filter.h:664 [inline] bpf_test_run+0x499/0xc30 net/bpf/test_run.c:425 bpf_prog_test_run_skb+0x14ea/0x1f20 net/bpf/test_run.c:1058 bpf_prog_test_run+0x6b7/0xad0 kernel/bpf/syscall.c:4269 __sys_bpf+0x6aa/0xd90 kernel/bpf/syscall.c:5678 __do_sys_bpf kernel/bpf/syscall.c:5767 [inline] __se_sys_bpf kernel/bpf/syscall.c:5765 [inline] __x64_sys_bpf+0xa0/0xe0 kernel/bpf/syscall.c:5765 x64_sys_call+0x96b/0x3b50 arch/x86/include/generated/asm/syscalls_64.h:322 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f
--- net/bridge/br_device.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bridge/br_device.c +6 -0
@@ -27,6 +27,7 @@ EXPORT_SYMBOL_GPL(nf_br_ops);/* net device transmit always called with BH disabled */ netdev_tx_t br_dev_xmit (struct sk_buff *skb,struct net_device *dev) { +enum skb_drop_reason reason =pskb_may_pull_reason (skb,ETH_HLEN );struct net_bridge_mcast_port *pmctx_null =NULL ;struct net_bridge *br =netdev_priv (dev);struct net_bridge_mcast *brmctx = &br->multicast_ctx;
@@ -38,6 +39,11 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)const unsigned char *dest;u16 vid =0 ; +if (unlikely (reason !=SKB_NOT_DROPPED_YET )) { +kfree_skb_reason (skb, reason); +return NETDEV_TX_OK ; + } +memset (skb->cb,0 ,sizeof (struct br_input_skb_cb ));rcu_read_lock ();
Signature · 1 line
2.46.0
PATCH 1/1 net: bridge: xmit: make sure we have at least eth header len bytes
From: Randy MacLeod <[email protected]>
[ Upstream commit 8bd67ebb50c0145fd2ca8681ab65eb7e8cde1afc ]
Based on above commit but simplified since pskb_may_pull_reason() does not exist until 6.1.
syzbot triggered an uninit value[1] error in bridge device's xmit path by sending a short (less than ETH_HLEN bytes) skb. To fix it check if we can actually pull that amount instead of assuming.
--- net/bridge/br_device.c | 5 +++++ 1 file changed, 5 insertions(+)
net/bridge/br_device.c +5 -0
@@ -38,6 +38,11 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)const unsigned char *dest;u16 vid =0 ; +if (unlikely (!pskb_may_pull (skb,ETH_HLEN ))) { +kfree_skb (skb); +return NETDEV_TX_OK ; + } +memset (skb->cb,0 ,sizeof (struct br_input_skb_cb ));rcu_read_lock ();
Signature · 1 line
2.34.1