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,
	Andrew Morton <akpm@linux-foundation.org>,
	Chunwei Chen <david.chen@nutanix.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 5.15 63/67] Fix page corruption caused by racy check in __free_pages
Date: Mon, 13 Feb 2023 15:49:44 +0100	[thread overview]
Message-ID: <20230213144735.393429059@linuxfoundation.org> (raw)
In-Reply-To: <20230213144732.336342050@linuxfoundation.org>

From: David Chen <david.chen@nutanix.com>

commit 462a8e08e0e6287e5ce13187257edbf24213ed03 upstream.

When we upgraded our kernel, we started seeing some page corruption like
the following consistently:

  BUG: Bad page state in process ganesha.nfsd  pfn:1304ca
  page:0000000022261c55 refcount:0 mapcount:-128 mapping:0000000000000000 index:0x0 pfn:0x1304ca
  flags: 0x17ffffc0000000()
  raw: 0017ffffc0000000 ffff8a513ffd4c98 ffffeee24b35ec08 0000000000000000
  raw: 0000000000000000 0000000000000001 00000000ffffff7f 0000000000000000
  page dumped because: nonzero mapcount
  CPU: 0 PID: 15567 Comm: ganesha.nfsd Kdump: loaded Tainted: P    B      O      5.10.158-1.nutanix.20221209.el7.x86_64 #1
  Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 04/05/2016
  Call Trace:
   dump_stack+0x74/0x96
   bad_page.cold+0x63/0x94
   check_new_page_bad+0x6d/0x80
   rmqueue+0x46e/0x970
   get_page_from_freelist+0xcb/0x3f0
   ? _cond_resched+0x19/0x40
   __alloc_pages_nodemask+0x164/0x300
   alloc_pages_current+0x87/0xf0
   skb_page_frag_refill+0x84/0x110
   ...

Sometimes, it would also show up as corruption in the free list pointer
and cause crashes.

After bisecting the issue, we found the issue started from commit
e320d3012d25 ("mm/page_alloc.c: fix freeing non-compound pages"):

	if (put_page_testzero(page))
		free_the_page(page, order);
	else if (!PageHead(page))
		while (order-- > 0)
			free_the_page(page + (1 << order), order);

So the problem is the check PageHead is racy because at this point we
already dropped our reference to the page.  So even if we came in with
compound page, the page can already be freed and PageHead can return
false and we will end up freeing all the tail pages causing double free.

Fixes: e320d3012d25 ("mm/page_alloc.c: fix freeing non-compound pages")
Link: https://lore.kernel.org/lkml/BYAPR02MB448855960A9656EEA81141FC94D99@BYAPR02MB4488.namprd02.prod.outlook.com/
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: stable@vger.kernel.org
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 mm/page_alloc.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5490,9 +5490,12 @@ EXPORT_SYMBOL(get_zeroed_page);
  */
 void __free_pages(struct page *page, unsigned int order)
 {
+	/* get PageHead before we drop reference */
+	int head = PageHead(page);
+
 	if (put_page_testzero(page))
 		free_the_page(page, order);
-	else if (!PageHead(page))
+	else if (!head)
 		while (order-- > 0)
 			free_the_page(page + (1 << order), order);
 }



  parent reply	other threads:[~2023-02-13 15:00 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13 14:48 [PATCH 5.15 00/67] 5.15.94-rc1 review Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 01/67] nvmem: core: add error handling for dev_set_name Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 02/67] nvmem: core: fix cleanup after dev_set_name() Greg Kroah-Hartman
2023-02-14 12:56   ` Russell King (Oracle)
2023-02-13 14:48 ` [PATCH 5.15 03/67] nvmem: core: fix registration vs use race Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 04/67] mm/migration: return errno when isolate_huge_page failed Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 05/67] migrate: hugetlb: check for hugetlb shared PMD in node migration Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 06/67] btrfs: limit device extents to the device size Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 07/67] btrfs: zlib: zero-initialize zlib workspace Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 08/67] ALSA: hda/realtek: Add Positivo N14KP6-TG Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 09/67] ALSA: emux: Avoid potential array out-of-bound in snd_emux_xg_control() Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 10/67] ALSA: hda/realtek: Fix the speaker output on Samsung Galaxy Book2 Pro 360 Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 11/67] ALSA: hda/realtek: Enable mute/micmute LEDs on HP Elitebook, 645 G9 Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 12/67] tracing: Fix poll() and select() do not work on per_cpu trace_pipe and trace_pipe_raw Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 13/67] of/address: Return an error when no valid dma-ranges are found Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 14/67] can: j1939: do not wait 250 ms if the same addr was already claimed Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 15/67] xfrm: compat: change expression for switch in xfrm_xlate64 Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 16/67] IB/hfi1: Restore allocated resources on failed copyout Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 17/67] xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr() Greg Kroah-Hartman
2023-02-13 14:48 ` [PATCH 5.15 18/67] IB/IPoIB: Fix legacy IPoIB due to wrong number of queues Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 19/67] RDMA/irdma: Fix potential NULL-ptr-dereference Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 20/67] RDMA/usnic: use iommu_map_atomic() under spin_lock() Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 21/67] xfrm: fix bug with DSCP copy to v6 from v4 tunnel Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 22/67] net: phylink: move phy_device_free() to correctly release phy device Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 23/67] bonding: fix error checking in bond_debug_reregister() Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 24/67] net: phy: meson-gxl: use MMD access dummy stubs for GXL, internal PHY Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 25/67] ionic: clean interrupt before enabling queue to avoid credit race Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 26/67] uapi: add missing ip/ipv6 header dependencies for linux/stddef.h Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 27/67] ice: Do not use WQ_MEM_RECLAIM flag for workqueue Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 28/67] net: dsa: mt7530: dont change PVC_EG_TAG when CPU port becomes VLAN-aware Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 29/67] net: mscc: ocelot: fix VCAP filters not matching on MAC with "protocol 802.1Q" Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 30/67] net/mlx5e: Move repeating clear_bit in mlx5e_rx_reporter_err_rq_cqe_recover Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 31/67] net/mlx5e: Introduce the mlx5e_flush_rq function Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 32/67] net/mlx5e: Update rx ring hw mtu upon each rx-fcs flag change Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 33/67] net/mlx5: Bridge, fix ageing of peer FDB entries Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 34/67] net/mlx5e: IPoIB, Show unknown speed instead of error Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 35/67] net/mlx5: fw_tracer, Clear load bit when freeing string DBs buffers Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 36/67] net/mlx5: fw_tracer, Zero consumer index when reloading the tracer Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 37/67] net/mlx5: Serialize module cleanup with reload and remove Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 38/67] igc: Add ndo_tx_timeout support Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 39/67] rds: rds_rm_zerocopy_callback() use list_first_entry() Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 40/67] selftests: forwarding: lib: quote the sysctl values Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 41/67] ALSA: pci: lx6464es: fix a debug loop Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 42/67] riscv: stacktrace: Fix missing the first frame Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 43/67] ASoC: topology: Return -ENOMEM on memory allocation failure Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 44/67] pinctrl: mediatek: Fix the drive register definition of some Pins Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 45/67] pinctrl: aspeed: Fix confusing types in return value Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 46/67] pinctrl: single: fix potential NULL dereference Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 47/67] spi: dw: Fix wrong FIFO level setting for long xfers Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 48/67] pinctrl: intel: Restore the pins that used to be in Direct IRQ mode Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 49/67] cifs: Fix use-after-free in rdata->read_into_pages() Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 50/67] net: USB: Fix wrong-direction WARNING in plusb.c Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 51/67] mptcp: be careful on subflow status propagation on errors Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 52/67] btrfs: free device in btrfs_close_devices for a single device filesystem Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 53/67] usb: core: add quirk for Alcor Link AK9563 smartcard reader Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 54/67] usb: typec: altmodes/displayport: Fix probe pin assign check Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 55/67] clk: ingenic: jz4760: Update M/N/OD calculation algorithm Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 56/67] ceph: flush cap releases when the session is flushed Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 57/67] riscv: Fixup race condition on PG_dcache_clean in flush_icache_pte Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 58/67] powerpc/64s/interrupt: Fix interrupt exit race with security mitigation switch Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 59/67] rtmutex: Ensure that the top waiter is always woken up Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 60/67] arm64: dts: meson-gx: Make mmc host controller interrupts level-sensitive Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 61/67] arm64: dts: meson-g12-common: " Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 62/67] arm64: dts: meson-axg: " Greg Kroah-Hartman
2023-02-13 14:49 ` Greg Kroah-Hartman [this message]
2023-02-13 14:49 ` [PATCH 5.15 64/67] drm/amdgpu/fence: Fix oops due to non-matching drm_sched init/fini Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 65/67] drm/i915: Initialize the obj flags for shmem objects Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 66/67] drm/i915: Fix VBT DSI DVO port handling Greg Kroah-Hartman
2023-02-13 14:49 ` [PATCH 5.15 67/67] nvmem: core: fix return value Greg Kroah-Hartman
2023-02-13 20:07 ` [PATCH 5.15 00/67] 5.15.94-rc1 review Florian Fainelli
2023-02-13 22:08 ` Allen Pais
2023-02-13 23:31 ` Shuah Khan
2023-02-14  3:04 ` Bagas Sanjaya
2023-02-14  8:26 ` Naresh Kamboju
2023-02-14 10:54 ` Sudip Mukherjee (Codethink)
2023-02-14 12:46 ` Ron Economos

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=20230213144735.393429059@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=david.chen@nutanix.com \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /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).