stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev,
	Christoph Paasch <christoph.paasch@gmail.com>,
	Vasily Averin <vvs@virtuozzo.com>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH 5.4 60/93] skb_expand_head() adjust skb->truesize incorrectly
Date: Mon,  6 Jan 2025 16:17:36 +0100	[thread overview]
Message-ID: <20250106151130.971492292@linuxfoundation.org> (raw)
In-Reply-To: <20250106151128.686130933@linuxfoundation.org>

5.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Vasily Averin <vvs@virtuozzo.com>

commit 7f678def99d29c520418607509bb19c7fc96a6db upstream.

Christoph Paasch reports [1] about incorrect skb->truesize
after skb_expand_head() call in ip6_xmit.
This may happen because of two reasons:
- skb_set_owner_w() for newly cloned skb is called too early,
before pskb_expand_head() where truesize is adjusted for (!skb-sk) case.
- pskb_expand_head() does not adjust truesize in (skb->sk) case.
In this case sk->sk_wmem_alloc should be adjusted too.

[1] https://lkml.org/lkml/2021/8/20/1082

Fixes: f1260ff15a71 ("skbuff: introduce skb_expand_head()")
Fixes: 2d85a1b31dde ("ipv6: ip6_finish_output2: set sk into newly allocated nskb")
Reported-by: Christoph Paasch <christoph.paasch@gmail.com>
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/644330dd-477e-0462-83bf-9f514c41edd1@virtuozzo.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/core/skbuff.c |   36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
 create mode 100644 net/core/sock_destructor.h

--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -77,6 +77,7 @@
 #include <linux/indirect_call_wrapper.h>
 
 #include "datagram.h"
+#include "sock_destructor.h"
 
 struct kmem_cache *skbuff_head_cache __ro_after_init;
 static struct kmem_cache *skbuff_fclone_cache __ro_after_init;
@@ -1741,30 +1742,39 @@ EXPORT_SYMBOL(skb_realloc_headroom);
 struct sk_buff *skb_expand_head(struct sk_buff *skb, unsigned int headroom)
 {
 	int delta = headroom - skb_headroom(skb);
+	int osize = skb_end_offset(skb);
+	struct sock *sk = skb->sk;
 
 	if (WARN_ONCE(delta <= 0,
 		      "%s is expecting an increase in the headroom", __func__))
 		return skb;
 
-	/* pskb_expand_head() might crash, if skb is shared */
-	if (skb_shared(skb)) {
+	delta = SKB_DATA_ALIGN(delta);
+	/* pskb_expand_head() might crash, if skb is shared. */
+	if (skb_shared(skb) || !is_skb_wmem(skb)) {
 		struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
 
-		if (likely(nskb)) {
-			if (skb->sk)
-				skb_set_owner_w(nskb, skb->sk);
-			consume_skb(skb);
-		} else {
-			kfree_skb(skb);
-		}
+		if (unlikely(!nskb))
+			goto fail;
+
+		if (sk)
+			skb_set_owner_w(nskb, sk);
+		consume_skb(skb);
 		skb = nskb;
 	}
-	if (skb &&
-	    pskb_expand_head(skb, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
-		kfree_skb(skb);
-		skb = NULL;
+	if (pskb_expand_head(skb, delta, 0, GFP_ATOMIC))
+		goto fail;
+
+	if (sk && is_skb_wmem(skb)) {
+		delta = skb_end_offset(skb) - osize;
+		refcount_add(delta, &sk->sk_wmem_alloc);
+		skb->truesize += delta;
 	}
 	return skb;
+
+fail:
+	kfree_skb(skb);
+	return NULL;
 }
 EXPORT_SYMBOL(skb_expand_head);
 



  parent reply	other threads:[~2025-01-06 16:00 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06 15:16 [PATCH 5.4 00/93] 5.4.289-rc1 review Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 01/93] net: sched: fix ordering of qlen adjustment Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 02/93] usb: dwc2: gadget: Dont write invalid mapped sg entries into dma_desc with iommu enabled Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 03/93] PCI/AER: Disable AER service on suspend Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 04/93] ALSA: usb: Fix UBSAN warning in parse_audio_unit() Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 05/93] PCI: Add ACS quirk for Broadcom BCM5760X NIC Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 06/93] i2c: pnx: Fix timeout in wait functions Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 07/93] drm/i915: Fix memory leak by correcting cache object name in error handler Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 08/93] erofs: fix order >= MAX_ORDER warning due to crafted negative i_size Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 09/93] erofs: fix incorrect symlink detection in fast symlink Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 10/93] net/smc: check sndbuf_space again after NOSPACE flag is set in smc_poll Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 11/93] ionic: use ee->offset when returning sprom data Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 12/93] net: hinic: Fix cleanup in create_rxqs/txqs() Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 13/93] net: ethernet: bgmac-platform: fix an OF node reference leak Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 14/93] netfilter: ipset: Fix for recursive locking warning Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 15/93] mmc: sdhci-tegra: Remove SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC quirk Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 16/93] chelsio/chtls: prevent potential integer overflow on 32bit Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 17/93] i2c: riic: Always round-up when calculating bus period Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 18/93] efivarfs: Fix error on non-existent file Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 19/93] USB: serial: option: add TCL IK512 MBIM & ECM Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 20/93] USB: serial: option: add MeiG Smart SLM770A Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 21/93] USB: serial: option: add Netprisma LCUK54 modules for WWAN Ready Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 22/93] USB: serial: option: add MediaTek T7XX compositions Greg Kroah-Hartman
2025-01-06 15:16 ` [PATCH 5.4 23/93] USB: serial: option: add Telit FE910C04 rmnet compositions Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 24/93] sh: clk: Fix clk_enable() to return 0 on NULL clk Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 25/93] zram: refuse to use zero sized block device as backing device Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 26/93] btrfs: tree-checker: reject inline extent items with 0 ref count Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 27/93] NFS/pnfs: Fix a live lock between recalled layouts and layoutget Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 28/93] of/irq: Fix using uninitialized variable @addr_len in API of_irq_parse_one() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 29/93] nilfs2: prevent use of deleted inode Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 30/93] udmabuf: also check for F_SEAL_FUTURE_WRITE Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 31/93] of: Fix error path in of_parse_phandle_with_args_map() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 32/93] of: Fix refcount leakage for OF node returned by __of_get_dma_parent() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 33/93] media: dvb-frontends: dib3000mb: fix uninit-value in dib3000_write_reg Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 34/93] bpf: Check negative offsets in __bpf_skb_min_len() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 35/93] nfsd: restore callback functionality for NFSv4.0 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 36/93] mtd: diskonchip: Cast an operand to prevent potential overflow Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 37/93] phy: core: Fix an OF node refcount leakage in _of_phy_get() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 38/93] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 39/93] phy: core: Fix that API devm_phy_put() fails to release the phy Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 40/93] phy: core: Fix that API devm_phy_destroy() fails to destroy " Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 41/93] dmaengine: mv_xor: fix child node refcount handling in early exit Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 42/93] dmaengine: at_xdmac: avoid null_prt_deref in at_xdmac_prep_dma_memset Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 43/93] mtd: rawnand: fix double free in atmel_pmecc_create_user() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 44/93] tracing/kprobe: Make trace_kprobes module callback called after jump_label update Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 45/93] scsi: qla1280: Fix hw revision numbering for ISP1020/1040 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 46/93] scsi: megaraid_sas: Fix for a potential deadlock Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 47/93] regmap: Use correct format specifier for logging range errors Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 48/93] platform/x86: asus-nb-wmi: Ignore unknown event 0xCF Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 49/93] scsi: mpt3sas: Diag-Reset when Doorbell-In-Use bit is set during driver load time Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 50/93] virtio-blk: dont keep queue frozen during system suspend Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 51/93] epoll: Add synchronous wakeup support for ep_poll_callback Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 52/93] MIPS: Probe toolchain support of -msym32 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 53/93] skbuff: introduce skb_expand_head() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 54/93] ipv6: use skb_expand_head in ip6_finish_output2 Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 55/93] ipv6: use skb_expand_head in ip6_xmit Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 56/93] ipv6: fix possible UAF in ip6_finish_output2() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 57/93] bpf: fix recursive lock when verdict program return SK_PASS Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 58/93] tracing: Constify string literal data member in struct trace_event_call Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 59/93] btrfs: avoid monopolizing a core when activating a swap file Greg Kroah-Hartman
2025-01-06 15:17 ` Greg Kroah-Hartman [this message]
2025-01-06 15:17 ` [PATCH 5.4 61/93] ipv6: prevent possible UAF in ip6_xmit() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 62/93] selinux: ignore unknown extended permissions Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 63/93] Drivers: hv: util: Avoid accessing a ringbuffer not initialized yet Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 64/93] IB/mlx5: Introduce and use mlx5_core_is_vf() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 65/93] net/mlx5: Make API mlx5_core_is_ecpf accept const pointer Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 66/93] RDMA/mlx5: Enforce same type port association for multiport RoCE Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 67/93] RDMA/bnxt_re: Add check for path mtu in modify_qp Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 68/93] RDMA/bnxt_re: Fix reporting hw_ver in query_device Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 69/93] RDMA/bnxt_re: Fix max_qp_wrs reported Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 70/93] drm: bridge: adv7511: Enable SPDIF DAI Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 71/93] drm/bridge: adv7511_audio: Update Audio InfoFrame properly Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 72/93] netrom: check buffer length before accessing it Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 73/93] netfilter: Replace zero-length array with flexible-array member Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 74/93] netfilter: nft_set_hash: unaligned atomic read on struct nft_set_ext Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 75/93] net: llc: reset skb->transport_header Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 76/93] ALSA: usb-audio: US16x08: Initialize array before use Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 77/93] af_packet: fix vlan_get_tci() vs MSG_PEEK Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 78/93] af_packet: fix vlan_get_protocol_dgram() " Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 79/93] ila: serialize calls to nf_register_net_hooks() Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 80/93] wifi: mac80211: wake the queues in case of failure in resume Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 81/93] sound: usb: format: dont warn that raw DSD is unsupported Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 82/93] bpf: fix potential error return Greg Kroah-Hartman
2025-01-06 15:17 ` [PATCH 5.4 83/93] net: usb: qmi_wwan: add Telit FE910C04 compositions Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 84/93] irqchip/gic: Correct declaration of *percpu_base pointer in union gic_base Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 85/93] ARC: build: Try to guess GCC variant of cross compiler Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 86/93] modpost: fix input MODULE_DEVICE_TABLE() built for 64-bit on 32-bit host Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 87/93] modpost: fix the missed iteration for the max bit in do_input() Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 88/93] RDMA/uverbs: Prevent integer overflow issue Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 89/93] pinctrl: mcp23s08: Fix sleeping in atomic context due to regmap locking Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 90/93] sky2: Add device ID 11ab:4373 for Marvell 88E8075 Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 91/93] net/sctp: Prevent autoclose integer overflow in sctp_association_init() Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 92/93] drm: adv7511: Drop dsi single lane support Greg Kroah-Hartman
2025-01-06 15:18 ` [PATCH 5.4 93/93] mm: vmscan: account for free pages to prevent infinite Loop in throttle_direct_reclaim() Greg Kroah-Hartman
2025-01-06 18:58 ` [PATCH 5.4 00/93] 5.4.289-rc1 review Florian Fainelli
2025-01-07 12:43 ` Jon Hunter
2025-01-07 13:50 ` Naresh Kamboju
2025-01-07 23:16 ` Shuah Khan
2025-01-08 13:00 ` Muhammad Usama Anjum
2025-01-09 10:12   ` Greg Kroah-Hartman
2025-01-09 14:10     ` Muhammad Usama Anjum
2025-01-09 14:14       ` Mark Brown
2025-01-08 14:13 ` Harshit Mogalapalli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250106151130.971492292@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=christoph.paasch@gmail.com \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=vvs@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).