All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] xilinx: fru: Small update and fixes
@ 2020-11-10 12:21 Michal Simek
  2020-11-10 12:21 ` [PATCH 1/3] fru: common: Switch capture variable with the rest Michal Simek
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michal Simek @ 2020-11-10 12:21 UTC (permalink / raw)
  To: u-boot

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(-)

-- 
2.29.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] fru: common: Switch capture variable with the rest
  2020-11-10 12:21 [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek
@ 2020-11-10 12:21 ` Michal Simek
  2020-11-10 12:21 ` [PATCH 2/3] fru: ops: Do not let parser to write data to not allocated space Michal Simek
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2020-11-10 12:21 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 board/xilinx/common/fru.h     | 2 +-
 board/xilinx/common/fru_ops.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/board/xilinx/common/fru.h b/board/xilinx/common/fru.h
index a3e652025714..e85dde45314f 100644
--- a/board/xilinx/common/fru.h
+++ b/board/xilinx/common/fru.h
@@ -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
diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c
index fc3add7d93da..affcb121aa9c 100644
--- a/board/xilinx/common/fru_ops.c
+++ b/board/xilinx/common/fru_ops.c
@@ -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;
-- 
2.29.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] fru: ops: Do not let parser to write data to not allocated space
  2020-11-10 12:21 [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek
  2020-11-10 12:21 ` [PATCH 1/3] fru: common: Switch capture variable with the rest Michal Simek
@ 2020-11-10 12:21 ` Michal Simek
  2020-11-10 12:21 ` [PATCH 3/3] fru: common: Record pcie/uuid fields in custom board area Michal Simek
  2020-11-20  9:49 ` [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek
  3 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2020-11-10 12:21 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 board/xilinx/common/fru_ops.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c
index affcb121aa9c..b4cd3d499885 100644
--- a/board/xilinx/common/fru_ops.c
+++ b/board/xilinx/common/fru_ops.c
@@ -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;
 
-- 
2.29.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] fru: common: Record pcie/uuid fields in custom board area
  2020-11-10 12:21 [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek
  2020-11-10 12:21 ` [PATCH 1/3] fru: common: Switch capture variable with the rest Michal Simek
  2020-11-10 12:21 ` [PATCH 2/3] fru: ops: Do not let parser to write data to not allocated space Michal Simek
@ 2020-11-10 12:21 ` Michal Simek
  2020-11-20  9:49 ` [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek
  3 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2020-11-10 12:21 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 board/xilinx/common/fru.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/board/xilinx/common/fru.h b/board/xilinx/common/fru.h
index e85dde45314f..e7284709ddea 100644
--- a/board/xilinx/common/fru.h
+++ b/board/xilinx/common/fru.h
@@ -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 {
-- 
2.29.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 0/3] xilinx: fru: Small update and fixes
  2020-11-10 12:21 [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek
                   ` (2 preceding siblings ...)
  2020-11-10 12:21 ` [PATCH 3/3] fru: common: Record pcie/uuid fields in custom board area Michal Simek
@ 2020-11-20  9:49 ` Michal Simek
  3 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2020-11-20  9:49 UTC (permalink / raw)
  To: u-boot

?t 10. 11. 2020 v 13:21 odes?latel Michal Simek
<michal.simek@xilinx.com> napsal:
>
> 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(-)
>
> --
> 2.29.2
>

Applied all.
M

-- 
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-20  9:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10 12:21 [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek
2020-11-10 12:21 ` [PATCH 1/3] fru: common: Switch capture variable with the rest Michal Simek
2020-11-10 12:21 ` [PATCH 2/3] fru: ops: Do not let parser to write data to not allocated space Michal Simek
2020-11-10 12:21 ` [PATCH 3/3] fru: common: Record pcie/uuid fields in custom board area Michal Simek
2020-11-20  9:49 ` [PATCH 0/3] xilinx: fru: Small update and fixes Michal Simek

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.