* [PATCH v2][next] cxgb4/ch_ktls: Fix undefined behavior bug in struct chcr_ktls_ofld_ctx_tx
@ 2023-10-03 10:56 Gustavo A. R. Silva
2023-10-03 16:58 ` Sabrina Dubroca
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-03 10:56 UTC (permalink / raw
To: Ayush Sawal, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Rohit Maheshwari
Cc: netdev, linux-kernel, Gustavo A. R. Silva, linux-hardening
`struct tls_offload_context_tx` is a flexible structure, which means
that it contains a flexible-array member at the bottom. This could
potentially lead to an overwrite of the objects following `base` in
`struct chcr_ktls_ofld_ctx_tx` at run-time.
Notice that flexible-array member `driver_state` in `struct
tls_offload_context_tx` can grow up to 16 bytes:
| include/net/tls.h-170:
| #define TLS_DRIVER_STATE_SIZE_TX 16
| include/net/tls.h-173:
| #define TLS_OFFLOAD_CONTEXT_SIZE_TX \
| (sizeof(struct tls_offload_context_tx) + TLS_DRIVER_STATE_SIZE_TX)
| net/tls/tls_device.c-1119:
| offload_ctx = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_TX, GFP_KERNEL);
Fix this by placing the declaration of object `base` at the end of
`struct chcr_ktls_ofld_ctx_tx`.
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.
Fixes: 34aba2c45024 ("cxgb4/chcr : Register to tls add and del callback")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v2:
- Update changelog text: mention -Wflex-array-member-not-at-end.
v1:
- Link: https://lore.kernel.org/linux-hardening/ZRvyysCUTqA7aXN4@work/
drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h
index 10572dc55365..35e34e3db663 100644
--- a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h
+++ b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h
@@ -68,8 +68,8 @@ struct chcr_ktls_info {
};
struct chcr_ktls_ofld_ctx_tx {
- struct tls_offload_context_tx base;
struct chcr_ktls_info *chcr_info;
+ struct tls_offload_context_tx base;
};
struct chcr_ktls_uld_ctx {
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2][next] cxgb4/ch_ktls: Fix undefined behavior bug in struct chcr_ktls_ofld_ctx_tx
2023-10-03 10:56 [PATCH v2][next] cxgb4/ch_ktls: Fix undefined behavior bug in struct chcr_ktls_ofld_ctx_tx Gustavo A. R. Silva
@ 2023-10-03 16:58 ` Sabrina Dubroca
0 siblings, 0 replies; 2+ messages in thread
From: Sabrina Dubroca @ 2023-10-03 16:58 UTC (permalink / raw
To: Gustavo A. R. Silva
Cc: Ayush Sawal, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Rohit Maheshwari, netdev, linux-kernel,
linux-hardening
2023-10-03, 12:56:54 +0200, Gustavo A. R. Silva wrote:
> `struct tls_offload_context_tx` is a flexible structure, which means
> that it contains a flexible-array member at the bottom. This could
> potentially lead to an overwrite of the objects following `base` in
> `struct chcr_ktls_ofld_ctx_tx` at run-time.
>
> Notice that flexible-array member `driver_state` in `struct
> tls_offload_context_tx` can grow up to 16 bytes:
>
> | include/net/tls.h-170:
> | #define TLS_DRIVER_STATE_SIZE_TX 16
>
> | include/net/tls.h-173:
> | #define TLS_OFFLOAD_CONTEXT_SIZE_TX \
> | (sizeof(struct tls_offload_context_tx) + TLS_DRIVER_STATE_SIZE_TX)
>
> | net/tls/tls_device.c-1119:
> | offload_ctx = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_TX, GFP_KERNEL);
>
> Fix this by placing the declaration of object `base` at the end of
> `struct chcr_ktls_ofld_ctx_tx`.
AFAIU, chcr_ktls_ofld_ctx_tx just misuses the extra space allocated by
tls_set_device_offload. There's no bug, but the code is a bit
confusing. I don't think this patch works, since chcr_ktls doesn't
allocate its own memory for chcr_ktls_ofld_ctx_tx.
As part of a series of cleanups that I'll submit soon (hopefully this
week), I updated chcr_ktls to use the driver_state part of
tls_offload_context_tx (instead of the cast in
chcr_get_ktls_tx_context), and then removed the flexarrays from
tls_offload_context_tx and tls_offload_context_rx (since they're
actually a fixed size).
--
Sabrina
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-03 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03 10:56 [PATCH v2][next] cxgb4/ch_ktls: Fix undefined behavior bug in struct chcr_ktls_ofld_ctx_tx Gustavo A. R. Silva
2023-10-03 16:58 ` Sabrina Dubroca
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 read-only IMAP folder(s) and NNTP newsgroup(s).