summaryrefslogtreecommitdiff
path: root/examples/l2fwd-crypto
diff options
context:
space:
mode:
authorPablo de Lara <pablo.de.lara.guarch@intel.com>2017-07-31 05:40:37 +0100
committerThomas Monjalon <thomas@monjalon.net>2017-07-31 22:46:36 +0200
commit8dbc9bbfe3d08d563abe7a65af7262af67214cf6 (patch)
treed102490339a8338e0ef3d6338742284861b3a333 /examples/l2fwd-crypto
parent04716352beb06ec1285710dd9cb28316cadec57d (diff)
downloaddpdk-8dbc9bbfe3d08d563abe7a65af7262af67214cf6.zip
dpdk-8dbc9bbfe3d08d563abe7a65af7262af67214cf6.tar.gz
dpdk-8dbc9bbfe3d08d563abe7a65af7262af67214cf6.tar.xz
examples/l2fwd-crypto: fix possible out-of-bounds
rte_cryptodev_socket_id() returns the socket id of a crypto device, unless the device id is not valid, in which case, it returns -1. This should not happen, as the device id is controlled by the application, but just for safety, a check is added. Coverity issue: 158628, 158638, 158656, 158662 Fixes: b3bbd9e5f265 ("cryptodev: support device independent sessions") Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Diffstat (limited to 'examples/l2fwd-crypto')
-rw-r--r--examples/l2fwd-crypto/main.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 83446f3..f020be3 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -662,7 +662,12 @@ initialize_crypto_session(struct l2fwd_crypto_options *options, uint8_t cdev_id)
{
struct rte_crypto_sym_xform *first_xform;
struct rte_cryptodev_sym_session *session;
- uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
+ int retval = rte_cryptodev_socket_id(cdev_id);
+
+ if (retval < 0)
+ return NULL;
+
+ uint8_t socket_id = (uint8_t) retval;
struct rte_mempool *sess_mp = session_pool_socket[socket_id];
if (options->xform_chain == L2FWD_CRYPTO_AEAD) {
@@ -1996,7 +2001,14 @@ initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
cdev_id++) {
struct rte_cryptodev_qp_conf qp_conf;
struct rte_cryptodev_info dev_info;
- uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);
+ retval = rte_cryptodev_socket_id(cdev_id);
+
+ if (retval < 0) {
+ printf("Invalid crypto device id used\n");
+ return -1;
+ }
+
+ uint8_t socket_id = (uint8_t) retval;
struct rte_cryptodev_config conf = {
.nb_queue_pairs = 1,