Skip to contentSkip to conversation

xilinx: fru: Small update and fixes

PATCH New Michal Simek 2 participants 5 messages Nov 10, 2020 – Nov 20, 2020 Arm/Zynq architecture

lore
Share & tools
lore
#0 lore raw

cover xilinx: fru: Small update and fixes

Hi,

I am sending 3 more patches for fru code. Especially the second patch is important because it ensures that data in .data section is not overwritten based on parsed structures.

Thanks,
Michal

Michal Simek (3):
fru: common: Switch capture variable with the rest
fru: ops: Do not let parser to write data to not allocated space
fru: common: Record pcie/uuid fields in custom board area

 board/xilinx/common/fru.h     |  6 +++++-
 board/xilinx/common/fru_ops.c | 10 ++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/3 fru: common: Switch capture variable with the rest

capture variable is bool which is just one byte and it is just causing unaligned accesses. Better to have it as last entry in the structure.

It also simplify offset calculation for initial header copy.

---

 board/xilinx/common/fru.h     | 2 +-
 board/xilinx/common/fru_ops.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
board/xilinx/common/fru.h +1 -1
index a3e652025714..e85dde45314f 100644
@@ -53,9 +53,9 @@ struct fru_board_data {
 };
 
 struct fru_table {
-	bool captured;
 	struct fru_common_hdr hdr;
 	struct fru_board_data brd;
+	bool captured;
 };
 
 #define FRU_TYPELEN_CODE_MASK	0xC0
board/xilinx/common/fru_ops.c +1 -1
index fc3add7d93da..affcb121aa9c 100644
@@ -217,7 +217,7 @@ int fru_capture(unsigned long addr)
 
 	hdr = (struct fru_common_hdr *)addr;
 
-	memcpy((void *)&fru_data.hdr, (void *)hdr,
+	memcpy((void *)&fru_data, (void *)hdr,
 	       sizeof(struct fru_common_hdr));
 
 	fru_data.captured = true;
Signature · 1 line
2.29.2
#2 lore raw

PATCH 2/3 fru: ops: Do not let parser to write data to not allocated space

In reply to Michal Simek

If customs fields in board area are used it will likely go over allocated space in struct fru_board_data. That's why calculate limit of this structure to make sure that different data is not rewritten by accident. When limit is reached stop to record fields.

---

 board/xilinx/common/fru_ops.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
board/xilinx/common/fru_ops.c +7 -1
index affcb121aa9c..b4cd3d499885 100644
@@ -163,12 +163,15 @@ static int fru_parse_board(unsigned long addr)
 {
 	u8 i, type;
 	int len;
-	u8 *data, *term;
+	u8 *data, *term, *limit;
 
 	memcpy(&fru_data.brd.ver, (void *)addr, 6);
 	addr += 6;
 	data = (u8 *)&fru_data.brd.manufacturer_type_len;
 
+	/* Record max structure limit not to write data over allocated space */
+	limit = data + sizeof(struct fru_board_data);
+
 	for (i = 0; ; i++, data += FRU_BOARD_MAX_LEN) {
 		len = fru_check_type_len(*(u8 *)addr, fru_data.brd.lang_code,
 					 &type);
@@ -178,6 +181,9 @@ static int fru_parse_board(unsigned long addr)
 		if (len == -EINVAL)
 			break;
 
+		/* Stop when amount of chars is more then fields to record */
+		if (data + len > limit)
+			break;
 		/* This record type/len field */
 		*data++ = *(u8 *)addr;
 
Signature · 1 line
2.29.2
#3 lore raw

PATCH 3/3 fru: common: Record pcie/uuid fields in custom board area

In reply to Michal Simek

Add additional fields. They will be just recorded and filled but not shown.

---

 board/xilinx/common/fru.h | 4 ++++
 1 file changed, 4 insertions(+)
board/xilinx/common/fru.h +4 -0
index e85dde45314f..e7284709ddea 100644
@@ -50,6 +50,10 @@ struct fru_board_data {
 	/* Xilinx custom fields */
 	u8 rev_type_len;
 	u8 rev[FRU_BOARD_MAX_LEN];
+	u8 pcie_type_len;
+	u8 pcie[FRU_BOARD_MAX_LEN];
+	u8 uuid_type_len;
+	u8 uuid[FRU_BOARD_MAX_LEN];
 };
 
 struct fru_table {
Signature · 1 line
2.29.2
#4 lore raw

cover xilinx: fru: Small update and fixes

In reply to Michal Simek

?t 10. 11. 2020 v 13:21 odes?latel Michal Simek
<[email protected]> napsal:

Quoted 16 lines

Hi,

I am sending 3 more patches for fru code. Especially the second patch is important because it ensures that data in .data section is not overwritten based on parsed structures.

Thanks,
Michal

Michal Simek (3):
fru: common: Switch capture variable with the rest
fru: ops: Do not let parser to write data to not allocated space
fru: common: Record pcie/uuid fields in custom board area

Quoted 7 lines
 board/xilinx/common/fru.h     |  6 +++++-
 board/xilinx/common/fru_ops.c | 10 ++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

--
2.29.2

Applied all.
M

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs