FAILED: patch "[PATCH] net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()" failed to apply to 5.15-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 56453199d28f0072a8196fba14b2d702632e2219
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 56453199d28f0072a8196fba14b2d702632e2219 Mon Sep 17 00:00:00 2001
From: Josef Bacik <[email protected]>
Date: Wed, 7 Oct 2026 17:36:04 +0000
Subject: [PATCH] net: skbuff: don't BUG() on a bad csum_start in
skb_copy_and_csum_dev()
skb_copy_and_csum_dev() copies everything up to the checksum start out of the linear area, and BUG()s if the checksum start is past the end of the linear area. It misses the other direction: a CHECKSUM_PARTIAL skb that has been pulled past its csum_start gives a negative offset, which gets past the check and becomes a ~4GB copy. It also trusts csum_offset when it stores the folded checksum. So far skb_copy_and_csum_bits() BUG()ing on a short skb has covered for that, but once it returns instead, a bad csum_offset would write past the end of the caller's buffer.
The function returns void and its callers are drivers copying a frame into a bounce buffer just before handing it to the hardware. There's nothing for them to back out of, so check both ends of csum_start and that the checksum field fits in the frame, and if not, copy the whole frame with skb_copy_bits() without filling in the checksum, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The frame
goes out with a bad checksum and is dropped by the receiver. If even that copy fails, zero the buffer so the driver doesn't send stale bytes.
--- net/core/skbuff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/core/skbuff.c +12 -1
@@ -3981,7 +3981,18 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else csstart =skb_headlen (skb); -BUG_ON (csstart >skb_headlen (skb)); +if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + (skb->ip_summed ==CHECKSUM_PARTIAL && + csstart + skb->csum_offset +sizeof (__sum16) > + skb->len))) { +DEBUG_NET_WARN_ON_ONCE (1 ); +/* Send the frame without the checksum filled in, or send +* zeroes if we can't even copy it. +*/ +if (skb_copy_bits (skb,0 , to, skb->len)) +memset (to,0 , skb->len); +return ; + }skb_copy_from_linear_data (skb, to, csstart);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/4 lib, stackdepot: add helper to print stack entries
From: Imran Khan <[email protected]>
[ Upstream commit 505be48165fa2f2cb795659b4fc61f35563d105e ]
To print a stack entries, users of stackdepot, first use stack_depot_fetch to get a list of stack entries and then use stack_trace_print to print this list. Provide a helper in stackdepot to print stack entries based on stackdepot handle. Also change above mentioned users to use this helper.
Stable-dep-of: 56453199d28f ("net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()")
--- include/linux/stackdepot.h | 2 ++ lib/stackdepot.c | 18 ++++++++++++++++++ mm/kasan/report.c | 15 +++------------ mm/page_owner.c | 13 ++++--------- 4 files changed, 27 insertions(+), 21 deletions(-)
include/linux/stackdepot.h +2 -0
@@ -19,6 +19,8 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,unsigned int stack_depot_fetch (depot_stack_handle_t handle,unsigned long **entries); +void stack_depot_print (depot_stack_handle_t stack); +#ifdef CONFIG_STACKDEPOT int stack_depot_init (void );#else
lib/stackdepot.c +18 -0
@@ -213,6 +213,24 @@ static inline struct stack_record *find_stack(struct stack_record *bucket,return NULL ; } +/** +* stack_depot_print - print stack entries from a depot +* +* @stack: Stack depot handle which was returned from +* stack_depot_save(). +* +*/ +void stack_depot_print (depot_stack_handle_t stack) +{ +unsigned long *entries; +unsigned int nr_entries; + + nr_entries =stack_depot_fetch (stack, &entries); +if (nr_entries >0 ) +stack_trace_print (entries, nr_entries,0 ); +} +EXPORT_SYMBOL_GPL (stack_depot_print); +/** * stack_depot_fetch - Fetch stack entries from a depot *
mm/kasan/report.c +3 -12
@@ -124,20 +124,11 @@ static void end_report(unsigned long *flags, unsigned long addr)kasan_enable_current (); } -static void print_stack (depot_stack_handle_t stack) -{ -unsigned long *entries; -unsigned int nr_entries; - - nr_entries =stack_depot_fetch (stack, &entries); -stack_trace_print (entries, nr_entries,0 ); -} -static void print_track (struct kasan_track *track,const char *prefix) {pr_err ("%s by task %u:\n" , prefix, track->pid);if (track->stack) { -print_stack (track->stack); +stack_depot_print (track->stack); }else {pr_err ("(stack is not available)\n" ); }
@@ -206,12 +197,12 @@ static void describe_object_stacks(struct kmem_cache *cache, void *object,return ;if (alloc_meta->aux_stack[0 ]) {pr_err ("Last potentially related work creation:\n" ); -print_stack (alloc_meta->aux_stack[0 ]); +stack_depot_print (alloc_meta->aux_stack[0 ]);pr_err ("\n" ); }if (alloc_meta->aux_stack[1 ]) {pr_err ("Second to last potentially related work creation:\n" ); -print_stack (alloc_meta->aux_stack[1 ]); +stack_depot_print (alloc_meta->aux_stack[1 ]);pr_err ("\n" ); }#endif
mm/page_owner.c +4 -9
@@ -394,8 +394,6 @@ void __dump_page_owner(const struct page *page)struct page_ext *page_ext =lookup_page_ext (page);struct page_owner *page_owner;depot_stack_handle_t handle; -unsigned long *entries; -unsigned int nr_entries;gfp_t gfp_mask;int mt;
@@ -423,20 +421,17 @@ void __dump_page_owner(const struct page *page) page_owner->pid, page_owner->ts_nsec, page_owner->free_ts_nsec); handle =READ_ONCE (page_owner->handle); -if (!handle) { +if (!handle)pr_alert ("page_owner allocation stack trace missing\n" ); - }else { - nr_entries =stack_depot_fetch (handle, &entries); -stack_trace_print (entries, nr_entries,0 ); - } +else +stack_depot_print (handle); handle =READ_ONCE (page_owner->free_handle);if (!handle) {pr_alert ("page_owner free stack trace missing\n" ); }else { - nr_entries =stack_depot_fetch (handle, &entries);pr_alert ("page last free stack trace:\n" ); -stack_trace_print (entries, nr_entries,0 ); +stack_depot_print (handle); }if (page_owner->last_migrate_reason !=-1 )
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 net: use .data.once section in netdev_level_once()
From: Eric Dumazet <[email protected]>
[ Upstream commit 7071732c26fe2cf141185ed16a8a85d02495ae8c ]
Same rationale than prior patch : using the dedicated section avoid holes and pack all these bool values.
Stable-dep-of: 56453199d28f ("net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()")
--- include/linux/netdevice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/netdevice.h +1 -1
@@ -5363,7 +5363,7 @@ void netdev_info(const struct net_device *dev, const char *format, ...);#define netdev_level_once (level, dev, fmt, ...) \ do { \ - static bool __print_once __read_mostly; \ + static bool __section(".data.once") __print_once; \ \ if (!__print_once) { \ __print_once = true; \
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 net: add include/net/net_debug.h
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit 5b87be9e4978fe507c7e14c0bdff147d10d39aec ]
Remove from include/linux/netdevice.h helpers
that send debug/info/warnings to syslog.
We plan adding more helpers in following patches.
v2: added two includes, and 'struct net_device' forward declaration
to avoid compile errors (kernel bots)
Extract the helpers that send debug/info/warnings to syslog from the network device header.
We plan adding more helpers in following patches.
v2: added two includes, and 'struct net_device' forward declaration
to avoid compile errors (kernel bots)
Omit the refcount-tracker include from the upstream context because the tracker infrastructure is absent. It is unrelated to this logging helper extraction. Keep the new header unchanged for the networking debug checks that follow.
Stable-dep-of: 56453199d28f ("net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()")
--- include/linux/netdevice.h | 141 +---------------------------------- include/net/net_debug.h | 151 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 140 deletions(-) create mode 100644 include/net/net_debug.h
include/linux/netdevice.h +1 -140
@@ -48,6 +48,7 @@#include <uapi/linux/pkt_cls.h> #include <linux/hashtable.h> #include <linux/rbtree.h> +#include <net/net_debug.h> struct netpoll_info ;struct device ;
@@ -5343,81 +5344,9 @@ static inline const char *netdev_reg_state(const struct net_device *dev)return " (unknown)" ; } -__printf(3, 4) __cold -void netdev_printk (const char *level,const struct net_device *dev, -const char *format, ...); -__printf(2, 3) __cold -void netdev_emerg (const struct net_device *dev,const char *format, ...); -__printf(2, 3) __cold -void netdev_alert (const struct net_device *dev,const char *format, ...); -__printf(2, 3) __cold -void netdev_crit (const struct net_device *dev,const char *format, ...); -__printf(2, 3) __cold -void netdev_err (const struct net_device *dev,const char *format, ...); -__printf(2, 3) __cold -void netdev_warn (const struct net_device *dev,const char *format, ...); -__printf(2, 3) __cold -void netdev_notice (const struct net_device *dev,const char *format, ...); -__printf(2, 3) __cold -void netdev_info (const struct net_device *dev,const char *format, ...); - -#define netdev_level_once (level, dev, fmt, ...) \ -do { \ - static bool __section(".data.once") __print_once; \ - \ - if (!__print_once) { \ - __print_once = true; \ - netdev_printk(level, dev, fmt, ##__VA_ARGS__); \ - } \ -} while (0) - -#define netdev_emerg_once (dev, fmt, ...) \ - netdev_level_once(KERN_EMERG, dev, fmt, ##__VA_ARGS__) -#define netdev_alert_once (dev, fmt, ...) \ - netdev_level_once(KERN_ALERT, dev, fmt, ##__VA_ARGS__) -#define netdev_crit_once (dev, fmt, ...) \ - netdev_level_once(KERN_CRIT, dev, fmt, ##__VA_ARGS__) -#define netdev_err_once (dev, fmt, ...) \ - netdev_level_once(KERN_ERR, dev, fmt, ##__VA_ARGS__) -#define netdev_warn_once (dev, fmt, ...) \ - netdev_level_once(KERN_WARNING, dev, fmt, ##__VA_ARGS__) -#define netdev_notice_once (dev, fmt, ...) \ - netdev_level_once(KERN_NOTICE, dev, fmt, ##__VA_ARGS__) -#define netdev_info_once (dev, fmt, ...) \ - netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__) -#define MODULE_ALIAS_NETDEV (device) \ MODULE_ALIAS("netdev-" device) -#if defined(CONFIG_DYNAMIC_DEBUG ) || \ - (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) -#define netdev_dbg(__dev, format, args...) \ -do { \ - dynamic_netdev_dbg(__dev, format, ##args); \ -} while (0) -#elif defined(DEBUG ) -#define netdev_dbg(__dev, format, args...) \ - netdev_printk(KERN_DEBUG, __dev, format, ##args) -#else -#define netdev_dbg(__dev, format, args...) \ -({ \ - if (0) \ - netdev_printk(KERN_DEBUG, __dev, format, ##args); \ -}) -#endif - -#if defined(VERBOSE_DEBUG ) -#define netdev_vdbg netdev_dbg -#else - -#define netdev_vdbg(dev, format, args...) \ -({ \ - if (0) \ - netdev_printk(KERN_DEBUG, dev, format, ##args); \ - 0; \ -}) -#endif -/* * netdev_WARN() acts like dev_printk(), but with the key difference * of using a WARN/WARN_ON to get the message out, including the
@@ -5431,74 +5360,6 @@ do { \WARN_ONCE (1 ,"netdevice: %s%s: " format,netdev_name (dev), \ netdev_reg_state(dev), ##args) -/* netif printk helpers, similar to netdev_printk */ - -#define netif_printk(priv, type, level, dev, fmt, args...) \ -do { \ - if (netif_msg_##type(priv)) \ - netdev_printk(level, (dev), fmt, ##args); \ -} while (0) - -#define netif_level(level, priv, type, dev, fmt, args...) \ -do { \ - if (netif_msg_##type(priv)) \ - netdev_##level(dev, fmt, ##args); \ -} while (0) - -#define netif_emerg(priv, type, dev, fmt, args...) \ - netif_level(emerg, priv, type, dev, fmt, ##args) -#define netif_alert(priv, type, dev, fmt, args...) \ - netif_level(alert, priv, type, dev, fmt, ##args) -#define netif_crit(priv, type, dev, fmt, args...) \ - netif_level(crit, priv, type, dev, fmt, ##args) -#define netif_err(priv, type, dev, fmt, args...) \ - netif_level(err, priv, type, dev, fmt, ##args) -#define netif_warn(priv, type, dev, fmt, args...) \ - netif_level(warn, priv, type, dev, fmt, ##args) -#define netif_notice(priv, type, dev, fmt, args...) \ - netif_level(notice, priv, type, dev, fmt, ##args) -#define netif_info(priv, type, dev, fmt, args...) \ - netif_level(info, priv, type, dev, fmt, ##args) - -#if defined(CONFIG_DYNAMIC_DEBUG) || \ - (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) -#define netif_dbg(priv, type, netdev, format, args...) \ -do { \ - if (netif_msg_##type(priv)) \ - dynamic_netdev_dbg(netdev, format, ##args); \ -} while (0) -#elif defined(DEBUG) -#define netif_dbg(priv, type, dev, format, args...) \ - netif_printk(priv, type, KERN_DEBUG, dev, format, ##args) -#else -#define netif_dbg(priv, type, dev, format, args...) \ -({ \ - if (0) \ - netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \ - 0; \ -}) -#endif - -/* if @cond then downgrade to debug, else print at @level */ -#define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \ - do { \ - if (cond) \ - netif_dbg(priv, type, netdev, fmt, ##args); \ - else \ - netif_ ## level(priv, type, netdev, fmt, ##args); \ - } while (0) - -#if defined(VERBOSE_DEBUG) -#define netif_vdbg netif_dbg -#else -#define netif_vdbg(priv, type, dev, format, args...) \ -({ \ - if (0) \ - netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \ - 0; \ -}) -#endif -/* * The list of packet types we will receive (as opposed to discard) * and the routines to invoke.
include/net/net_debug.h new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()
In reply to Sasha LevinFrom: Josef Bacik <[email protected]>
[ Upstream commit 56453199d28f0072a8196fba14b2d702632e2219 ]
skb_copy_and_csum_dev() copies everything up to the checksum start out of the linear area, and BUG()s if the checksum start is past the end of the linear area. It misses the other direction: a CHECKSUM_PARTIAL skb that has been pulled past its csum_start gives a negative offset, which gets past the check and becomes a ~4GB copy. It also trusts csum_offset when it stores the folded checksum. So far skb_copy_and_csum_bits() BUG()ing on a short skb has covered for that, but once it returns instead, a bad csum_offset would write past the end of the caller's buffer.
The function returns void and its callers are drivers copying a frame into a bounce buffer just before handing it to the hardware. There's nothing for them to back out of, so check both ends of csum_start and that the checksum field fits in the frame, and if not, copy the whole frame with skb_copy_bits() without filling in the checksum, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels. The frame
goes out with a bad checksum and is dropped by the receiver. If even that copy fails, zero the buffer so the driver doesn't send stale bytes.
--- net/core/skbuff.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/core/skbuff.c +12 -1
@@ -3257,7 +3257,18 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else csstart =skb_headlen (skb); -BUG_ON (csstart >skb_headlen (skb)); +if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + (skb->ip_summed ==CHECKSUM_PARTIAL && + csstart + skb->csum_offset +sizeof (__sum16) > + skb->len))) { +WARN_ON_ONCE (IS_ENABLED (CONFIG_DEBUG_NET )); +/* Send the frame without the checksum filled in, or send +* zeroes if we can't even copy it. +*/ +if (skb_copy_bits (skb,0 , to, skb->len)) +memset (to,0 , skb->len); +return ; + }skb_copy_from_linear_data (skb, to, csstart);
Signature · 1 line
2.53.0