cryptodev: Handle unexpected request to avoid crash
PATCH 1/1 cryptodev: Handle unexpected request to avoid crash
Generally guest side should discover which services the device is able to offer, then do requests on device.
However it's also possible to break this rule in a guest. Handle unexpected request here to avoid NULL pointer dereference.
--- backends/cryptodev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
backends/cryptodev.c +10 -0
@@ -191,6 +191,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend,if (algtype ==QCRYPTODEV_BACKEND_ALG_ASYM ) {CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info; len = asym_op_info->src_len; + +if (unlikely (!backend->asym_stat)) { +error_report ("cryptodev: Unexpected asym operation" ); +return -VIRTIO_CRYPTO_NOTSUPP ; + }switch (op_info->op_code) {case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT :CryptodevAsymStatIncEncrypt (backend, len);
@@ -210,6 +215,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend, }else if (algtype ==QCRYPTODEV_BACKEND_ALG_SYM ) {CryptoDevBackendSymOpInfo *sym_op_info = op_info->u.sym_op_info; len = sym_op_info->src_len; + +if (unlikely (!backend->sym_stat)) { +error_report ("cryptodev: Unexpected sym operation" ); +return -VIRTIO_CRYPTO_NOTSUPP ; + }switch (op_info->op_code) {case VIRTIO_CRYPTO_CIPHER_ENCRYPT :CryptodevSymStatIncEncrypt (backend, len);
Signature · 1 line
2.34.1
Quoted 51 lines · zhenwei pi
Generally guest side should discover which services the device is able to offer, then do requests on device.
However it's also possible to break this rule in a guest. Handle unexpected request here to avoid NULL pointer dereference.
Fixes e7a775fd ('cryptodev: Account statistics')Cc Gonglei <[email protected]>Cc Mauro Matteo Cascella <[email protected]>Cc Xiao Lei <[email protected]>Cc Yongkang Jia <[email protected]>Reported-by Yiming Tao <[email protected]>Signed-off-by zhenwei pi <[email protected]>---
backends/cryptodev.c| 10 ++++++++++1 file changed, 10 insertions(+)backends/cryptodev.c +10
-0@@ -191,6 +191,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend,if (algtype ==QCRYPTODEV_BACKEND_ALG_ASYM ) {CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info; len = asym_op_info->src_len; + +if (unlikely (!backend->asym_stat)) { +error_report ("cryptodev: Unexpected asym operation" ); +return -VIRTIO_CRYPTO_NOTSUPP ; + }switch (op_info->op_code) {case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT :CryptodevAsymStatIncEncrypt (backend, len);@@ -210,6 +215,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend, }else if (algtype ==QCRYPTODEV_BACKEND_ALG_SYM ) {CryptoDevBackendSymOpInfo *sym_op_info = op_info->u.sym_op_info; len = sym_op_info->src_len; + +if (unlikely (!backend->sym_stat)) { +error_report ("cryptodev: Unexpected sym operation" ); +return -VIRTIO_CRYPTO_NOTSUPP ; + }switch (op_info->op_code) {case VIRTIO_CRYPTO_CIPHER_ENCRYPT :CryptodevSymStatIncEncrypt (backend, len);Signature · 1 line
2.34.1
Best regards,
Lei He
--
[email protected]
Hi Michael
Could you please apply this patch?
Quoted 62 lines · Lei He
Quoted 51 lines · zhenwei pi
Generally guest side should discover which services the device is able to offer, then do requests on device.
However it's also possible to break this rule in a guest. Handle unexpected request here to avoid NULL pointer dereference.
Fixes e7a775fd ('cryptodev: Account statistics')Cc Gonglei <[email protected]>Cc Mauro Matteo Cascella <[email protected]>Cc Xiao Lei <[email protected]>Cc Yongkang Jia <[email protected]>Reported-by Yiming Tao <[email protected]>Signed-off-by zhenwei pi <[email protected]>---
backends/cryptodev.c| 10 ++++++++++1 file changed, 10 insertions(+)backends/cryptodev.c +10
-0@@ -191,6 +191,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend,if (algtype ==QCRYPTODEV_BACKEND_ALG_ASYM ) {CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info; len = asym_op_info->src_len; + +if (unlikely (!backend->asym_stat)) { +error_report ("cryptodev: Unexpected asym operation" ); +return -VIRTIO_CRYPTO_NOTSUPP ; + }switch (op_info->op_code) {case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT :CryptodevAsymStatIncEncrypt (backend, len);@@ -210,6 +215,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend, }else if (algtype ==QCRYPTODEV_BACKEND_ALG_SYM ) {CryptoDevBackendSymOpInfo *sym_op_info = op_info->u.sym_op_info; len = sym_op_info->src_len; + +if (unlikely (!backend->sym_stat)) { +error_report ("cryptodev: Unexpected sym operation" ); +return -VIRTIO_CRYPTO_NOTSUPP ; + }switch (op_info->op_code) {case VIRTIO_CRYPTO_CIPHER_ENCRYPT :CryptodevSymStatIncEncrypt (backend, len);Signature · 1 line
2.34.1Reviewed-by Lei He <[email protected]>Best regards,
Lei He
--
[email protected]
Signature · 1 line
zhenwei pi