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, Antoine Tenart <atenart@kernel.org>,
	Alexander Duyck <alexanderduyck@fb.com>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH 4.14 15/57] net-sysfs: take the rtnl lock when storing xps_cpus
Date: Mon, 11 Jan 2021 14:01:34 +0100	[thread overview]
Message-ID: <20210111130034.468704561@linuxfoundation.org> (raw)
In-Reply-To: <20210111130033.715773309@linuxfoundation.org>

From: Antoine Tenart <atenart@kernel.org>

[ Upstream commit 1ad58225dba3f2f598d2c6daed4323f24547168f ]

Two race conditions can be triggered when storing xps cpus, resulting in
various oops and invalid memory accesses:

1. Calling netdev_set_num_tc while netif_set_xps_queue:

   - netif_set_xps_queue uses dev->tc_num as one of the parameters to
     compute the size of new_dev_maps when allocating it. dev->tc_num is
     also used to access the map, and the compiler may generate code to
     retrieve this field multiple times in the function.

   - netdev_set_num_tc sets dev->tc_num.

   If new_dev_maps is allocated using dev->tc_num and then dev->tc_num
   is set to a higher value through netdev_set_num_tc, later accesses to
   new_dev_maps in netif_set_xps_queue could lead to accessing memory
   outside of new_dev_maps; triggering an oops.

2. Calling netif_set_xps_queue while netdev_set_num_tc is running:

   2.1. netdev_set_num_tc starts by resetting the xps queues,
        dev->tc_num isn't updated yet.

   2.2. netif_set_xps_queue is called, setting up the map with the
        *old* dev->num_tc.

   2.3. netdev_set_num_tc updates dev->tc_num.

   2.4. Later accesses to the map lead to out of bound accesses and
        oops.

   A similar issue can be found with netdev_reset_tc.

One way of triggering this is to set an iface up (for which the driver
uses netdev_set_num_tc in the open path, such as bnx2x) and writing to
xps_cpus in a concurrent thread. With the right timing an oops is
triggered.

Both issues have the same fix: netif_set_xps_queue, netdev_set_num_tc
and netdev_reset_tc should be mutually exclusive. We do that by taking
the rtnl lock in xps_cpus_store.

Fixes: 184c449f91fe ("net: Add support for XPS with QoS via traffic classes")
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/core/net-sysfs.c |    6 ++++++
 1 file changed, 6 insertions(+)

--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1273,7 +1273,13 @@ static ssize_t xps_cpus_store(struct net
 		return err;
 	}
 
+	if (!rtnl_trylock()) {
+		free_cpumask_var(mask);
+		return restart_syscall();
+	}
+
 	err = netif_set_xps_queue(dev, mask, index);
+	rtnl_unlock();
 
 	free_cpumask_var(mask);
 



  parent reply	other threads:[~2021-01-11 14:00 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 13:01 [PATCH 4.14 00/57] 4.14.215-rc1 review Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 01/57] kbuild: dont hardcode depmod path Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 02/57] workqueue: Kick a worker based on the actual activation of delayed works Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 03/57] scsi: ufs-pci: Ensure UFS device is in PowerDown mode for suspend-to-disk ->poweroff() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 04/57] scsi: ide: Do not set the RQF_PREEMPT flag for sense requests Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 05/57] lib/genalloc: fix the overflow when size is too big Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 06/57] depmod: handle the case of /sbin/depmod without /sbin in PATH Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 07/57] ethernet: ucc_geth: fix use-after-free in ucc_geth_remove() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 08/57] ethernet: ucc_geth: set dev->max_mtu to 1518 Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 09/57] atm: idt77252: call pci_disable_device() on error path Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 10/57] qede: fix offload for IPIP tunnel packets Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 11/57] virtio_net: Fix recursive call to cpus_read_lock() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 12/57] net: dcb: Validate netlink message in DCB handler Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 13/57] net/ncsi: Use real net-device for response handler Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 14/57] net: ethernet: Fix memleak in ethoc_probe Greg Kroah-Hartman
2021-01-11 13:01 ` Greg Kroah-Hartman [this message]
2021-01-11 13:01 ` [PATCH 4.14 16/57] net: ethernet: ti: cpts: fix ethtool output when no ptp_clock registered Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 17/57] ipv4: Ignore ECN bits for fib lookups in fib_compute_spec_dst() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 18/57] net: hns: fix return value check in __lb_other_process() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 19/57] net: hdlc_ppp: Fix issues when mod_timer is called while timer is running Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 20/57] CDC-NCM: remove "connected" log message Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 21/57] net: usb: qmi_wwan: add Quectel EM160R-GL Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 22/57] vhost_net: fix ubuf refcount incorrectly when sendmsg fails Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 23/57] net: sched: prevent invalid Scell_log shift count Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 24/57] net-sysfs: take the rtnl lock when accessing xps_cpus_map and num_tc Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 25/57] net: mvpp2: Fix GoP port 3 Networking Complex Control configurations Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 26/57] net: systemport: set dev->max_mtu to UMAC_MAX_MTU_SIZE Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 27/57] video: hyperv_fb: Fix the mmap() regression for v5.4.y and older Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 28/57] crypto: ecdh - avoid buffer overflow in ecdh_set_secret() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 29/57] usb: gadget: enable super speed plus Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 30/57] USB: cdc-acm: blacklist another IR Droid device Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 31/57] usb: dwc3: ulpi: Use VStsDone to detect PHY regs access completion Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 32/57] usb: chipidea: ci_hdrc_imx: add missing put_device() call in usbmisc_get_init_data() Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 33/57] USB: xhci: fix U1/U2 handling for hardware with XHCI_INTEL_HOST quirk set Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 34/57] usb: usbip: vhci_hcd: protect shift size Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 35/57] usb: uas: Add PNY USB Portable SSD to unusual_uas Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 36/57] USB: serial: iuu_phoenix: fix DMA from stack Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 37/57] USB: serial: option: add LongSung M5710 module support Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 38/57] USB: serial: option: add Quectel EM160R-GL Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 39/57] USB: yurex: fix control-URB timeout handling Greg Kroah-Hartman
2021-01-11 13:01 ` [PATCH 4.14 40/57] USB: usblp: fix DMA to stack Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 41/57] ALSA: usb-audio: Fix UBSAN warnings for MIDI jacks Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 42/57] usb: gadget: select CONFIG_CRC32 Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 43/57] usb: gadget: f_uac2: reset wMaxPacketSize Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 44/57] usb: gadget: function: printer: Fix a memory leak for interface descriptor Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 45/57] USB: gadget: legacy: fix return error code in acm_ms_bind() Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 46/57] usb: gadget: Fix spinlock lockup on usb_function_deactivate Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 47/57] usb: gadget: configfs: Preserve function ordering after bind failure Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 48/57] usb: gadget: configfs: Fix use-after-free issue with udc_name Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 49/57] USB: serial: keyspan_pda: remove unused variable Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 50/57] x86/mm: Fix leak of pmd ptlock Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 51/57] ALSA: hda/conexant: add a new hda codec CX11970 Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 52/57] ALSA: hda/realtek - Fix speaker volume control on Lenovo C940 Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 53/57] Revert "device property: Keep secondary firmware node secondary by type" Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 54/57] netfilter: ipset: fix shift-out-of-bounds in htable_bits() Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 55/57] netfilter: xt_RATEEST: reject non-null terminated string from userspace Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 56/57] x86/mtrr: Correct the range check before performing MTRR type lookups Greg Kroah-Hartman
2021-01-11 13:02 ` [PATCH 4.14 57/57] KVM: x86: fix shift out of bounds reported by UBSAN Greg Kroah-Hartman
2021-01-11 21:53 ` [PATCH 4.14 00/57] 4.14.215-rc1 review Guenter Roeck
2021-01-12  7:36 ` Naresh Kamboju

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=20210111130034.468704561@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=alexanderduyck@fb.com \
    --cc=atenart@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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).