All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Justin Tee <justin.tee@broadcom.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	james.smart@broadcom.com, dick.kennedy@broadcom.com,
	jejb@linux.ibm.com, linux-scsi@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 13/58] scsi: lpfc: Fix use-after-free KFENCE violation during sysfs firmware write
Date: Sun, 26 Feb 2023 21:04:11 -0500	[thread overview]
Message-ID: <20230227020457.1048737-13-sashal@kernel.org> (raw)
In-Reply-To: <20230227020457.1048737-1-sashal@kernel.org>

From: Justin Tee <justin.tee@broadcom.com>

[ Upstream commit 21681b81b9ae548c5dae7ae00d931197a27f480c ]

During the sysfs firmware write process, a use-after-free read warning is
logged from the lpfc_wr_object() routine:

  BUG: KFENCE: use-after-free read in lpfc_wr_object+0x235/0x310 [lpfc]
  Use-after-free read at 0x0000000000cf164d (in kfence-#111):
  lpfc_wr_object+0x235/0x310 [lpfc]
  lpfc_write_firmware.cold+0x206/0x30d [lpfc]
  lpfc_sli4_request_firmware_update+0xa6/0x100 [lpfc]
  lpfc_request_firmware_upgrade_store+0x66/0xb0 [lpfc]
  kernfs_fop_write_iter+0x121/0x1b0
  new_sync_write+0x11c/0x1b0
  vfs_write+0x1ef/0x280
  ksys_write+0x5f/0xe0
  do_syscall_64+0x59/0x90
  entry_SYSCALL_64_after_hwframe+0x63/0xcd

The driver accessed wr_object pointer data, which was initialized into
mailbox payload memory, after the mailbox object was released back to the
mailbox pool.

Fix by moving the mailbox free calls to the end of the routine ensuring
that we don't reference internal mailbox memory after release.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/scsi/lpfc/lpfc_sli.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 21c52154626f1..b93c948c4fcc4 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -20802,6 +20802,7 @@ lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
 	struct lpfc_mbx_wr_object *wr_object;
 	LPFC_MBOXQ_t *mbox;
 	int rc = 0, i = 0;
+	int mbox_status = 0;
 	uint32_t shdr_status, shdr_add_status, shdr_add_status_2;
 	uint32_t shdr_change_status = 0, shdr_csf = 0;
 	uint32_t mbox_tmo;
@@ -20847,11 +20848,15 @@ lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
 	wr_object->u.request.bde_count = i;
 	bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
 	if (!phba->sli4_hba.intr_enable)
-		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
+		mbox_status = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
 	else {
 		mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
-		rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
+		mbox_status = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
 	}
+
+	/* The mbox status needs to be maintained to detect MBOX_TIMEOUT. */
+	rc = mbox_status;
+
 	/* The IOCTL status is embedded in the mailbox subheader. */
 	shdr_status = bf_get(lpfc_mbox_hdr_status,
 			     &wr_object->header.cfg_shdr.response);
@@ -20866,10 +20871,6 @@ lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
 				  &wr_object->u.response);
 	}
 
-	if (!phba->sli4_hba.intr_enable)
-		mempool_free(mbox, phba->mbox_mem_pool);
-	else if (rc != MBX_TIMEOUT)
-		mempool_free(mbox, phba->mbox_mem_pool);
 	if (shdr_status || shdr_add_status || shdr_add_status_2 || rc) {
 		lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
 				"3025 Write Object mailbox failed with "
@@ -20887,6 +20888,12 @@ lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
 		lpfc_log_fw_write_cmpl(phba, shdr_status, shdr_add_status,
 				       shdr_add_status_2, shdr_change_status,
 				       shdr_csf);
+
+	if (!phba->sli4_hba.intr_enable)
+		mempool_free(mbox, phba->mbox_mem_pool);
+	else if (mbox_status != MBX_TIMEOUT)
+		mempool_free(mbox, phba->mbox_mem_pool);
+
 	return rc;
 }
 
-- 
2.39.0


  parent reply	other threads:[~2023-02-27  2:08 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27  2:03 [PATCH AUTOSEL 6.1 01/58] drm: panel-orientation-quirks: Add quirk for Lenovo Yoga Tab 3 X90F Sasha Levin
2023-02-27  2:03 ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 02/58] drm: panel-orientation-quirks: Add quirk for DynaBook K50 Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 03/58] drm/amd/display: Reduce expected sdp bandwidth for dcn321 Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 04/58] drm/amd/display: Revert Reduce delay when sink device not able to ACK 00340h write Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 05/58] drm/amd/display: Fix potential null-deref in dm_resume Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 06/58] drm/omap: dsi: Fix excessive stack usage Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 07/58] HID: Add Mapping for System Microphone Mute Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 08/58] drm/tiny: ili9486: Do not assume 8-bit only SPI controllers Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 09/58] drm/amd/display: Defer DIG FIFO disable after VID stream enable Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 10/58] drm/radeon: free iio for atombios when driver shutdown Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 11/58] drm/amd: Avoid BUG() for case of SRIOV missing IP version Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 12/58] drm/amdkfd: Page aligned memory reserve size Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` Sasha Levin [this message]
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 14/58] Revert "fbcon: don't lose the console font across generic->chip driver switch" Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 15/58] drm/amd: Avoid ASSERT for some message failures Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 16/58] drm: amd: display: Fix memory leakage Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 17/58] drm/amd/display: fix mapping to non-allocated address Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 18/58] drm/msm/dp: Remove INIT_SETUP delay Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  9:12   ` Johan Hovold
2023-02-27  9:12     ` Johan Hovold
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 19/58] HID: uclogic: Add frame type quirk Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 20/58] HID: uclogic: Add battery quirk Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 21/58] HID: uclogic: Add support for XP-PEN Deco Pro SW Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 22/58] HID: uclogic: Add support for XP-PEN Deco Pro MW Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 23/58] HID: multitouch: Add quirks for flipped axes Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 24/58] drm/msm/dsi: Add missing check for alloc_ordered_workqueue Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 25/58] drm: rcar-du: Add quirk for H3 ES1.x pclk workaround Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 26/58] drm: rcar-du: Fix setting a reserved bit in DPLLCR Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 27/58] drm/drm_print: correct format problem Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 28/58] drm/amd/display: Set hvm_enabled flag for S/G mode Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 29/58] habanalabs: extend fatal messages to contain PCI info Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 30/58] habanalabs: fix bug in timestamps registration code Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 31/58] docs/scripts/gdb: add necessary make scripts_gdb step Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 32/58] drm/msm/dpu: Add DSC hardware blocks to register snapshot Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 33/58] ASoC: soc-compress: Reposition and add pcm_mutex Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 34/58] ASoC: kirkwood: Iterate over array indexes instead of using pointer math Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 35/58] regulator: max77802: Bounds check regulator id against opmode Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 36/58] regulator: s5m8767: Bounds check id indexing into arrays Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 37/58] Revert "drm/amdgpu: TA unload messages are not actually sent to psp when amdgpu is uninstalled" Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 38/58] drm/amd/display: fix FCLK pstate change underflow Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 39/58] gfs2: Improve gfs2_make_fs_rw error handling Sasha Levin
2023-02-27  2:04   ` [Cluster-devel] " Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 40/58] hwmon: (coretemp) Simplify platform device handling Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 41/58] hwmon: (nct6775) Directly call ASUS ACPI WMI method Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 42/58] hwmon: (nct6775) B650/B660/X670 ASUS boards support Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 43/58] pinctrl: at91: use devm_kasprintf() to avoid potential leaks Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 44/58] drm/amd/display: Do not set DRR on pipe commit Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 45/58] drm/amd/display: Do not commit pipe when updating DRR Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 46/58] scsi: snic: Fix memory leak with using debugfs_lookup() Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 47/58] scsi: ufs: core: Fix device management cmd timeout flow Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 48/58] HID: logitech-hidpp: Don't restart communication if not necessary Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 49/58] drm/amd/display: Move DCN314 DOMAIN power control to DMCUB Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 50/58] drm/amd/display: Enable P-state validation checks for DCN314 Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 51/58] drm: panel-orientation-quirks: Add quirk for Lenovo IdeaPad Duet 3 10IGL5 Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 52/58] drm/amd/display: Disable HUBP/DPP PG on DCN314 for now Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [dm-devel] [PATCH AUTOSEL 6.1 53/58] dm thin: add cond_resched() to various workqueue loops Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [dm-devel] [PATCH AUTOSEL 6.1 54/58] dm cache: " Sasha Levin
2023-02-27  2:04   ` Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 55/58] nfsd: zero out pointers after putting nfsd_files on COPY setup error Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 56/58] nfsd: clean up potential nfsd_file refcount leaks in COPY codepath Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 57/58] nfsd: don't hand out delegation on setuid files being opened for write Sasha Levin
2023-02-27  2:04 ` [PATCH AUTOSEL 6.1 58/58] cifs: prevent data race in smb2_reconnect() 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=20230227020457.1048737-13-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dick.kennedy@broadcom.com \
    --cc=james.smart@broadcom.com \
    --cc=jejb@linux.ibm.com \
    --cc=justin.tee@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.