From nobody Mon Feb 9 17:58:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499957477892729.5140165519749; Thu, 13 Jul 2017 07:51:17 -0700 (PDT) Received: from localhost ([::1]:60484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfSV-0000Ql-3w for importer@patchew.org; Thu, 13 Jul 2017 10:51:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVf48-0001d1-AW for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVf42-0003d7-MG for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:04 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34803) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVf42-0003Zi-FL for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:58 -0400 Received: by mail-wr0-f195.google.com with SMTP id k67so9397089wrc.1 for ; Thu, 13 Jul 2017 07:25:58 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id k75sm6042448wmh.10.2017.07.13.07.24.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 07:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v8Ye64ojBmodVoLEiAf8jnorl9/RSRr2e/2Mv26y/FU=; b=i2aS4rlwLX1Y7A55bjn3zTy95j3cf1FEEKlwbR6Pl2h1KG4KYpNDI3hDqq3qlCE5vk fzlw1W57klNCrvShOf7pG8LdzE9o5pAdHQqyXQmyF/4RLAW+LnJvbZ4/pqA4dUvrido9 vqGl/jJfZEX1q4Shxpq5Z2WhNEYFiyg0ns/2jidCW1FlI/4N8vZ+RfiFiIJJqbCwUtKU xvvHuD/c1xT41fSCl3nGh6NtP2lsOilFYuAVzCkfEVFuT/sWkm2Tm4DNOFCU/TEkSffh Wnyhf4bEFe4nsdV6Urgahar8a1hHgkLxvaWjqhXUC+eVLBv29+kPp85XgB2Lno8TduJP zjkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=v8Ye64ojBmodVoLEiAf8jnorl9/RSRr2e/2Mv26y/FU=; b=Jw3zyejeIETKqEuYVmDd47zDXY6k3iGkZcX7LOsuzmKaNYlvRxgAAuoOgN4H2tdqtt mQu6eBQLbUfswhUJKo6OvjMTVkTDKvEee0ZGA98a548asKKFxCdeCxm1U5ccve/ZZDJ9 lhSHxPG9TFfKzJmS29QYI4JufbEUMJC3ST8jZH8TkW2EbO3SY5M+pgoaB2MKYdlUzxFR UIzFcCG/2PoifaA93gvQszQ25LIt5EMbKW/gorHzgxdpd2V1i+L+iNeuyIT77UyqnW71 wR0ZYxAGAE0JG8/jomf8oCYw89c2O/J9KQXb4kA6SztMHW+K/ZjNq95FSs3SCgs91jFs 3SlQ== X-Gm-Message-State: AIVw111YSguPNugE2EscC49rVjay7WN/rAHbe4mrJObnQ1MGPIfE1z5L cgw5Fu2N4o7IVVhHhSw= X-Received: by 10.223.134.157 with SMTP id 29mr2153280wrx.157.1499955897089; Thu, 13 Jul 2017 07:24:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 16:24:04 +0200 Message-Id: <1499955874-10954-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> References: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: 209.85.128.195 Subject: [Qemu-devel] [PULL 11/41] char: forbid direct chardevice access for hotswap devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anton Nefedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Anton Nefedov qemu_chr_fe_get_driver() is unsafe, frontends with hotswap support should not access CharDriver ptr directly as CharDriver might change. Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <1499342940-56739-5-git-send-email-anton.nefedov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- chardev/char-fe.c | 7 +++++++ include/chardev/char-fe.h | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 7054863..de5ba3c 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -179,9 +179,16 @@ void qemu_chr_fe_printf(CharBackend *be, const char *f= mt, ...) =20 Chardev *qemu_chr_fe_get_driver(CharBackend *be) { + /* this is unsafe for the users that support chardev hotswap */ + assert(be->chr_be_change =3D=3D NULL); return be->chr; } =20 +bool qemu_chr_fe_backend_connected(CharBackend *be) +{ + return !!be->chr; +} + bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) { int tag =3D 0; diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index 9f38060..588abed 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -46,10 +46,20 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del); * * Returns the driver associated with a CharBackend or NULL if no * associated Chardev. + * Note: avoid this function as the driver should never be accessed direct= ly, + * especially by the frontends that support chardevice hotswap. + * Consider qemu_chr_fe_backend_connected() to check for driver exis= tence */ Chardev *qemu_chr_fe_get_driver(CharBackend *be); =20 /** + * @qemu_chr_fe_backend_connected: + * + * Returns true if there is a chardevice associated with @be. + */ +bool qemu_chr_fe_backend_connected(CharBackend *be); + +/** * @qemu_chr_fe_set_handlers: * @b: a CharBackend * @fd_can_read: callback to get the amount of data the frontend may --=20 1.8.3.1