Skip to content

Commit

Permalink
crypto/nitrox: fix panic with high number of segments
Browse files Browse the repository at this point in the history
[ upstream commit 4a469e1216384d19a6dc3950686f479e30e319a9 ]

When the number of segments in source or destination mbuf is higher than
max supported then the application was panicked during the creation of
sglist when RTE_VERIFY was called. Validate the number of mbuf segments
and return an error instead of panicking.

Fixes: 678f3ec ("crypto/nitrox: support cipher-only operations")
Fixes: 9282bde ("crypto/nitrox: add cipher auth chain processing")

Signed-off-by: Nagadheeraj Rottela <rnagadheeraj@marvell.com>
  • Loading branch information
Nagadheeraj Rottela authored and bluca committed Nov 8, 2023
1 parent 3c0b095 commit 01ae596
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions drivers/crypto/nitrox/nitrox_sym_reqmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#include "nitrox_sym_reqmgr.h"
#include "nitrox_logs.h"

#define MAX_SGBUF_CNT 16
#define MAX_SGCOMP_CNT 5
#define MAX_SUPPORTED_MBUF_SEGS 16
/* IV + AAD + ORH + CC + DIGEST */
#define ADDITIONAL_SGBUF_CNT 5
#define MAX_SGBUF_CNT (MAX_SUPPORTED_MBUF_SEGS + ADDITIONAL_SGBUF_CNT)
#define MAX_SGCOMP_CNT (RTE_ALIGN_MUL_CEIL(MAX_SGBUF_CNT, 4) / 4)
/* SLC_STORE_INFO */
#define MIN_UDD_LEN 16
/* PKT_IN_HDR + SLC_STORE_INFO */
Expand Down Expand Up @@ -303,7 +306,7 @@ create_sglist_from_mbuf(struct nitrox_sgtable *sgtbl, struct rte_mbuf *mbuf,
datalen -= mlen;
}

RTE_VERIFY(cnt <= MAX_SGBUF_CNT);
RTE_ASSERT(cnt <= MAX_SGBUF_CNT);
sgtbl->map_bufs_cnt = cnt;
return 0;
}
Expand Down Expand Up @@ -375,7 +378,7 @@ create_cipher_outbuf(struct nitrox_softreq *sr)
sr->out.sglist[cnt].virt = &sr->resp.completion;
cnt++;

RTE_VERIFY(cnt <= MAX_SGBUF_CNT);
RTE_ASSERT(cnt <= MAX_SGBUF_CNT);
sr->out.map_bufs_cnt = cnt;

create_sgcomp(&sr->out);
Expand Down Expand Up @@ -600,7 +603,7 @@ create_aead_outbuf(struct nitrox_softreq *sr, struct nitrox_sglist *digest)
resp.completion);
sr->out.sglist[cnt].virt = &sr->resp.completion;
cnt++;
RTE_VERIFY(cnt <= MAX_SGBUF_CNT);
RTE_ASSERT(cnt <= MAX_SGBUF_CNT);
sr->out.map_bufs_cnt = cnt;

create_sgcomp(&sr->out);
Expand Down Expand Up @@ -774,6 +777,14 @@ nitrox_process_se_req(uint16_t qno, struct rte_crypto_op *op,
{
int err;

if (unlikely(op->sym->m_src->nb_segs > MAX_SUPPORTED_MBUF_SEGS ||
(op->sym->m_dst &&
op->sym->m_dst->nb_segs > MAX_SUPPORTED_MBUF_SEGS))) {
NITROX_LOG(ERR, "Mbuf segments not supported. "
"Max supported %d\n", MAX_SUPPORTED_MBUF_SEGS);
return -ENOTSUP;
}

softreq_init(sr, sr->iova);
sr->ctx = ctx;
sr->op = op;
Expand Down

0 comments on commit 01ae596

Please sign in to comment.