From nobody Fri May 17 03:54:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604404484; cv=none; d=zohomail.com; s=zohoarc; b=SIvn52fr4aawgZehqfMV8wQDSpGHhRhySEpWsa5EbITcbLceQIVW+OJQeUtu/oo4o1GmtiBw51mXSnBcB5eCMiTNswQJwxlHcTWEohlZF0KKqd1nKIdD68je4MEgQdTGCCNp9mw+mIYm5egq4AqssNjQxlp/Ezjllm+mLMCW8AA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604404484; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ngJheC9QZOVPanmRgme/165PV51CnDzzeIFAgC08HO0=; b=efbm5S9G9P43jTjbTH3MgLy/KT9gZJ1Vww666xdohARGHDwRk9r0+YMuMilcHc492NiIWaQ7iGBmTTTB5bgFUkNNp8mjvEs9PDDGfUOLDyr5JgMU8sYyNGnePUr6XXpw16X0DcvFZ+NxjaWFc1739DQfFCJPfPurL/LdFhpPP7Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1604404484669947.3548425306085; Tue, 3 Nov 2020 03:54:44 -0800 (PST) Received: from localhost ([::1]:41390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZutf-0007vL-BT for importer@patchew.org; Tue, 03 Nov 2020 06:54:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZus3-0006hx-Hv for qemu-devel@nongnu.org; Tue, 03 Nov 2020 06:53:03 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51953) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kZus1-0007Ft-9X for qemu-devel@nongnu.org; Tue, 03 Nov 2020 06:53:03 -0500 Received: by mail-wm1-x341.google.com with SMTP id v5so12428043wmh.1 for ; Tue, 03 Nov 2020 03:53:00 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id g138sm2621092wme.39.2020.11.03.03.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 03:52:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ngJheC9QZOVPanmRgme/165PV51CnDzzeIFAgC08HO0=; b=VilcuFdls26gLVgsa91KRKORdtXWWIpogLXNC2OYGmOLyz3H3G4gQLlsDWF0lDsBab aXMRduQD2xWW+U9EDESQRXq3Tm+ZQmwOjWSipZJTNxGFPxig//MCJcPwBMDx9m2IJ3nl DliepYV8Z6+pjt47ciGaBYxQ6hKpm/E5+H0rS+7JnzRAWjSPHToviyuBqTfZg8IYa8m/ NHRMk0L1y4U4fVvsFSlYtIuNLyHcwZwlrve8ykfiek2t4fbh/pzL+MRArVinEkWwhozn 0Lzn+SooZP6/F7B1wMFy10JXYV/EpzZISNjXUPbuhd2NgExcSTf0+E+8TW6yGjA0M6PC UQbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ngJheC9QZOVPanmRgme/165PV51CnDzzeIFAgC08HO0=; b=aL38Jl90knHMz9JpRtd0wCxaDkTHeE4T1fRI1LqRrgsDNWbP0UUUgnJIDgk891FH32 k62mvKc/Yp0299W+JYt2O9/LVUYJS2otzWhuDnWlPOGeY0FGIpRRoluOAH0pW/iYmg1h xJFMzwA6cr1oN8hE/+blHbcd14QyRtqbvEYt31mt/ULRA3FFNohe/JPm+urfHgtHxn8F VytF5fcrJO9llTBiX48lOFp1L0caeMps9ob56ViE2YFhKS/1xGBj+CYHRgDKSlgxruwu mNidY8Zbn7GtmhJKtYsbfGVrJFP5h6CDiu5TwEM2p+BATByBbLg7PMvV8QmmIyAwDZ6x ykhw== X-Gm-Message-State: AOAM533M36jWwdy0dh7sgAqyirReHA0Wp2xoqHhuyv1I6e0hPTwMtdO3 ll3sYY0RoXOk+mFKyyW4tePuadqekthayA== X-Google-Smtp-Source: ABdhPJz5UhJkBt0isXuGzCsNnRv7KPfpamfvvZb0Vdy13vZV0wRy7IN4ICwYuy0nx90PWB+SxJjeBg== X-Received: by 2002:a1c:bbc4:: with SMTP id l187mr3360224wmf.133.1604404379539; Tue, 03 Nov 2020 03:52:59 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH] tests/qtest/libqos/ahci.c: Avoid NULL dereference in ahci_exec() Date: Tue, 3 Nov 2020 11:52:57 +0000 Message-Id: <20201103115257.23623-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::341; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Laurent Vivier , Paolo Bonzini , Thomas Huth , John Snow , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In ahci_exec() we attempt to permit the caller to pass a NULL pointer for opts_in (in which case we use a default set of options). However although we check for NULL when setting up the opts variable at the top of the function, we unconditionally dereference opts_in at the end of the function as part of freeing the opts->buffer. Switch to checking whether the final buffer is the same as the buffer we started with, instead of assuming the value we started with is always opts_in->buffer. At the moment all the callers pass a non-NULL opts argument, so we never saw any crashes in practice. Fixes: Coverity CID 1432302 Signed-off-by: Peter Maydell --- tests/qtest/libqos/ahci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c index 2946abc15ae..fba3e7a954e 100644 --- a/tests/qtest/libqos/ahci.c +++ b/tests/qtest/libqos/ahci.c @@ -637,10 +637,13 @@ void ahci_exec(AHCIQState *ahci, uint8_t port, AHCICommand *cmd; int rc; AHCIOpts *opts; + uint64_t buffer_in; =20 opts =3D g_memdup((opts_in =3D=3D NULL ? &default_opts : opts_in), sizeof(AHCIOpts)); =20 + buffer_in =3D opts->buffer; + /* No guest buffer provided, create one. */ if (opts->size && !opts->buffer) { opts->buffer =3D ahci_alloc(ahci, opts->size); @@ -686,7 +689,7 @@ void ahci_exec(AHCIQState *ahci, uint8_t port, g_assert_cmpint(rc, =3D=3D, 0); } ahci_command_free(cmd); - if (opts->buffer !=3D opts_in->buffer) { + if (opts->buffer !=3D buffer_in) { ahci_free(ahci, opts->buffer); } g_free(opts); --=20 2.20.1