linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Johannes Berg <johannes.berg@intel.com>,
	Luca Coelho <luciano.coelho@intel.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.11 062/104] iwlwifi: pcie: make cfg vs. trans_cfg more robust
Date: Wed,  5 May 2021 12:33:31 -0400	[thread overview]
Message-ID: <20210505163413.3461611-62-sashal@kernel.org> (raw)
In-Reply-To: <20210505163413.3461611-1-sashal@kernel.org>

From: Johannes Berg <johannes.berg@intel.com>

[ Upstream commit 48a5494d6a4cb5812f0640d9515f1876ffc7a013 ]

If we (for example) have a trans_cfg entry in the PCI IDs table,
but then don't find a full cfg entry for it in the info table,
we fall through to the code that treats the PCI ID table entry
as a full cfg entry. This obviously causes crashes later, e.g.
when trying to build the firmware name string.

Avoid such crashes by using the low bit of the pointer as a tag
for trans_cfg entries (automatically using a macro that checks
the type when assigning) and then checking that before trying to
use the data as a full entry - if it's just a partial entry at
that point, fail.

Since we're adding some macro magic, also check that the type is
in fact either struct iwl_cfg_trans_params or struct iwl_cfg,
failing compilation ("initializer element is not constant") if
it isn't.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20210330162204.6f69fe6e4128.I921d4ae20ef5276716baeeeda0b001cf25b9b968@changeid
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/wireless/intel/iwlwifi/pcie/drv.c | 35 +++++++++++++++----
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
index 018daa84ddd2..70752f0c67b0 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
@@ -17,10 +17,20 @@
 #include "iwl-prph.h"
 #include "internal.h"
 
+#define TRANS_CFG_MARKER BIT(0)
+#define _IS_A(cfg, _struct) __builtin_types_compatible_p(typeof(cfg),	\
+							 struct _struct)
+extern int _invalid_type;
+#define _TRANS_CFG_MARKER(cfg)						\
+	(__builtin_choose_expr(_IS_A(cfg, iwl_cfg_trans_params),	\
+			       TRANS_CFG_MARKER,			\
+	 __builtin_choose_expr(_IS_A(cfg, iwl_cfg), 0, _invalid_type)))
+#define _ASSIGN_CFG(cfg) (_TRANS_CFG_MARKER(cfg) + (kernel_ulong_t)&(cfg))
+
 #define IWL_PCI_DEVICE(dev, subdev, cfg) \
 	.vendor = PCI_VENDOR_ID_INTEL,  .device = (dev), \
 	.subvendor = PCI_ANY_ID, .subdevice = (subdev), \
-	.driver_data = (kernel_ulong_t)&(cfg)
+	.driver_data = _ASSIGN_CFG(cfg)
 
 /* Hardware specific file defines the PCI IDs table for that hardware module */
 static const struct pci_device_id iwl_hw_card_ids[] = {
@@ -988,19 +998,22 @@ static const struct iwl_dev_info iwl_dev_info_table[] = {
 
 static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-	const struct iwl_cfg_trans_params *trans =
-		(struct iwl_cfg_trans_params *)(ent->driver_data);
+	const struct iwl_cfg_trans_params *trans;
 	const struct iwl_cfg *cfg_7265d __maybe_unused = NULL;
 	struct iwl_trans *iwl_trans;
 	struct iwl_trans_pcie *trans_pcie;
 	int i, ret;
+	const struct iwl_cfg *cfg;
+
+	trans = (void *)(ent->driver_data & ~TRANS_CFG_MARKER);
+
 	/*
 	 * This is needed for backwards compatibility with the old
 	 * tables, so we don't need to change all the config structs
 	 * at the same time.  The cfg is used to compare with the old
 	 * full cfg structs.
 	 */
-	const struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
+	cfg = (void *)(ent->driver_data & ~TRANS_CFG_MARKER);
 
 	/* make sure trans is the first element in iwl_cfg */
 	BUILD_BUG_ON(offsetof(struct iwl_cfg, trans));
@@ -1102,11 +1115,19 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 #endif
 	/*
-	 * If we didn't set the cfg yet, assume the trans is actually
-	 * a full cfg from the old tables.
+	 * If we didn't set the cfg yet, the PCI ID table entry should have
+	 * been a full config - if yes, use it, otherwise fail.
 	 */
-	if (!iwl_trans->cfg)
+	if (!iwl_trans->cfg) {
+		if (ent->driver_data & TRANS_CFG_MARKER) {
+			pr_err("No config found for PCI dev %04x/%04x, rev=0x%x, rfid=0x%x\n",
+			       pdev->device, pdev->subsystem_device,
+			       iwl_trans->hw_rev, iwl_trans->hw_rf_id);
+			ret = -EINVAL;
+			goto out_free_trans;
+		}
 		iwl_trans->cfg = cfg;
+	}
 
 	/* if we don't have a name yet, copy name from the old cfg */
 	if (!iwl_trans->name)
-- 
2.30.2


  parent reply	other threads:[~2021-05-05 16:49 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 16:32 [PATCH AUTOSEL 5.11 001/104] ath11k: fix thermal temperature read Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 002/104] ALSA: usb-audio: Add Pioneer DJM-850 to quirks-table Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 003/104] fs: dlm: fix debugfs dump Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 004/104] fs: dlm: fix mark setting deadlock Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 005/104] fs: dlm: add errno handling to check callback Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 006/104] fs: dlm: add check if dlm is currently running Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 007/104] fs: dlm: change allocation limits Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 008/104] fs: dlm: check on minimum msglen size Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 009/104] fs: dlm: flush swork on shutdown Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 010/104] fs: dlm: add shutdown hook Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 011/104] tipc: convert dest node's address to network order Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 012/104] ASoC: Intel: bytcr_rt5640: Enable jack-detect support on Asus T100TAF Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 013/104] net/mlx5e: Use net_prefetchw instead of prefetchw in MPWQE TX datapath Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 014/104] net: stmmac: Set FIFO sizes for ipq806x Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 015/104] ASoC: rsnd: core: Check convert rate in rsnd_hw_params Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 016/104] Documentation: networking: switchdev: fix command for static FDB entries Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 017/104] Bluetooth: Fix incorrect status handling in LE PHY UPDATE event Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 018/104] i2c: bail out early when RDWR parameters are wrong Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 019/104] ALSA: hdsp: don't disable if not enabled Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 020/104] ALSA: hdspm: " Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 021/104] ALSA: rme9652: " Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 022/104] ALSA: bebob: enable to deliver MIDI messages for multiple ports Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 023/104] Bluetooth: Set CONF_NOT_COMPLETE as l2cap_chan default Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 024/104] Bluetooth: verify AMP hci_chan before amp_destroy Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 025/104] Bluetooth: initialize skb_queue_head at l2cap_chan_create() Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 026/104] net/sched: cls_flower: use ntohs for struct flow_dissector_key_ports Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 027/104] net: bridge: when suppression is enabled exclude RARP packets Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 028/104] Bluetooth: check for zapped sk before connecting Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 029/104] selftests/powerpc: Fix L1D flushing tests for Power10 Sasha Levin
2021-05-05 16:32 ` [PATCH AUTOSEL 5.11 030/104] powerpc/32: Statically initialise first emergency context Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 031/104] net: hns3: remediate a potential overflow risk of bd_num_list Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 032/104] net: hns3: add handling for xmit skb with recursive fraglist Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 033/104] ip6_vti: proper dev_{hold|put} in ndo_[un]init methods Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 034/104] ASoC: Intel: bytcr_rt5640: Add quirk for the Chuwi Hi8 tablet Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 035/104] ice: handle increasing Tx or Rx ring sizes Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 036/104] KVM: arm64: Use BUG and BUG_ON in nVHE hyp Sasha Levin
2021-05-05 16:48   ` Marc Zyngier
2021-05-06  0:14     ` Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 037/104] net: usb: ax88179_178a: initialize local variables before use Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 038/104] Bluetooth: btusb: Enable quirk boolean flag for Mediatek Chip Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 039/104] ASoC: rt5670: Add a quirk for the Dell Venue 10 Pro 5055 Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 040/104] selftests: mptcp: launch mptcp_connect with timeout Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 041/104] i2c: Add I2C_AQ_NO_REP_START adapter quirk Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 042/104] Bluetooth: Do not set cur_adv_instance in adv param MGMT request Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 043/104] MIPS: Loongson64: Use _CACHE_UNCACHED instead of _CACHE_UNCACHED_ACCELERATED Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 044/104] coresight: Do not scan for graph if none is present Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 045/104] IB/hfi1: Correct oversized ring allocation Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 046/104] mac80211: Set priority and queue mapping for injected frames Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 047/104] mac80211: clear the beacon's CRC after channel switch Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 048/104] ASoC: soc-compress: lock pcm_mutex to resolve lockdep error Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 049/104] pinctrl: samsung: use 'int' for register masks in Exynos Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 050/104] rtw88: 8822c: add LC calibration for RTL8822C Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 051/104] mt76: mt7615: fix key set/delete issues Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 052/104] mt76: mt7615: support loading EEPROM for MT7613BE Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 053/104] mt76: mt76x0: disable GTK offloading Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 054/104] mt76: mt7915: always check return value from mt7915_mcu_alloc_wtbl_req Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 055/104] mt76: mt7915: fix key set/delete issue Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 056/104] mt76: mt7915: fix txpower init for TSSI off chips Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 057/104] mt76: mt7915: add wifi subsystem reset Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 058/104] i2c: imx: Fix PM reference leak in i2c_imx_reg_slave() Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 059/104] fuse: invalidate attrs when page writeback completes Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 060/104] virtiofs: fix userns Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 061/104] cuse: prevent clone Sasha Levin
2021-05-05 16:33 ` Sasha Levin [this message]
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 063/104] iwlwifi: queue: avoid memory leak in reset flow Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 064/104] powerpc/mm: Add cond_resched() while removing hpte mappings Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 065/104] ASoC: rsnd: call rsnd_ssi_master_clk_start() from rsnd_ssi_init() Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 066/104] Revert "iommu/amd: Fix performance counter initialization" Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 067/104] iommu/amd: Remove performance counter pre-initialization test Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 068/104] drm/amd/display: Force vsync flip when reconfiguring MPCC Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 069/104] selftests: Set CC to clang in lib.mk if LLVM is set Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 070/104] kconfig: nconf: stop endless search loops Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 071/104] ALSA: hda/realtek: Add quirk for Lenovo Ideapad S740 Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 072/104] ASoC: Intel: sof_sdw: add quirk for new ADL-P Rvp Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 073/104] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 074/104] sctp: Fix out-of-bounds warning in sctp_process_asconf_param() Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 075/104] flow_dissector: Fix out-of-bounds warning in __skb_flow_bpf_to_target() Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 076/104] powerpc/xive: Use the "ibm, chip-id" property only under PowerNV Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 077/104] powerpc/smp: Set numa node before updating mask Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 078/104] wilc1000: Bring MAC address setting in line with typical Linux behavior Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 079/104] mac80211: properly drop the connection in case of invalid CSA IE Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 080/104] ASoC: rt286: Generalize support for ALC3263 codec Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 081/104] ethtool: ioctl: Fix out-of-bounds warning in store_link_ksettings_for_user() Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 082/104] net: sched: tapr: prevent cycle_time == 0 in parse_taprio_schedule Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 083/104] samples/bpf: Fix broken tracex1 due to kprobe argument change Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 084/104] powerpc/pseries: Stop calling printk in rtas_stop_self() Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 085/104] drm/amd/display: fixed divide by zero kernel crash during dsc enablement Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 086/104] drm/amd/display: add handling for hdcp2 rx id list validation Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 087/104] drm/amdgpu: Add mem sync flag for IB allocated by SA Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 088/104] mt76: mt7615: fix entering driver-own state on mt7663 Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 089/104] crypto: ccp: Free SEV device if SEV init fails Sasha Levin
2021-05-05 16:33 ` [PATCH AUTOSEL 5.11 090/104] wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 091/104] wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 092/104] qtnfmac: Fix possible buffer overflow in qtnf_event_handle_external_auth Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 093/104] powerpc/iommu: Annotate nested lock for lockdep Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 094/104] iavf: remove duplicate free resources calls Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 095/104] net: ethernet: mtk_eth_soc: fix RX VLAN offload Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 096/104] selftests: mlxsw: Increase the tolerance of backlog buildup Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 097/104] selftests: mlxsw: Fix mausezahn invocation in ERSPAN scale test Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 098/104] kbuild: generate Module.symvers only when vmlinux exists Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 099/104] bnxt_en: Add PCI IDs for Hyper-V VF devices Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 100/104] ia64: module: fix symbolizer crash on fdescr Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 101/104] watchdog: rename __touch_watchdog() to a better descriptive name Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 102/104] watchdog: explicitly update timestamp when reporting softlockup Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 103/104] watchdog/softlockup: remove logic that tried to prevent repeated reports Sasha Levin
2021-05-05 16:34 ` [PATCH AUTOSEL 5.11 104/104] watchdog: fix barriers when printing backtraces from all CPUs Sasha Levin

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=20210505163413.3461611-62-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=johannes.berg@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    --cc=netdev@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).