From nobody Sun May 19 03:54:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586003252; cv=none; d=zohomail.com; s=zohoarc; b=Lmrmyu4Eb04q6zQJHSigtxfBfRg5HqieZdLLLAINeDzFRwDYFgzqi0bBE1MFCX/fOt9gt6EkyEmuzvnNFuYOHpq4eXq/MeR+O7Q6/+Kaw73zqlvqjPoPY3NaxozdfKQ3WhTPk/5IzgLxTMByvXETEPNipivAbUft+I7iKYYpJGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586003252; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yaUQGMTUul9I2XZ/qHlJVTWpznqCJBLPf50RX7914W0=; b=ZyIG8Viu1H5XcuMIbE7u07RsAI2zRSgf02G5bshm0EPLFKqdD6RRCUjnVh4qinCaPuNKLiookTZyyDEMbJBOnqgKLUliqnBesVuKiLeAKiY+D9P50OV3nm5xuYcRO64XdKG/swutcTrXXILW3It6/YR0sdKV6y1BBetV7GZWiyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586003252908950.9376885133182; Sat, 4 Apr 2020 05:27:32 -0700 (PDT) Received: from localhost ([::1]:38436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhtb-00067m-II for importer@patchew.org; Sat, 04 Apr 2020 08:27:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54351) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhqb-00025G-SM for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKhqa-00037V-CF for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:25 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:52289 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKhqa-00034H-81 for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-LiE7BIKrPT6udWT9FWDomQ-1; Sat, 04 Apr 2020 08:24:19 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2AC778017CE; Sat, 4 Apr 2020 12:24:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-152.ams2.redhat.com [10.36.112.152]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6C3B19C4F; Sat, 4 Apr 2020 12:24:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5C18511385C8; Sat, 4 Apr 2020 14:24:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586003063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yaUQGMTUul9I2XZ/qHlJVTWpznqCJBLPf50RX7914W0=; b=SXp0jE+560+hLdLQrgtooFNlfRejYO9bppMqVa+x2ogVrVhl1/tGYCXdo0u8F8OFxEtWRJ T5ncuX5LgBc1kq4JOMwhHqwNol+7zZSJxEPtk/VU/MeNTxFLVS0bQuaAIL9DD7VgKakA3b CMZ5CqCD5RkZjXWaeJQ9LvQ66qkgOlk= X-MC-Unique: LiE7BIKrPT6udWT9FWDomQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 1/3] scripts/coccinelle: add error-use-after-free.cocci Date: Sat, 4 Apr 2020 14:24:14 +0200 Message-Id: <20200404122416.1837-2-armbru@redhat.com> In-Reply-To: <20200404122416.1837-1-armbru@redhat.com> References: <20200404122416.1837-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Sementsov-Ogievskiy , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Add script to find and fix trivial use-after-free of Error objects. How to use: spatch --sp-file scripts/coccinelle/error-use-after-free.cocci \ --macro-file scripts/cocci-macro-file.h --in-place \ --no-show-diff ( FILES... | --use-gitgrep . ) Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20200324153630.11882-2-vsementsov@virtuozzo.com> Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster [Pastos in commit message and comment fixed, globbing in MAINTAINERS expanded] Signed-off-by: Markus Armbruster --- scripts/coccinelle/error-use-after-free.cocci | 52 +++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 57 insertions(+) create mode 100644 scripts/coccinelle/error-use-after-free.cocci diff --git a/scripts/coccinelle/error-use-after-free.cocci b/scripts/coccin= elle/error-use-after-free.cocci new file mode 100644 index 0000000000..72ae9fdebf --- /dev/null +++ b/scripts/coccinelle/error-use-after-free.cocci @@ -0,0 +1,52 @@ +// Find and fix trivial use-after-free of Error objects +// +// Copyright (c) 2020 Virtuozzo International GmbH. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// . +// +// How to use: +// spatch --sp-file scripts/coccinelle/error-use-after-free.cocci \ +// --macro-file scripts/cocci-macro-file.h --in-place \ +// --no-show-diff ( FILES... | --use-gitgrep . ) + +@ exists@ +identifier fn, fn2; +expression err; +@@ + + fn(...) + { + <... +( + error_free(err); ++ err =3D NULL; +| + error_report_err(err); ++ err =3D NULL; +| + error_reportf_err(err, ...); ++ err =3D NULL; +| + warn_report_err(err); ++ err =3D NULL; +| + warn_reportf_err(err, ...); ++ err =3D NULL; +) + ... when !=3D err =3D NULL + when !=3D exit(...) + fn2(..., err, ...) + ...> + } diff --git a/MAINTAINERS b/MAINTAINERS index 7cb53ec138..9d156d73b3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2053,6 +2053,11 @@ F: include/qemu/error-report.h F: qapi/error.json F: util/error.c F: util/qemu-error.c +F: scripts/coccinelle/err-bad-newline.cocci +F: scripts/coccinelle/error-use-after-free.cocci +F: scripts/coccinelle/error_propagate_null.cocci +F: scripts/coccinelle/remove_local_err.cocci +F: scripts/coccinelle/use-error_fatal.cocci =20 GDB stub M: Alex Benn=C3=A9e --=20 2.21.1 From nobody Sun May 19 03:54:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586003141; cv=none; d=zohomail.com; s=zohoarc; b=BQffKgE4oCLmY0xDJbXadpuxs1IcrlZv9QC5mhaQMSpVsVGdIXVZCPukbfRCdFN+qEnMwZo9X/d7phPDprzjR8ZWTE71Jo+i/YL3ReXtuyQcyz5dY+pk3ur0e2ZLm4CIiIcM/n61LM44w97DBTmKmMk01BoaxOo7L/KvUIJPLrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586003141; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eb23JDY2ph7uUo2FAF/JWbKPJXBxBkM6ynhU6yd5bws=; b=KAd2j7FbZxwOvgZKiitPrseCIl6lfWc/vK3AxUE1Gi/ckjMgils0lIDHyO9JQT/nYIqBIHeYgIZY8U9wEXkR62b3YaKa7av2CJFfVPMBMdGTwUVvrLiHDwY0TjEyfSiJNfLqrycPeJ6/lEzMtQC1psQ3dME5dxOrNUT2Nfp2/mA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586003141099293.01418572300224; Sat, 4 Apr 2020 05:25:41 -0700 (PDT) Received: from localhost ([::1]:38406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhrn-0003P8-63 for importer@patchew.org; Sat, 04 Apr 2020 08:25:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54320) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhqZ-00024o-H8 for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKhqY-00032e-Ak for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:23 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:33805 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKhqY-00031p-46 for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-4-kmmRRdMXWzon6wn58yIg-1; Sat, 04 Apr 2020 08:24:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25D59800D4E; Sat, 4 Apr 2020 12:24:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-152.ams2.redhat.com [10.36.112.152]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D94CE1000322; Sat, 4 Apr 2020 12:24:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5F56C11384A9; Sat, 4 Apr 2020 14:24:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586003061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eb23JDY2ph7uUo2FAF/JWbKPJXBxBkM6ynhU6yd5bws=; b=F810NgXwj+CKA5+rkOH1YZF7kAkOp39wQjn5htUvZENE/An5dg4p3XaZrrKMbbOVS0R5Vl eKy9Zzkx5d6+e7r5gJwmKJqMiGe9LnbHBHBewHyGKwMjJ2KRebMSH8qtRYHPfW3wjWJoZ+ V/qHxjsEfhDjem57R2Ek7mklpJcRl44= X-MC-Unique: 4-kmmRRdMXWzon6wn58yIg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 2/3] dump/win_dump: fix use after free of err Date: Sat, 4 Apr 2020 14:24:15 +0200 Message-Id: <20200404122416.1837-3-armbru@redhat.com> In-Reply-To: <20200404122416.1837-1-armbru@redhat.com> References: <20200404122416.1837-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Sementsov-Ogievskiy , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy It's possible that we'll try to set err twice (or more). It's bad, it will crash. Instead, use warn_report(). Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20200324153630.11882-4-vsementsov@virtuozzo.com> Reviewed-by: Markus Armbruster Reviewed-by: Richard Henderson Signed-off-by: Markus Armbruster --- dump/win_dump.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dump/win_dump.c b/dump/win_dump.c index eda2a48974..652c7bad99 100644 --- a/dump/win_dump.c +++ b/dump/win_dump.c @@ -304,13 +304,11 @@ static void restore_context(WinDumpHeader64 *h, struct saved_context *saved_ctx) { int i; - Error *err =3D NULL; =20 for (i =3D 0; i < h->NumberProcessors; i++) { if (cpu_memory_rw_debug(first_cpu, saved_ctx[i].addr, (uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 1)) { - error_setg(&err, "win-dump: failed to restore CPU #%d context"= , i); - warn_report_err(err); + warn_report("win-dump: failed to restore CPU #%d context", i); } } } --=20 2.21.1 From nobody Sun May 19 03:54:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586003141; cv=none; d=zohomail.com; s=zohoarc; b=iKxvSU3hnn0mtiD70jJvgno/0SjzHQRxK+PVJyZwHrU/NIfmyujLlgPSq9bTi0WvorgMBwG0L+lEjvNLhbp/Swd5UFdb+rcwTE0JCciDhks0XL1ze3ScAS9Yi3Gec3nk3CnEHFwZ8FacnzZOiA+D5iG4JPTgOlHHHkdoPK2SAfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586003141; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B7wjwW4kktbArsvMvX1086jM6kTZmn7Iq2jjE58VOA4=; b=nZ7Qmdhgma98gc9wXDat3xcMjOfY6NGQPaSbLMBqYmgTea07AbvlKNzWKT/zrb9Dx6dBRs8DKUJn1vMM3W/Xx/rjX2LTnpvMlcweYUmKT7cQ9CZVdd1HKO8Yp/dlrsVBHEjjXIpB4rBQHxyZ7AmJs1s8Eb84fK20j3nghfA7iKU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586003141304590.7165929835538; Sat, 4 Apr 2020 05:25:41 -0700 (PDT) Received: from localhost ([::1]:38404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhrn-0003P2-36 for importer@patchew.org; Sat, 04 Apr 2020 08:25:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54317) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKhqZ-00024n-CO for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKhqY-00032W-9f for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:23 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:52403 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKhqY-00031s-44 for qemu-devel@nongnu.org; Sat, 04 Apr 2020 08:24:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-348-TkGJ7AS1NduzlbHmanlxCA-1; Sat, 04 Apr 2020 08:24:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2C4E61005513; Sat, 4 Apr 2020 12:24:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-152.ams2.redhat.com [10.36.112.152]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D942E96B7B; Sat, 4 Apr 2020 12:24:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 628A811358AF; Sat, 4 Apr 2020 14:24:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586003061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B7wjwW4kktbArsvMvX1086jM6kTZmn7Iq2jjE58VOA4=; b=a5PsSbyYnw6JDCcBIv2HaIJYpd6g1QuAdS1YV25Lz8c3l3q6Qm/HYYTi6yIJkOQAFLl5HR uQImNtN3Dz7bRRwKZPMNX1FW/gDTOP+ecltuMK1Ik5wPoU8fxMPlpSV74mKi/PzNeCpKaz //HeBmny4kuS39tCA1ayaqOMb0+Wykc= X-MC-Unique: TkGJ7AS1NduzlbHmanlxCA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 3/3] qga/commands-posix: fix use after free of local_err Date: Sat, 4 Apr 2020 14:24:16 +0200 Message-Id: <20200404122416.1837-4-armbru@redhat.com> In-Reply-To: <20200404122416.1837-1-armbru@redhat.com> References: <20200404122416.1837-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Sementsov-Ogievskiy , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy local_err is used several times in guest_suspend(). Setting non-NULL local_err will crash, so let's zero it after freeing. Also fix possible leak of local_err in final if(). Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20200324153630.11882-7-vsementsov@virtuozzo.com> Reviewed-by: Richard Henderson Signed-off-by: Markus Armbruster --- qga/commands-posix.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 93474ff770..cc69b82704 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1773,6 +1773,7 @@ static void guest_suspend(SuspendMode mode, Error **e= rrp) } =20 error_free(local_err); + local_err =3D NULL; =20 if (pmutils_supports_mode(mode, &local_err)) { mode_supported =3D true; @@ -1784,6 +1785,7 @@ static void guest_suspend(SuspendMode mode, Error **e= rrp) } =20 error_free(local_err); + local_err =3D NULL; =20 if (linux_sys_state_supports_mode(mode, &local_err)) { mode_supported =3D true; @@ -1791,6 +1793,7 @@ static void guest_suspend(SuspendMode mode, Error **e= rrp) } =20 if (!mode_supported) { + error_free(local_err); error_setg(errp, "the requested suspend mode is not supported by the gue= st"); } else { --=20 2.21.1