From nobody Sun Nov 24 06:50:20 2024 Delivered-To: importer@patchew.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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1724819689; cv=none; d=zohomail.com; s=zohoarc; b=AlWroh/pkcudMLQJeVwPOUHlK/kdM3MC6Ri1ynVIvoYsCKE/QlGxtWFhrnvVYuiW7K1IymRYRG9iBMOZnV+W3t/Mr+nHRw3IICV9xLyDhTT5gJqS8H2TI5/JW8XQOqlyDchlrrfMialwd8DN/bbkY8vRObDkXcQ85FEdrBXcs2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724819689; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GmKSAgPdEuaidN129B+a5rF+PXzuWPo3dTfBM5ZgjWs=; b=Mn19Fmkbg/Ctw3suicxXISDt83y94txgvA3tQRHZIysCTCqtpd+BACTDJDxRfy+pbUWbp9CbT3dNj9N2Ds8zmAO0BTtQ/wXnqP/gq59WhaORmEDM8H04hGLKcf95Z1W8QoGfpDdTIA6YEdlf4GbJcNMaY/UL8A4qx9Afa19e5Wc= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724819689925385.83218479794107; Tue, 27 Aug 2024 21:34:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjANZ-0000Rv-Bs; Wed, 28 Aug 2024 00:33:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjANU-0000JM-6d for qemu-devel@nongnu.org; Wed, 28 Aug 2024 00:33:53 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjANS-0002dM-Nk for qemu-devel@nongnu.org; Wed, 28 Aug 2024 00:33:51 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-202089e57d8so1449805ad.0 for ; Tue, 27 Aug 2024 21:33:50 -0700 (PDT) Received: from wheely.local0.net ([1.146.81.12]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038557f093sm90342325ad.63.2024.08.27.21.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 21:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724819629; x=1725424429; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GmKSAgPdEuaidN129B+a5rF+PXzuWPo3dTfBM5ZgjWs=; b=kQt11aAOScD633YQwvKEhRWWGmXj65F9S7g3TMhgNjzdS1w6Lcvr//hhs/iyaA27lQ O/iosPwMcCQVW4OAlTubBpJArXJmyfMaBmt4hmOWJyWjQKWbkh8v55GyAsD2tPmCGljp 7qRL2qPi9XWf0HXx7ppS/7yWpy3mugpxr+U5MWB2uL8XmxiOeZ03hPJ9ugeQuadSjuud q8Oas05tTMuFAA8KBlKfwjD94nzK0wcCUmkCF084vg8J4Y1sJspMwuZWLISXk9ED35aA +dhBuRj3RVKGXlzE4E4QnOJ2b1PUNdSAuMsO22M/1qINFUr9GMUvhOBcuv4zPxzxy/3d wFqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724819629; x=1725424429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GmKSAgPdEuaidN129B+a5rF+PXzuWPo3dTfBM5ZgjWs=; b=RVIOwGI6W4lFZxW9j2FH8M/kiATygiHAUcAxcnlYTizbU7d302QRXr3oK0N1w+7t9i DZMVqp/vDxjjBccSV47cs7EPS3dsmCvs7XiY9rsSV54Z9Jtbi8acfX7I3I5NCEfunLPl jSq7fAsx5I8wGhoU+KEYgwKhoQH4aLJPBx+TDU09ht6SfZ4U7CfdeZxp3mkPTldierh1 dfKl++I1Vo4V/cFahAsDr3pOHKlR8GdaVqWudic5p4Mrh+9ccz7AmXzFCxV8phxfD6p2 +fdg46XwDBZxYRvhFsBDjLexw7VYtVpsWBtIE8CzqcoSNEXrZgo4v8p8JLdZtcxBqaOX Eihg== X-Forwarded-Encrypted: i=1; AJvYcCW7LF9SB01FGFeiyUv06Jo2fBuLd2eAI/g/Z0zDNlKcZru0mNWtxmAqKG8/Ad/NaRCmgbtkipUXT5VA@nongnu.org X-Gm-Message-State: AOJu0YwNzsJcml7sVlzzWsdyEf+Wb47XgAG19dnrPuykaI8P0h9H3cPP E1LpGKgGwwBAidf+kJrdmv0WEZ0klhIXomzg94JOuR88U0VEO/Le8wcHxg== X-Google-Smtp-Source: AGHT+IHQ0pMWGdx7R1XbhTeblGbSI5nEVdA5B7wefCynXbSADfKkbdv3jVHfz82jlKKiVYNmtui0Tg== X-Received: by 2002:a17:902:e542:b0:1fb:77e7:27b2 with SMTP id d9443c01a7336-204f9bd573bmr11133225ad.18.1724819629299; Tue, 27 Aug 2024 21:33:49 -0700 (PDT) From: Nicholas Piggin To: Peter Maydell Cc: Nicholas Piggin , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org Subject: [PATCH 1/2] chardev: Fix record/replay error path NULL deref in device creation Date: Wed, 28 Aug 2024 14:33:34 +1000 Message-ID: <20240828043337.14587-2-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240828043337.14587-1-npiggin@gmail.com> References: <20240828043337.14587-1-npiggin@gmail.com> 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=2607:f8b0:4864:20::62d; envelope-from=npiggin@gmail.com; helo=mail-pl1-x62d.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1724819691527116600 Content-Type: text/plain; charset="utf-8" qemu_chardev_set_replay() was being called in chardev creation to set up replay parameters even if the chardev is NULL. A segfault can be reproduced by specifying '-serial chardev:bad' with an rr=3Drecord mode. Fix this with a NULL pointer check. Reported-by: Peter Maydell Resolves: Coverity CID 1559470 Fixes: 4c193bb129dae ("chardev: set record/replay on the base device of a m= uxed device") Signed-off-by: Nicholas Piggin Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Peter Maydell --- chardev/char.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chardev/char.c b/chardev/char.c index ba847b6e9e..47a744ebeb 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -721,7 +721,7 @@ static Chardev *__qemu_chr_new(const char *label, const= char *filename, =20 if (strstart(filename, "chardev:", &p)) { chr =3D qemu_chr_find(p); - if (replay) { + if (replay && chr) { qemu_chardev_set_replay(chr, &err); if (err) { error_report_err(err); --=20 2.45.2 From nobody Sun Nov 24 06:50:20 2024 Delivered-To: importer@patchew.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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1724819681; cv=none; d=zohomail.com; s=zohoarc; b=TXqIshciwNzQoNsCEl3y6Fyw8oqw7M/DMl1QAYvRBnb82/yqI+vPx3OltfHAvfHKca9WrXVnkLF4lTDqxUgLbaxMWE1icGvtUhUa7suzZz9lVf5hsK/tegZhJO6wfJEQbHnf49BrrpI7h8KHZWyKj2C/i85Zm439WJb3dTDD7x8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724819681; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2zdwiYqr0w43Mh87Wpao4Jr5QC0LLctdaAixHY2H6x0=; b=KESHLd1kZZ/UkB6mPR2ISNV4RDMGV7WZsePLNsaCUhPsg0w5NMs2TTPTNkGupon3Gkm+X1qNpCsm52AdICKFF6ymhTCWQLKO1pY9zsUHYWeODUaYfdm7XgIbQaCzvvjLSZonaC4a6o3MDsx6jlkBJrJizIfXTDnDoNmkdoutBy8= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724819681209234.08825222334883; Tue, 27 Aug 2024 21:34:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjANc-0000cR-Ei; Wed, 28 Aug 2024 00:34:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjANZ-0000UY-Tl for qemu-devel@nongnu.org; Wed, 28 Aug 2024 00:33:57 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjANW-0002dr-90 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 00:33:57 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2025031eb60so55112375ad.3 for ; Tue, 27 Aug 2024 21:33:53 -0700 (PDT) Received: from wheely.local0.net ([1.146.81.12]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038557f093sm90342325ad.63.2024.08.27.21.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 21:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724819633; x=1725424433; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2zdwiYqr0w43Mh87Wpao4Jr5QC0LLctdaAixHY2H6x0=; b=YhIstGaSHMGvaNnY79jMN+EuraAGwUV3AQMvlXVUvTfb9TWHFPfGC4zNugCTuy2+Nm VFOPKEBloi86sQtehZlj1fdniZeDZ2DcFADWhdkx5lEvI+yE2eDcFLB618VTmZGf5PMs wC0ErXDm5Vls8yoAoYG4F1RcEvXkyLQA0K/9O4RXYiFlkhgJ6IAtcedOPrXgZByg6S/E AgHOPC/xC1QbGwaJKx7qwN6tv5suZFu/dHM+yJBct7iHAUaNSOnlCkXljF3AS3JCNSVo YWg+PjW4Ze8Fnq6Z3HKM2fR7QOpDzxSC0kzXUEhUzIfH10EPs5JvB8BjXRax/0ucnEU7 2xmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724819633; x=1725424433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2zdwiYqr0w43Mh87Wpao4Jr5QC0LLctdaAixHY2H6x0=; b=UYq+T0GJFgiAIbzuZX3bE0rdEYTLKjQDGJWg/Z7nXwVpqVmgoQ7U0UBFxsm57DBMEy 7abm6TO1yoh8cM5DQ/FHKXbrqYLykxKHqt4DgdpZ49mzPA47jDOwDON4Vp84Kl0ZL1o9 e+2yQMnLNmw3TjPEDuJLP1bh53AKCQ7keui/D5VTC/pAoLFDHc+8RDKmZzI+riqdPdWI FmPebZjc9GbPwjxqiQ1kpZGWtj8tubV5LB18owjbUiZAQCWZzN7NybHuojibc2EgkKnG OXQ1yhsOq8WIkW5rAPIYTo6fvIdFrS8f3wXv2HRR8HRpp7ZJVLEj84B2G3+lf8V1nZSY RXbg== X-Forwarded-Encrypted: i=1; AJvYcCWgEobRSoq/7uKFPJNebIzLxGvh9A/xOx2TgwVWOUjLgKJ38HO2ejzGOCArP1cAIP1PdIQaycy8bfo3@nongnu.org X-Gm-Message-State: AOJu0Yz1/szWQY7oS9/eJsrDyVybuGPbc9gsE2SqDws578lMbeT4qdp6 0LmlLTxQYfGuRq+2yjaOx5IaS49NXg5Bx9jvfUV3xScr9W51dK7yKmznKg== X-Google-Smtp-Source: AGHT+IFZA5Iy+G9nCiHF97A2dmNLj29tq3TCYXByNxHVlAcV8NNtXxAY+lmKBMcRTX95kK1hz2Xnzg== X-Received: by 2002:a17:902:d509:b0:201:f409:ce73 with SMTP id d9443c01a7336-2039e545857mr147447095ad.65.1724819633014; Tue, 27 Aug 2024 21:33:53 -0700 (PDT) From: Nicholas Piggin To: Peter Maydell Cc: Nicholas Piggin , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org Subject: [PATCH 2/2] chardev: Remove __-prefixed names Date: Wed, 28 Aug 2024 14:33:35 +1000 Message-ID: <20240828043337.14587-3-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240828043337.14587-1-npiggin@gmail.com> References: <20240828043337.14587-1-npiggin@gmail.com> 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=2607:f8b0:4864:20::634; envelope-from=npiggin@gmail.com; helo=mail-pl1-x634.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1724819681838116600 Content-Type: text/plain; charset="utf-8" Peter points out double underscore prefix names tend to be reserved for the system. Clean these up. Suggested-by: Peter Maydell Signed-off-by: Nicholas Piggin Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Peter Maydell --- chardev/char.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 47a744ebeb..46d4798e4e 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -628,8 +628,8 @@ static void qemu_chardev_set_replay(Chardev *chr, Error= **errp) } } =20 -static Chardev *__qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *con= text, - bool replay, Error **errp) +static Chardev *do_qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *co= ntext, + bool replay, Error **errp) { const ChardevClass *cc; Chardev *base =3D NULL, *chr =3D NULL; @@ -707,12 +707,12 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMain= Context *context, Error **errp) { /* XXX: should this really not record/replay? */ - return __qemu_chr_new_from_opts(opts, context, false, errp); + return do_qemu_chr_new_from_opts(opts, context, false, errp); } =20 -static Chardev *__qemu_chr_new(const char *label, const char *filename, - bool permit_mux_mon, GMainContext *context, - bool replay) +static Chardev *qemu_chr_new_from_name(const char *label, const char *file= name, + bool permit_mux_mon, + GMainContext *context, bool replay) { const char *p; Chardev *chr; @@ -735,7 +735,7 @@ static Chardev *__qemu_chr_new(const char *label, const= char *filename, if (!opts) return NULL; =20 - chr =3D __qemu_chr_new_from_opts(opts, context, replay, &err); + chr =3D do_qemu_chr_new_from_opts(opts, context, replay, &err); if (!chr) { error_report_err(err); goto out; @@ -760,7 +760,8 @@ out: Chardev *qemu_chr_new_noreplay(const char *label, const char *filename, bool permit_mux_mon, GMainContext *context) { - return __qemu_chr_new(label, filename, permit_mux_mon, context, false); + return qemu_chr_new_from_name(label, filename, permit_mux_mon, context, + false); } =20 static Chardev *qemu_chr_new_permit_mux_mon(const char *label, @@ -768,7 +769,8 @@ static Chardev *qemu_chr_new_permit_mux_mon(const char = *label, bool permit_mux_mon, GMainContext *context) { - return __qemu_chr_new(label, filename, permit_mux_mon, context, true); + return qemu_chr_new_from_name(label, filename, permit_mux_mon, context, + true); } =20 Chardev *qemu_chr_new(const char *label, const char *filename, --=20 2.45.2