* [PATCH] migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv
@ 2024-09-10 5:41 Stefan Weil via
2024-09-11 18:43 ` Peter Xu
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil via @ 2024-09-10 5:41 UTC (permalink / raw)
To: Peter Xu, Fabiano Rosas, Paolo Bonzini; +Cc: qemu-devel, Stefan Weil
GitHub's CodeQL reports four critical errors which are fixed by this commit:
Unsigned difference expression compared to zero
An expression (u - v > 0) with unsigned values u, v is only false if u == v,
so all changed expressions did not work as expected.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
I don't know what effect the errors will have.
Please check whether the fix should be backported to existing versions of QEMU.
And I think that it might be a good idea to add the security check to
https://github.com/qemu/qemu, too. The critical errors here and in net/colo-compare.c
were not reported by other static code analyzers as far as I know.
Paolo, if desired, I can send a patch for CodeQL.
Stefan W.
migration/multifd-zstd.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c
index 53da33e048..abed140855 100644
--- a/migration/multifd-zstd.c
+++ b/migration/multifd-zstd.c
@@ -123,9 +123,9 @@ static int multifd_zstd_send_prepare(MultiFDSendParams *p, Error **errp)
*/
do {
ret = ZSTD_compressStream2(z->zcs, &z->out, &z->in, flush);
- } while (ret > 0 && (z->in.size - z->in.pos > 0)
- && (z->out.size - z->out.pos > 0));
- if (ret > 0 && (z->in.size - z->in.pos > 0)) {
+ } while (ret > 0 && (z->in.size > z->in.pos)
+ && (z->out.size > z->out.pos));
+ if (ret > 0 && (z->in.size > z->in.pos)) {
error_setg(errp, "multifd %u: compressStream buffer too small",
p->id);
return -1;
@@ -243,7 +243,7 @@ static int multifd_zstd_recv(MultiFDRecvParams *p, Error **errp)
*/
do {
ret = ZSTD_decompressStream(z->zds, &z->out, &z->in);
- } while (ret > 0 && (z->in.size - z->in.pos > 0)
+ } while (ret > 0 && (z->in.size > z->in.pos)
&& (z->out.pos < page_size));
if (ret > 0 && (z->out.pos < page_size)) {
error_setg(errp, "multifd %u: decompressStream buffer too small",
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv
2024-09-10 5:41 [PATCH] migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv Stefan Weil via
@ 2024-09-11 18:43 ` Peter Xu
0 siblings, 0 replies; 2+ messages in thread
From: Peter Xu @ 2024-09-11 18:43 UTC (permalink / raw)
To: Stefan Weil; +Cc: Fabiano Rosas, Paolo Bonzini, qemu-devel
On Tue, Sep 10, 2024 at 07:41:38AM +0200, Stefan Weil wrote:
> GitHub's CodeQL reports four critical errors which are fixed by this commit:
>
> Unsigned difference expression compared to zero
>
> An expression (u - v > 0) with unsigned values u, v is only false if u == v,
> so all changed expressions did not work as expected.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> I don't know what effect the errors will have.
> Please check whether the fix should be backported to existing versions of QEMU.
>
> And I think that it might be a good idea to add the security check to
> https://github.com/qemu/qemu, too. The critical errors here and in net/colo-compare.c
> were not reported by other static code analyzers as far as I know.
> Paolo, if desired, I can send a patch for CodeQL.
I hope Paolo can see these lines.
Patch queued, thanks.
--
Peter Xu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-11 18:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10 5:41 [PATCH] migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv Stefan Weil via
2024-09-11 18:43 ` Peter Xu
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 NNTP newsgroup(s).