examples/ipsec-secgw: fix partial overflow

Message ID 20231115123101.2377544-1-brian.dooley@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series examples/ipsec-secgw: fix partial overflow |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

Brian Dooley Nov. 15, 2023, 12:31 p.m. UTC
  Case of partial overflow detected with ASan. Added extra padding
to cdev_key structure.

This structure is used for the key in hash table.
Padding is added to force the struct to use 8 bytes,
to ensure memory is notread past this structs boundary
(the hash key calculation reads 8 bytes if this struct is size 5 bytes).
The padding should be zeroed.
If fields are modified in this struct, the padding must be updated to
ensure multiple of 8 bytes size overall.

Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")
Cc: sergio.gonzalez.monroy@intel.com
Cc: stable@dpdk.org

Signed-off-by: Brian Dooley <brian.dooley@intel.com>
---
 examples/ipsec-secgw/ipsec.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Comments

Power, Ciara Nov. 15, 2023, 4:24 p.m. UTC | #1
> -----Original Message-----
> From: Brian Dooley <brian.dooley@intel.com>
> Sent: Wednesday, November 15, 2023 12:31 PM
> To: dev@dpdk.org
> Cc: Dooley, Brian <brian.dooley@intel.com>;
> sergio.gonzalez.monroy@intel.com; stable@dpdk.org; Nicolau, Radu
> <radu.nicolau@intel.com>; Akhil Goyal <gakhil@marvell.com>
> Subject: [PATCH] examples/ipsec-secgw: fix partial overflow
> 
> Case of partial overflow detected with ASan. Added extra padding to cdev_key
> structure.
> 
> This structure is used for the key in hash table.
> Padding is added to force the struct to use 8 bytes, to ensure memory is
> notread past this structs boundary (the hash key calculation reads 8 bytes if
> this struct is size 5 bytes).
> The padding should be zeroed.
> If fields are modified in this struct, the padding must be updated to ensure
> multiple of 8 bytes size overall.
> 
> Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")
> Cc: sergio.gonzalez.monroy@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Brian Dooley <brian.dooley@intel.com>

Acked-by: Ciara Power <ciara.power@intel.com>
  
Thomas Monjalon Nov. 22, 2023, 4:37 p.m. UTC | #2
> > Case of partial overflow detected with ASan. Added extra padding to cdev_key
> > structure.
> > 
> > This structure is used for the key in hash table.
> > Padding is added to force the struct to use 8 bytes, to ensure memory is
> > notread past this structs boundary (the hash key calculation reads 8 bytes if
> > this struct is size 5 bytes).
> > The padding should be zeroed.
> > If fields are modified in this struct, the padding must be updated to ensure
> > multiple of 8 bytes size overall.
> > 
> > Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")
> > Cc: sergio.gonzalez.monroy@intel.com
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Brian Dooley <brian.dooley@intel.com>
> 
> Acked-by: Ciara Power <ciara.power@intel.com>

Applied and made the comment simpler with this:

  uint8_t padding[3]; /* padding to 8-byte size should be zeroed */
  
Brian Dooley Nov. 23, 2023, 10:48 a.m. UTC | #3
Thanks Thomas, makes sense.

> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Wednesday, November 22, 2023 4:38 PM
> To: Dooley, Brian <brian.dooley@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Nicolau, Radu
> <radu.nicolau@intel.com>; Akhil Goyal <gakhil@marvell.com>; Power, Ciara
> <ciara.power@intel.com>
> Subject: Re: [PATCH] examples/ipsec-secgw: fix partial overflow
> 
> > > Case of partial overflow detected with ASan. Added extra padding to
> > > cdev_key structure.
> > >
> > > This structure is used for the key in hash table.
> > > Padding is added to force the struct to use 8 bytes, to ensure
> > > memory is notread past this structs boundary (the hash key
> > > calculation reads 8 bytes if this struct is size 5 bytes).
> > > The padding should be zeroed.
> > > If fields are modified in this struct, the padding must be updated
> > > to ensure multiple of 8 bytes size overall.
> > >
> > > Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample
> > > application")
> > > Cc: sergio.gonzalez.monroy@intel.com
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Brian Dooley <brian.dooley@intel.com>
> >
> > Acked-by: Ciara Power <ciara.power@intel.com>
> 
> Applied and made the comment simpler with this:
> 
>   uint8_t padding[3]; /* padding to 8-byte size should be zeroed */
> 
>
  

Patch

diff --git a/examples/ipsec-secgw/ipsec.h b/examples/ipsec-secgw/ipsec.h
index 5059418456..10e7fc179b 100644
--- a/examples/ipsec-secgw/ipsec.h
+++ b/examples/ipsec-secgw/ipsec.h
@@ -249,11 +249,21 @@  struct offloads {
 
 extern struct offloads tx_offloads;
 
+/*
+ * This structure is used for the key in hash table.
+ * Padding is added to force the struct to use 8 bytes,
+ * to ensure memory is notread past this structs boundary
+ * (the hash key calculation reads 8 bytes if this struct is size 5 bytes).
+ * The padding should be zeroed.
+ * If fields are modified in this struct, the padding must be updated to
+ * ensure multiple of 8 bytes size overall.
+ */
 struct cdev_key {
 	uint16_t lcore_id;
 	uint8_t cipher_algo;
 	uint8_t auth_algo;
 	uint8_t aead_algo;
+	uint8_t padding[3];
 };
 
 struct socket_ctx {