[PATCH 0/3] xilinx: fru: Small update and fixes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/3] xilinx: fru: Small update and fixes

Michal Simek-3
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

Reply | Threaded
Open this post in threaded view
|

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

Michal Simek-3
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 <[hidden email]>
---

 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

Reply | Threaded
Open this post in threaded view
|

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

Michal Simek-3
In reply to this post by Michal Simek-3
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 <[hidden email]>
---

 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

Reply | Threaded
Open this post in threaded view
|

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

Michal Simek-3
In reply to this post by Michal Simek-3
Add additional fields. They will be just recorded and filled but not shown.

Signed-off-by: Michal Simek <[hidden email]>
---

 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

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/3] xilinx: fru: Small update and fixes

Michal Simek-4
In reply to this post by Michal Simek-3
Ășt 10. 11. 2020 v 13:21 odesĂ­latel Michal Simek
<[hidden email]> 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