stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "stable@vger.kernel.org" <stable@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Kees Cook <keescook@chromium.org>,
	Daniel Micay <danielmicay@gmail.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Sasha Levin <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL for 3.18 019/101] scsi: csiostor: Avoid content leaks and casts
Date: Mon, 9 Apr 2018 00:35:25 +0000	[thread overview]
Message-ID: <20180409003505.164715-19-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180409003505.164715-1-alexander.levin@microsoft.com>

From: Kees Cook <keescook@chromium.org>

[ Upstream commit 42c335f7e67029d2e01711f2f2bc6252277c8993 ]

When copying attributes, the len argument was padded out and the
resulting memcpy() would copy beyond the end of the source buffer.
Avoid this, and use size_t for val_len to avoid all the casts.
Similarly, avoid source buffer casts and use void *.

Additionally enforces val_len can be represented by u16 and that the DMA
buffer was not overflowed. Fixes the size of mfa, which is not
FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN (but it will be padded up to 4). This
was noticed by the future CONFIG_FORTIFY_SOURCE checks.

Cc: Daniel Micay <danielmicay@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Varun Prakash <varun@chelsio.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
---
 drivers/scsi/csiostor/csio_lnode.c | 43 +++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
index ffe9be04dc39..1ffd67b749b1 100644
--- a/drivers/scsi/csiostor/csio_lnode.c
+++ b/drivers/scsi/csiostor/csio_lnode.c
@@ -238,14 +238,23 @@ csio_osname(uint8_t *buf, size_t buf_len)
 }
 
 static inline void
-csio_append_attrib(uint8_t **ptr, uint16_t type, uint8_t *val, uint16_t len)
+csio_append_attrib(uint8_t **ptr, uint16_t type, void *val, size_t val_len)
 {
+	uint16_t len;
 	struct fc_fdmi_attr_entry *ae = (struct fc_fdmi_attr_entry *)*ptr;
+
+	if (WARN_ON(val_len > U16_MAX))
+		return;
+
+	len = val_len;
+
 	ae->type = htons(type);
 	len += 4;		/* includes attribute type and length */
 	len = (len + 3) & ~3;	/* should be multiple of 4 bytes */
 	ae->len = htons(len);
-	memcpy(ae->value, val, len);
+	memcpy(ae->value, val, val_len);
+	if (len > val_len)
+		memset(ae->value + val_len, 0, len - val_len);
 	*ptr += len;
 }
 
@@ -335,7 +344,7 @@ csio_ln_fdmi_rhba_cbfn(struct csio_hw *hw, struct csio_ioreq *fdmi_req)
 	numattrs++;
 	val = htonl(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
 	csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_SUPPORTEDSPEED,
-			   (uint8_t *)&val,
+			   &val,
 			   FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN);
 	numattrs++;
 
@@ -346,23 +355,22 @@ csio_ln_fdmi_rhba_cbfn(struct csio_hw *hw, struct csio_ioreq *fdmi_req)
 	else
 		val = htonl(CSIO_HBA_PORTSPEED_UNKNOWN);
 	csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED,
-			   (uint8_t *)&val,
-			   FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN);
+			   &val, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN);
 	numattrs++;
 
 	mfs = ln->ln_sparm.csp.sp_bb_data;
 	csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_MAXFRAMESIZE,
-			   (uint8_t *)&mfs, FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN);
+			   &mfs, sizeof(mfs));
 	numattrs++;
 
 	strcpy(buf, "csiostor");
 	csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_OSDEVICENAME, buf,
-			   (uint16_t)strlen(buf));
+			   strlen(buf));
 	numattrs++;
 
 	if (!csio_hostname(buf, sizeof(buf))) {
 		csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_HOSTNAME,
-				   buf, (uint16_t)strlen(buf));
+				   buf, strlen(buf));
 		numattrs++;
 	}
 	attrib_blk->numattrs = htonl(numattrs);
@@ -444,33 +452,32 @@ csio_ln_fdmi_dprt_cbfn(struct csio_hw *hw, struct csio_ioreq *fdmi_req)
 
 	strcpy(buf, "Chelsio Communications");
 	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MANUFACTURER, buf,
-			   (uint16_t)strlen(buf));
+			   strlen(buf));
 	numattrs++;
 	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_SERIALNUMBER,
-			   hw->vpd.sn, (uint16_t)sizeof(hw->vpd.sn));
+			   hw->vpd.sn, sizeof(hw->vpd.sn));
 	numattrs++;
 	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MODEL, hw->vpd.id,
-			   (uint16_t)sizeof(hw->vpd.id));
+			   sizeof(hw->vpd.id));
 	numattrs++;
 	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MODELDESCRIPTION,
-			   hw->model_desc, (uint16_t)strlen(hw->model_desc));
+			   hw->model_desc, strlen(hw->model_desc));
 	numattrs++;
 	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_HARDWAREVERSION,
-			   hw->hw_ver, (uint16_t)sizeof(hw->hw_ver));
+			   hw->hw_ver, sizeof(hw->hw_ver));
 	numattrs++;
 	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_FIRMWAREVERSION,
-			   hw->fwrev_str, (uint16_t)strlen(hw->fwrev_str));
+			   hw->fwrev_str, strlen(hw->fwrev_str));
 	numattrs++;
 
 	if (!csio_osname(buf, sizeof(buf))) {
 		csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_OSNAMEVERSION,
-				   buf, (uint16_t)strlen(buf));
+				   buf, strlen(buf));
 		numattrs++;
 	}
 
 	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD,
-			   (uint8_t *)&maxpayload,
-			   FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
+			   &maxpayload, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
 	len = (uint32_t)(pld - (uint8_t *)cmd);
 	numattrs++;
 	attrib_blk->numattrs = htonl(numattrs);
@@ -1794,6 +1801,8 @@ csio_ln_mgmt_submit_req(struct csio_ioreq *io_req,
 	struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
 	int rv;
 
+	BUG_ON(pld_len > pld->len);
+
 	io_req->io_cbfn = io_cbfn;	/* Upper layer callback handler */
 	io_req->fw_handle = (uintptr_t) (io_req);
 	io_req->eq_idx = mgmtm->eq_idx;
-- 
2.15.1

  parent reply	other threads:[~2018-04-09  0:39 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09  0:35 [PATCH AUTOSEL for 3.18 001/101] ALSA: timer: Wrap with spinlock for queue access Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 002/101] e1000e: Undo e1000e_pm_freeze if __e1000_shutdown fails Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 003/101] perf/core: Correct event creation with PERF_FORMAT_GROUP Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 004/101] MIPS: mm: fixed mappings: correct initialisation Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 005/101] MIPS: kprobes: flush_insn_slot should flush only if probe initialised Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 006/101] net: emac: fix reset timeout with AR8035 phy Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 007/101] perf tests: Decompress kernel module before objdump Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 008/101] xen: avoid type warning in xchg_xen_ulong Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 009/101] KEYS: put keyring if install_session_keyring_to_cred() fails Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 010/101] bnx2x: Allow vfs to disable txvlan offload Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 011/101] sctp: fix recursive locking warning in sctp_do_peeloff Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 012/101] sparc64: ldc abort during vds iso boot Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 013/101] iio: magnetometer: st_magn_spi: fix spi_device_id table Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 014/101] Bluetooth: Send HCI Set Event Mask Page 2 command only when needed Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 015/101] ACPICA: Events: Add runtime stub support for event APIs Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 016/101] ACPICA: Disassembler: Abort on an invalid/unknown AML opcode Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 017/101] s390/dasd: Display read-only attribute correctly Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 018/101] vxlan: dont migrate permanent fdb entries during learn Sasha Levin
2018-04-09  0:35 ` Sasha Levin [this message]
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 020/101] scsi: megaraid: Fix a sleep-in-atomic bug Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 021/101] scsi: lpfc: Fix return value of board_mode store routine in case of online failure Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 022/101] usb: usbip tool: Check the return of get_nports() Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 023/101] usb: usbip tool: Fix refresh_imported_device_list() Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 024/101] PCI: Correct PCI_STD_RESOURCE_END usage Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 025/101] PCI: Add domain number check to find_smbios_instance_string() Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 026/101] mtd: handle partitioning on devices with 0 erasesize Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 027/101] platform/x86: acer-wmi: Detect RF Button capability Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 028/101] caif: Add sockaddr length check before accessing sa_family in connect handler Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 029/101] ixgbe: avoid permanent lock of *_PTP_TX_IN_PROGRESS Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 030/101] net_sched: move tcf_lock down after gen_replace_estimator() Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 031/101] PCI: Protect pci_error_handlers->reset_notify() usage with device_lock() Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 032/101] firmware: dmi_scan: Check DMI structure length Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 033/101] i2c: ismt: fix wrong device address when unmap the data buffer Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 034/101] drm/mgag200: Fix to always set HiPri for G200e4 V2 Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 035/101] r8152: add byte_enable for ocp_read_word function Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 036/101] Btrfs: skip commit transaction if we don't have enough pinned bytes Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 037/101] scsi: lpfc: Fix crash after firmware flash when IO is running Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 038/101] mmc: sdhci-esdhc: Add SDHCI_QUIRK_32BIT_DMA_ADDR Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 039/101] x86/nmi: Fix timeout test in test_nmi_ipi() Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 040/101] arm64: pass machine size to sparse Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 041/101] fib_rules: Resolve goto rules target on delete Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 042/101] dccp: call inet_add_protocol after register_pernet_subsys in dccp_v4_init Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 043/101] arm64: ptrace: Fix VFP register dumping in compat coredumps Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 044/101] veth: Be more robust on network device creation when no attributes Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 045/101] macvlan: Do not return error when setting the same mac address Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 046/101] sctp: adjust ssthresh when transport is idle Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 047/101] arm64: pass endianness info to sparse Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 048/101] scsi: bnx2i: missing error code in bnx2i_ep_connect() Sasha Levin
2018-04-09  0:35 ` [PATCH AUTOSEL for 3.18 049/101] powerpc: Fix /proc/cpuinfo revision for POWER9 DD2 Sasha Levin
2018-04-09  0:36 ` [PATCH AUTOSEL for 3.18 050/101] ACPI: EC: Fix EC command visibility for dynamic debug Sasha Levin
2018-04-09  0:36 ` [PATCH AUTOSEL for 3.18 051/101] scsi: sun_esp: fix device reference leaks Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 052/101] powerpc/fadump: avoid duplicates in crash memory ranges 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=20180409003505.164715-19-alexander.levin@microsoft.com \
    --to=alexander.levin@microsoft.com \
    --cc=danielmicay@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@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 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).