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: Harshvardhan Jha <harshvardhan.jha@oracle.com>,
	Sumit Saxena <sumit.saxena@broadcom.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.14 42/64] scsi: megaraid_mm: Fix end of loop tests for list_for_each_entry()
Date: Tue, 24 Aug 2021 13:04:35 -0400	[thread overview]
Message-ID: <20210824170457.710623-43-sashal@kernel.org> (raw)
In-Reply-To: <20210824170457.710623-1-sashal@kernel.org>

From: Harshvardhan Jha <harshvardhan.jha@oracle.com>

[ Upstream commit 77541f78eadfe9fdb018a7b8b69f0f2af2cf4b82 ]

The list_for_each_entry() iterator, "adapter" in this code, can never be
NULL.  If we exit the loop without finding the correct adapter then
"adapter" points invalid memory that is an offset from the list head.  This
will eventually lead to memory corruption and presumably a kernel crash.

Link: https://lore.kernel.org/r/20210708074642.23599-1-harshvardhan.jha@oracle.com
Acked-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Harshvardhan Jha <harshvardhan.jha@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/scsi/megaraid/megaraid_mm.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index 65b6f6ace3a5..8ec308c5970f 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -250,7 +250,7 @@ mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
 	mimd_t		mimd;
 	uint32_t	adapno;
 	int		iterator;
-
+	bool		is_found;
 
 	if (copy_from_user(&mimd, umimd, sizeof(mimd_t))) {
 		*rval = -EFAULT;
@@ -266,12 +266,16 @@ mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
 
 	adapter = NULL;
 	iterator = 0;
+	is_found = false;
 
 	list_for_each_entry(adapter, &adapters_list_g, list) {
-		if (iterator++ == adapno) break;
+		if (iterator++ == adapno) {
+			is_found = true;
+			break;
+		}
 	}
 
-	if (!adapter) {
+	if (!is_found) {
 		*rval = -ENODEV;
 		return NULL;
 	}
@@ -739,6 +743,7 @@ ioctl_done(uioc_t *kioc)
 	uint32_t	adapno;
 	int		iterator;
 	mraid_mmadp_t*	adapter;
+	bool		is_found;
 
 	/*
 	 * When the kioc returns from driver, make sure it still doesn't
@@ -761,19 +766,23 @@ ioctl_done(uioc_t *kioc)
 		iterator	= 0;
 		adapter		= NULL;
 		adapno		= kioc->adapno;
+		is_found	= false;
 
 		con_log(CL_ANN, ( KERN_WARNING "megaraid cmm: completed "
 					"ioctl that was timedout before\n"));
 
 		list_for_each_entry(adapter, &adapters_list_g, list) {
-			if (iterator++ == adapno) break;
+			if (iterator++ == adapno) {
+				is_found = true;
+				break;
+			}
 		}
 
 		kioc->timedout = 0;
 
-		if (adapter) {
+		if (is_found)
 			mraid_mm_dealloc_kioc( adapter, kioc );
-		}
+
 	}
 	else {
 		wake_up(&wait_q);
-- 
2.30.2


  parent reply	other threads:[~2021-08-24 17:32 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 17:03 [PATCH 4.14 00/64] 4.14.245-rc1 review Sasha Levin
2021-08-24 17:03 ` [PATCH 4.14 01/64] iio: humidity: hdc100x: Add margin to the conversion time Sasha Levin
2021-08-24 17:03 ` [PATCH 4.14 02/64] iio: adc: Fix incorrect exit of for-loop Sasha Levin
2021-08-24 17:03 ` [PATCH 4.14 03/64] ASoC: intel: atom: Fix reference to PCM buffer address Sasha Levin
2021-08-24 17:03 ` [PATCH 4.14 04/64] i2c: dev: zero out array used for i2c reads from userspace Sasha Levin
2021-08-24 17:03 ` [PATCH 4.14 05/64] ACPI: NFIT: Fix support for virtual SPA ranges Sasha Levin
2021-08-24 17:03 ` [PATCH 4.14 06/64] ASoC: cs42l42: Correct definition of ADC Volume control Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 07/64] ASoC: cs42l42: Don't allow SND_SOC_DAIFMT_LEFT_J Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 08/64] ASoC: cs42l42: Fix inversion of ADC Notch Switch control Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 09/64] ASoC: cs42l42: Remove duplicate control for WNF filter frequency Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 10/64] net: dsa: mt7530: add the missing RxUnicast MIB counter Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 11/64] ppp: Fix generating ifname when empty IFLA_IFNAME is specified Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 12/64] psample: Add a fwd declaration for skbuff Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 13/64] net: Fix memory leak in ieee802154_raw_deliver Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 14/64] net: bridge: fix memleak in br_add_if() Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 15/64] tcp_bbr: fix u32 wrap bug in round logic if bbr_init() called after 2B packets Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 16/64] xen/events: Fix race in set_evtchn_to_irq Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 17/64] vsock/virtio: avoid potential deadlock when vsock device remove Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 18/64] powerpc/kprobes: Fix kprobe Oops happens in booke Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 19/64] x86/tools: Fix objdump version check again Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 20/64] x86/resctrl: Fix default monitoring groups reporting Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 21/64] PCI/MSI: Enable and mask MSI-X early Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 22/64] PCI/MSI: Do not set invalid bits in MSI mask Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 23/64] PCI/MSI: Correct misleading comments Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 24/64] PCI/MSI: Use msi_mask_irq() in pci_msi_shutdown() Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 25/64] PCI/MSI: Protect msi_desc::masked for multi-MSI Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 26/64] PCI/MSI: Mask all unused MSI-X entries Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 27/64] PCI/MSI: Enforce that MSI-X table entry is masked for update Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 28/64] PCI/MSI: Enforce MSI[X] entry updates to be visible Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 29/64] vmlinux.lds.h: Handle clang's module.{c,d}tor sections Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 30/64] mac80211: drop data frames without key on encrypted links Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 31/64] KVM: nSVM: always intercept VMLOAD/VMSAVE when nested (CVE-2021-3656) Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 32/64] KVM: nSVM: avoid picking up unsupported bits from L2 in int_ctl (CVE-2021-3653) Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 33/64] x86/fpu: Make init_fpstate correct with optimized XSAVE Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 34/64] ath: Use safer key clearing with key cache entries Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 35/64] ath9k: Clear key cache explicitly on disabling hardware Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 36/64] ath: Export ath_hw_keysetmac() Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 37/64] ath: Modify ath_key_delete() to not need full key entry Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 38/64] ath9k: Postpone key cache entry deletion for TXQ frames reference it Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 39/64] dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe() Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 40/64] ARM: dts: am43x-epos-evm: Reduce i2c0 bus speed for tps65218 Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 41/64] dmaengine: of-dma: router_xlate to return -EPROBE_DEFER if controller is not yet available Sasha Levin
2021-08-24 17:04 ` Sasha Levin [this message]
2021-08-24 17:04 ` [PATCH 4.14 43/64] scsi: scsi_dh_rdac: Avoid crash during rdac_bus_attach() Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 44/64] scsi: core: Avoid printing an error if target_alloc() returns -ENXIO Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 45/64] ARM: dts: nomadik: Fix up interrupt controller node names Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 46/64] net: usb: lan78xx: don't modify phy_device state concurrently Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 47/64] Bluetooth: hidp: use correct wait queue when removing ctrl_wait Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 48/64] dccp: add do-while-0 stubs for dccp_pr_debug macros Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 49/64] vhost: Fix the calculation in vhost_overflow() Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 50/64] bnxt: don't lock the tx queue from napi poll Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 51/64] net: 6pack: fix slab-out-of-bounds in decode_data Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 52/64] ptp_pch: Restore dependency on PCI Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 53/64] net: qlcnic: add missed unlock in qlcnic_83xx_flash_read32 Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 54/64] net: mdio-mux: Don't ignore memory allocation errors Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 55/64] net: mdio-mux: Handle -EPROBE_DEFER correctly Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 56/64] mmc: dw_mmc: Fix hang on data CRC error Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 57/64] ALSA: hda - fix the 'Capture Switch' value change notifications Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 58/64] ipack: tpci200: fix many double free issues in tpci200_pci_probe Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 59/64] btrfs: prevent rename2 from exchanging a subvol with a directory from different parents Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 60/64] ASoC: intel: atom: Fix breakage for PCM buffer address setup Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 61/64] locks: print a warning when mount fails due to lack of "mand" support Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 62/64] fs: warn about impending deprecation of mandatory locks Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 63/64] netfilter: nft_exthdr: fix endianness of tcp option cast Sasha Levin
2021-08-24 17:04 ` [PATCH 4.14 64/64] Linux 4.14.245-rc1 Sasha Levin
2021-08-25 20:26 ` [PATCH 4.14 00/64] 4.14.245-rc1 review Guenter Roeck
2021-08-25 21:04 ` Daniel Díaz
2021-08-26  1:01 ` Samuel Zou

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=20210824170457.710623-43-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=harshvardhan.jha@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=sumit.saxena@broadcom.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).