vdpa: Merge all net_init_vhost_vdpa error goto
cover vdpa: Merge all net_init_vhost_vdpa error goto
Few steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one.
This series includes an already posted patch [1], because it must be applied on top of that.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2022-08/msg00089.html
Eugenio Pérez (2):
vdpa: Fix file descriptor leak on get features error
vdpa: Merge all net_init_vhost_vdpa error goto
net/vhost-vdpa.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 vdpa: Fix file descriptor leak on get features error
File descriptor vdpa_device_fd is not free in the case of returning error from vhost_vdpa_get_features. Fixing it by making all errors go to the same error path.
Resolves: Coverity CID 1490785
--- net/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/vhost-vdpa.c +2 -2
@@ -566,7 +566,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;g_autoptr (VhostIOVATree) iova_tree =NULL ;NetClientState *nc; -int queue_pairs, r, i, has_cvq =0 ; +int queue_pairs, r, i =0 , has_cvq =0 ;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;
@@ -582,7 +582,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, r =vhost_vdpa_get_features (vdpa_device_fd, &features, errp);if (unlikely (r <0 )) { -return r; + goto err; } queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, features,
Signature · 1 line
2.31.1
Re: [PATCH 1/2] vdpa: Fix file descriptor leak on get features error
Quoted 26 lines · Eugenio Pérez
File descriptor
vdpa_device_fdis not free in the case of returning error fromvhost_vdpa_get_features. Fixing it by making all errors go to the same error path.Resolves: Coverity CID 1490785
Fixes 8170ab3f43 ("vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs")Signed-off-by Eugenio Pérez <[email protected]>--- net/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/vhost-vdpa.c +1
-1@@ -566,7 +566,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;g_autoptr (VhostIOVATree) iova_tree =NULL ;NetClientState *nc; -int queue_pairs, r, i, has_cvq =0 ; +int queue_pairs, r, i =0 , has_cvq =0 ;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;
net/vhost-vdpa.c int net_init_vhost_vdpa(const Netdev *netdev, const char *name, · line 588
Quoted 8 lines
net/vhost-vdpa.c +1
-1@@ -582,7 +582,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, r =vhost_vdpa_get_features (vdpa_device_fd, &features, errp);if (unlikely (r <0 )) { -return r; + goto err; } queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, features,
I can take this one via the trivial branch.
Thanks,
Laurent
Michael S. Tsirkin
Reviewed-byRe: [PATCH 1/2] vdpa: Fix file descriptor leak on get features error
Quoted 35 lines · Laurent Vivier
Quoted 25 lines · Eugenio Pérez
File descriptor
vdpa_device_fdis not free in the case of returning error fromvhost_vdpa_get_features. Fixing it by making all errors go to the same error path.Resolves: Coverity CID 1490785
Fixes 8170ab3f43 ("vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs")Signed-off-by Eugenio Pérez <[email protected]>--- net/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/vhost-vdpa.c +1
-1@@ -566,7 +566,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;g_autoptr (VhostIOVATree) iova_tree =NULL ;NetClientState *nc; -int queue_pairs, r, i, has_cvq =0 ; +int queue_pairs, r, i =0 , has_cvq =0 ;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;net/vhost-vdpa.c int net_init_vhost_vdpa(const Netdev *netdev, const char *name, · line 586
Quoted 6 lines
net/vhost-vdpa.c +1
-1@@ -582,7 +582,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, r =vhost_vdpa_get_features (vdpa_device_fd, &features, errp);if (unlikely (r <0 )) { -return r; + goto err; } queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, features,Reviewed-by Laurent Vivier <[email protected]>
Quoted 4 lines
I can take this one via the trivial branch.
Thanks,
Laurent
Not sure why it's appropriate for trivial but sure if you like
Laurent Vivier
AppliedRe: [PATCH 1/2] vdpa: Fix file descriptor leak on get features error
In reply to Eugenio PérezLe 02/08/2022 à 13:24, Eugenio Pérez a écrit :
Quoted 26 lines
File descriptor
vdpa_device_fdis not free in the case of returning error fromvhost_vdpa_get_features. Fixing it by making all errors go to the same error path.Resolves: Coverity CID 1490785
Fixes 8170ab3f43 ("vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs")Signed-off-by Eugenio Pérez <[email protected]>--- net/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/vhost-vdpa.c +1
-1@@ -566,7 +566,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;g_autoptr (VhostIOVATree) iova_tree =NULL ;NetClientState *nc; -int queue_pairs, r, i, has_cvq =0 ; +int queue_pairs, r, i =0 , has_cvq =0 ;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;
net/vhost-vdpa.c int net_init_vhost_vdpa(const Netdev *netdev, const char *name, · line 588
Quoted 8 lines
net/vhost-vdpa.c +1
-1@@ -582,7 +582,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, r =vhost_vdpa_get_features (vdpa_device_fd, &features, errp);if (unlikely (r <0 )) { -return r; + goto err; } queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, features,
Applied to my trivial-patches branch.
Thanks,
Laurent
PATCH 2/2 vdpa: Merge all net_init_vhost_vdpa error goto
In reply to Eugenio PérezFew steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one.
--- net/vhost-vdpa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/vhost-vdpa.c +2 -4
@@ -588,8 +588,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, queue_pairs =vhost_vdpa_get_max_queue_pairs (vdpa_device_fd, features, &has_cvq, errp);if (queue_pairs <0 ) { -qemu_close (vdpa_device_fd); -return queue_pairs; + goto err; }if (opts->x_svq) {
@@ -604,7 +603,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (invalid_dev_features) {error_setg (errp,"vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); - goto err_svq; + goto err; }vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range);
@@ -640,7 +639,6 @@ err: } } -err_svq:qemu_close (vdpa_device_fd);return -1 ;
Signature · 1 line
2.31.1
Quoted 32 lines · Eugenio Pérez
Few steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one.
Signed-off-by Eugenio Pérez <[email protected]>--- net/vhost-vdpa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/vhost-vdpa.c +2
-3@@ -588,8 +588,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, queue_pairs =vhost_vdpa_get_max_queue_pairs (vdpa_device_fd, features, &has_cvq, errp);if (queue_pairs <0 ) { -qemu_close (vdpa_device_fd); -return queue_pairs; + goto err; }if (opts->x_svq) {@@ -604,7 +603,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (invalid_dev_features) {error_setg (errp,"vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); - goto err_svq; + goto err; }vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range);
net/vhost-vdpa.c err: · line 644
Quoted 7 lines
net/vhost-vdpa.c +0
-1@@ -640,7 +639,6 @@ err: } } -err_svq:qemu_close (vdpa_device_fd);return -1 ;
Michael S. Tsirkin
Reviewed-byQuoted 5 lines · Laurent Vivier
Quoted 4 lines · Eugenio Pérez
Few steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one.
Signed-off-by Eugenio Pérez <[email protected]>
qemu-trivial too I guess then?
Quoted 33 lines
Quoted 26 lines
--- net/vhost-vdpa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/vhost-vdpa.c +2
-3@@ -588,8 +588,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, queue_pairs =vhost_vdpa_get_max_queue_pairs (vdpa_device_fd, features, &has_cvq, errp);if (queue_pairs <0 ) { -qemu_close (vdpa_device_fd); -return queue_pairs; + goto err; }if (opts->x_svq) {@@ -604,7 +603,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (invalid_dev_features) {error_setg (errp,"vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); - goto err_svq; + goto err; }vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range);net/vhost-vdpa.c err: · line 642
Quoted 5 lines
net/vhost-vdpa.c +0
-1@@ -640,7 +639,6 @@ err: } } -err_svq:qemu_close (vdpa_device_fd);return -1 ;Reviewed-by Laurent Vivier <[email protected]>
Quoted 9 lines · Michael S. Tsirkin
Quoted 5 lines · Laurent Vivier
Quoted 4 lines · Eugenio Pérez
Few steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one.
Signed-off-by Eugenio Pérez <[email protected]>qemu-trivial too I guess then?
For 7.1 or later?
Thanks,
Laurent
Quoted 37 lines
Reviewed-by Michael S. Tsirkin <[email protected]>Quoted 33 lines
Quoted 26 lines
--- net/vhost-vdpa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/vhost-vdpa.c +2
-3@@ -588,8 +588,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, queue_pairs =vhost_vdpa_get_max_queue_pairs (vdpa_device_fd, features, &has_cvq, errp);if (queue_pairs <0 ) { -qemu_close (vdpa_device_fd); -return queue_pairs; + goto err; }if (opts->x_svq) {@@ -604,7 +603,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (invalid_dev_features) {error_setg (errp,"vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); - goto err_svq; + goto err; }vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range);net/vhost-vdpa.c err: · line 642
Quoted 5 lines
net/vhost-vdpa.c +0
-1@@ -640,7 +639,6 @@ err: } } -err_svq:qemu_close (vdpa_device_fd);return -1 ;Reviewed-by Laurent Vivier <[email protected]>
Quoted 9 lines · Laurent Vivier
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines · Laurent Vivier
Quoted 4 lines · Eugenio Pérez
Few steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one.
Signed-off-by Eugenio Pérez <[email protected]>
Quoted 6 lines
Quoted 1 line
qemu-trivial too I guess then?
For 7.1 or later?
Thanks,
Laurent
I don't really care. Since you are merging this you get to decide.
Quoted 37 lines
Quoted 37 lines
Reviewed-by Michael S. Tsirkin <[email protected]>Quoted 33 lines
Quoted 26 lines
--- net/vhost-vdpa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/vhost-vdpa.c +2
-3@@ -588,8 +588,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, queue_pairs =vhost_vdpa_get_max_queue_pairs (vdpa_device_fd, features, &has_cvq, errp);if (queue_pairs <0 ) { -qemu_close (vdpa_device_fd); -return queue_pairs; + goto err; }if (opts->x_svq) {@@ -604,7 +603,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (invalid_dev_features) {error_setg (errp,"vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); - goto err_svq; + goto err; }vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range);net/vhost-vdpa.c err: · line 642
Quoted 5 lines
net/vhost-vdpa.c +0
-1@@ -640,7 +639,6 @@ err: } } -err_svq:qemu_close (vdpa_device_fd);return -1 ;Reviewed-by Laurent Vivier <[email protected]>
Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines · Laurent Vivier
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines · Laurent Vivier
Quoted 4 lines · Eugenio Pérez
Few steps allocate new resources, and all of the allocated can be checked to avoid trying to free an invalid one.
Signed-off-by Eugenio Pérez <[email protected]>
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
qemu-trivial too I guess then?
For 7.1 or later?
Thanks,
LaurentI don't really care. Since you are merging this you get to decide.
In my opinion it's better to leave that for a later revision.
I sent it to trivial because it only touches a few lines of code and it's easy to review even without knowledge of net or vdpa subsystem, but if it's not appropriate I can send future patches like this out of trivial.
Thanks!
Quoted 38 lines
Quoted 37 lines
Quoted 37 lines
Reviewed-by Michael S. Tsirkin <[email protected]>Quoted 33 lines
Quoted 26 lines
--- net/vhost-vdpa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/vhost-vdpa.c +2
-3@@ -588,8 +588,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, queue_pairs =vhost_vdpa_get_max_queue_pairs (vdpa_device_fd, features, &has_cvq, errp);if (queue_pairs <0 ) { -qemu_close (vdpa_device_fd); -return queue_pairs; + goto err; }if (opts->x_svq) {@@ -604,7 +603,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (invalid_dev_features) {error_setg (errp,"vdpa svq does not work with features 0x%" PRIx64, invalid_dev_features); - goto err_svq; + goto err; }vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range);net/vhost-vdpa.c err: · line 642
Quoted 5 lines
net/vhost-vdpa.c +0
-1@@ -640,7 +639,6 @@ err: } } -err_svq:qemu_close (vdpa_device_fd);return -1 ;Reviewed-by Laurent Vivier <[email protected]>