linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, alexander.levin@verizon.com,
	Dave Jones <davej@codemonkey.org.uk>,
	"liujian (CE)" <liujian56@huawei.com>,
	Ding Tianhong <dingtianhong@huawei.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 4.9 49/93] packet: fix use-after-free in prb_retire_rx_blk_timer_expired()
Date: Wed,  9 Aug 2017 11:13:42 -0700	[thread overview]
Message-ID: <20170809181337.643487659@linuxfoundation.org> (raw)
In-Reply-To: <20170809181335.658857427@linuxfoundation.org>

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

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

From: WANG Cong <xiyou.wangcong@gmail.com>


[ Upstream commit c800aaf8d869f2b9b47b10c5c312fe19f0a94042 ]

There are multiple reports showing we have a use-after-free in
the timer prb_retire_rx_blk_timer_expired(), where we use struct
tpacket_kbdq_core::pkbdq, a pg_vec, after it gets freed by
free_pg_vec().

The interesting part is it is not freed via packet_release() but
via packet_setsockopt(), which means we are not closing the socket.
Looking into the big and fat function packet_set_ring(), this could
happen if we satisfy the following conditions:

1. closing == 0, not on packet_release() path
2. req->tp_block_nr == 0, we don't allocate a new pg_vec
3. rx_ring->pg_vec is already set as V3, which means we already called
   packet_set_ring() wtih req->tp_block_nr > 0 previously
4. req->tp_frame_nr == 0, pass sanity check
5. po->mapped == 0, never called mmap()

In this scenario we are clearing the old rx_ring->pg_vec, so we need
to free this pg_vec, but we don't stop the timer on this path because
of closing==0.

The timer has to be stopped as long as we need to free pg_vec, therefore
the check on closing!=0 is wrong, we should check pg_vec!=NULL instead.

Thanks to liujian for testing different fixes.

Reported-by: alexander.levin@verizon.com
Reported-by: Dave Jones <davej@codemonkey.org.uk>
Reported-by: liujian (CE) <liujian56@huawei.com>
Tested-by: liujian (CE) <liujian56@huawei.com>
Cc: Ding Tianhong <dingtianhong@huawei.com>
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/packet/af_packet.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4322,7 +4322,7 @@ static int packet_set_ring(struct sock *
 		register_prot_hook(sk);
 	}
 	spin_unlock(&po->bind_lock);
-	if (closing && (po->tp_version > TPACKET_V2)) {
+	if (pg_vec && (po->tp_version > TPACKET_V2)) {
 		/* Because we don't support block-based V3 on tx-ring */
 		if (!tx_ring)
 			prb_shutdown_retire_blk_timer(po, rb_queue);

  parent reply	other threads:[~2017-08-09 18:15 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-09 18:12 [PATCH 4.9 00/93] 4.9.42-stable review Greg Kroah-Hartman
2017-08-09 18:12 ` [PATCH 4.9 01/93] parisc: Handle vmas whose context is not current in flush_cache_range Greg Kroah-Hartman
2017-08-09 18:12 ` [PATCH 4.9 02/93] cgroup: create dfl_root files on subsys registration Greg Kroah-Hartman
2017-08-09 18:12 ` [PATCH 4.9 03/93] cgroup: fix error return value from cgroup_subtree_control() Greg Kroah-Hartman
2017-08-09 18:12 ` [PATCH 4.9 04/93] libata: array underflow in ata_find_dev() Greg Kroah-Hartman
2017-08-09 18:12 ` [PATCH 4.9 05/93] workqueue: restore WQ_UNBOUND/max_active==1 to be ordered Greg Kroah-Hartman
2017-08-09 18:12 ` [PATCH 4.9 06/93] iwlwifi: dvm: prevent an out of bounds access Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 07/93] brcmfmac: fix memleak due to calling brcmf_sdiod_sgtable_alloc() twice Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 08/93] NFSv4: Fix EXCHANGE_ID corrupt verifier issue Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 09/93] mmc: sdhci-of-at91: force card detect value for non removable devices Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 10/93] device property: Make dev_fwnode() public Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 11/93] mmc: core: Fix access to HS400-ES devices Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 12/93] mm, mprotect: flush TLB if potentially racing with a parallel reclaim leaving stale TLB entries Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 13/93] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 14/93] ALSA: hda - Fix speaker output from VAIO VPCL14M1R Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 16/93] ASoC: do not close shared backend dailink Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 18/93] mm/page_alloc: Remove kernel address exposure in free_reserved_area() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 19/93] timers: Fix overflow in get_next_timer_interrupt Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 20/93] powerpc/tm: Fix saving of TM SPRs in core dump Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 21/93] powerpc/64: Fix __check_irq_replay missing decrementer interrupt Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 22/93] iommu/amd: Enable ga_log_intr when enabling guest_mode Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 23/93] gpiolib: skip unwanted events, dont convert them to opposite edge Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 24/93] ext4: fix SEEK_HOLE/SEEK_DATA for blocksize < pagesize Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 25/93] ext4: fix overflow caused by missing cast in ext4_resize_fs() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 26/93] ARM: dts: armada-38x: Fix irq type for pca955 Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 27/93] ARM: dts: tango4: Request RGMII RX and TX clock delays Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 28/93] media: platform: davinci: return -EINVAL for VPFE_CMD_S_CCDC_RAW_PARAMS ioctl Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 29/93] iscsi-target: Fix initial login PDU asynchronous socket close OOPs Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 30/93] mmc: dw_mmc: Use device_property_read instead of of_property_read Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 31/93] mmc: core: " Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 32/93] media: lirc: LIRC_GET_REC_RESOLUTION should return microseconds Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 33/93] f2fs: sanity check checkpoint segno and blkoff Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 34/93] Btrfs: fix early ENOSPC due to delalloc Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 35/93] [media] saa7164: fix double fetch PCIe access condition Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 36/93] tcp_bbr: cut pacing rate only if filled pipe Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 37/93] tcp_bbr: introduce bbr_bw_to_pacing_rate() helper Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 38/93] tcp_bbr: introduce bbr_init_pacing_rate_from_rtt() helper Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 39/93] tcp_bbr: remove sk_pacing_rate=0 transient during init Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 40/93] tcp_bbr: init pacing rate on first RTT sample Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 41/93] ipv4: ipv6: initialize treq->txhash in cookie_v[46]_check() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 42/93] net: Zero terminate ifr_name in dev_ifname() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 43/93] ipv6: avoid overflow of offset in ip6_find_1stfragopt Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 44/93] net: dsa: b53: Add missing ARL entries for BCM53125 Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 45/93] ipv4: initialize fib_trie prior to register_netdev_notifier call Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 46/93] rtnetlink: allocate more memory for dev_set_mac_address() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 47/93] mcs7780: Fix initialization when CONFIG_VMAP_STACK is enabled Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 48/93] openvswitch: fix potential out of bound access in parse_ct Greg Kroah-Hartman
2017-08-09 18:13 ` Greg Kroah-Hartman [this message]
2017-08-09 18:13 ` [PATCH 4.9 50/93] ipv6: Dont increase IPSTATS_MIB_FRAGFAILS twice in ip6_fragment() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 51/93] net: ethernet: nb8800: Handle all 4 RGMII modes identically Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 52/93] dccp: fix a memleak that dccp_ipv6 doesnt put reqsk properly Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 53/93] dccp: fix a memleak that dccp_ipv4 " Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 54/93] dccp: fix a memleak for dccp_feat_init err process Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 55/93] sctp: dont dereference ptr before leaving _sctp_walk_{params, errors}() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 56/93] sctp: fix the check for _sctp_walk_params and _sctp_walk_errors Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 57/93] net/mlx5: Consider tx_enabled in all modes on remap Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 58/93] net/mlx5: Fix command bad flow on command entry allocation failure Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 59/93] net/mlx5e: Fix outer_header_zero() check size Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 60/93] net/mlx5e: Fix wrong delay calculation for overflow check scheduling Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 61/93] net/mlx5e: Schedule overflow check work to mlx5e workqueue Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 62/93] net: phy: Correctly process PHY_HALTED in phy_stop_machine() Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 63/93] xen-netback: correctly schedule rate-limited queues Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 64/93] sparc64: Measure receiver forward progress to avoid send mondo timeout Greg Kroah-Hartman
2017-08-09 18:13 ` [PATCH 4.9 65/93] sparc64: Prevent perf from running during super critical sections Greg Kroah-Hartman
2017-08-10 16:20   ` Greg Kroah-Hartman
2017-08-10 16:45     ` David Miller
2017-08-11  5:00     ` David Miller
2017-08-11 19:33       ` Greg KH
2017-08-09 18:13 ` [PATCH 4.9 66/93] sparc64: Fix exception handling in UltraSPARC-III memcpy Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 67/93] wext: handle NULL extra data in iwe_stream_add_point better Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 68/93] sh_eth: fix EESIPR values for SH77{34|63} Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 69/93] sh_eth: R8A7740 supports packet shecksumming Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 70/93] net: phy: dp83867: fix irq generation Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 71/93] tg3: Fix race condition in tg3_get_stats64() Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 72/93] x86/boot: Add missing declaration of string functions Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 73/93] spi: spi-axi: Free resources on error path Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 74/93] ASoC: rt5645: set sel_i2s_pre_div1 to 2 Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 75/93] netfilter: use fwmark_reflect in nf_send_reset Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 76/93] phy state machine: failsafe leave invalid RUNNING state Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 77/93] ipv4: make tcp_notsent_lowat sysctl knob behave as true unsigned int Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 78/93] clk/samsung: exynos542x: mark some clocks as critical Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 79/93] scsi: qla2xxx: Get mutex lock before checking optrom_state Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 80/93] drm/virtio: fix framebuffer sparse warning Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 81/93] ARM: dts: sun8i: Support DTB build for NanoPi M1 Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 82/93] ARM: dts: sunxi: Change node name for pwrseq pin on Olinuxino-lime2-emmc Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 83/93] iw_cxgb4: do not send RX_DATA_ACK CPLs after close/abort Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 84/93] nbd: blk_mq_init_queue returns an error code on failure, not NULL Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 85/93] virtio_blk: fix panic in initialization error path Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 86/93] ARM: 8632/1: ftrace: fix syscall name matching Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 87/93] mm, slab: make sure that KMALLOC_MAX_SIZE will fit into MAX_ORDER Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 88/93] lib/Kconfig.debug: fix frv build failure Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 89/93] signal: protect SIGNAL_UNKILLABLE from unintentional clearing Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 90/93] mm: dont dereference struct page fields of invalid pages Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 91/93] net/mlx5: E-Switch, Re-enable RoCE on mode change only after FDB destroy Greg Kroah-Hartman
2017-08-09 18:14 ` [PATCH 4.9 92/93] ipv4: Should use consistent conditional judgement for ip fragment in __ip_append_data and ip_finish_output Greg Kroah-Hartman
2017-08-10  0:15 ` [PATCH 4.9 00/93] 4.9.42-stable review Shuah Khan
2017-08-10  0:41 ` Guenter Roeck
2017-08-10  3:04 ` Sumit Semwal

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=20170809181337.643487659@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=alexander.levin@verizon.com \
    --cc=davej@codemonkey.org.uk \
    --cc=davem@davemloft.net \
    --cc=dingtianhong@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liujian56@huawei.com \
    --cc=stable@vger.kernel.org \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=xiyou.wangcong@gmail.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).