From patchwork Fri May 19 12:47:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9737103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B4DE46034C for ; Fri, 19 May 2017 12:49:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A923328929 for ; Fri, 19 May 2017 12:49:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DF6F28932; Fri, 19 May 2017 12:49:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 310DB28929 for ; Fri, 19 May 2017 12:49:33 +0000 (UTC) Received: from localhost ([::1]:58624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhLY-0000gj-AN for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 08:49:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBhK0-0000aD-Cb for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBhJz-0004Jy-JH for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:56 -0400 Received: from mail-eopbgr00136.outbound.protection.outlook.com ([40.107.0.136]:31167 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBhJz-0004AG-BQ for qemu-devel@nongnu.org; Fri, 19 May 2017 08:47:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=dCkinYUMHQJtOxHbRDFwbovkS+KtXIYn4PW9yLFBFr8=; b=VdeWqcLMPCySI9pgGzCI9WlWFOdor2qaxI68Jh5G72haR9/me4qQvKkgUk37p/qm6zO2pmQOsFNU3prVeiLleDam7qQNk2FsgxpGZbg6L17Er90OIe3zNxOtkuR0AK98omPa2LndpWo/IwUG30Cm8FlODeVBFshUVCqIhbB+xk8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by DB6PR0801MB1989.eurprd08.prod.outlook.com (10.168.85.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Fri, 19 May 2017 12:47:51 +0000 From: Anton Nefedov To: Date: Fri, 19 May 2017 15:47:18 +0300 Message-ID: <1495198042-124203-6-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495198042-124203-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1495198042-124203-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR1001CA0002.EURPRD10.PROD.OUTLOOK.COM (10.171.79.12) To DB6PR0801MB1989.eurprd08.prod.outlook.com (10.168.85.150) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB6PR0801MB1989: X-MS-Office365-Filtering-Correlation-Id: 753eb5c9-6343-4496-74b4-08d49eb542ee X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:DB6PR0801MB1989; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 3:eBnIKsjNc+qv6EWw+dx4tdVHnzrRHdBbdlef8opKaI04e6RYBfWyjdMQ8ON9N8MN+msqgpF3w+bNKQ4e2R/xCIyvdRBDXrjYid7HEnjs+cZtCd5yhzeGxWrEAUaaObkgn1KzFq+TL24U9YcrCCJWjy1H0Vhl5YjxQBlW8j2Ng8srf6kogQrxv3fP3PknwHB62Bxdf/dqTfKeUBJHRu6x7arljrHDxWE+bhhcPT8TAt0iuDeJr1ll+7DfBedU9+Lk30YKLkwXb8o4ozOWqkHhcEQkMp/Bu8KzBjKxbUjiIoqc/eAjHB5qv/5T7FyWO2ePyrTZtnN8GsaSRkXRHBJ6Kg==; 25:Dz80T9GiNNNf7Dawq18zOSA8vjGj+93ZXAR/uz1QzQzHZcs8UOHCuvPrZttX+AwEX0KQLWKPQfLaSehZVgcl4TV45XAWi7kOyXBXBjKhg9kLrV3FxU8RgcKVqlwR1MMg1yXDsvyWRbkxGzAJOk2KqnFCSuz5BzlFjIV0uUHLOsp/sDlQMy0XALdOMWW4Y+wmtmnRXnk6Iq1sGmVK8ZNL5ZjccAsS4RmD8FnQEUccrxEFwRVCBPT3Qb51ooiBhQiyZJaTlzeeefE3bfMOj54/J3Gx57njvPmWo7Uf/Dnjg776jisgrkPz7OZP2t4ocldF8WgmrgIwGImhGj/zgtUvucrFLub/+gcqHACckszYmfXCQRewiVgXwRV8VZPY84sKC64pPE7Eqpw0magYA9vm65ZDfSELagAkZhDMOMU4fhAMav9X8OJFfjww7+E8vPnA7gunhfi9oZpjr/o6aKYEtKJnx0x5Kr7sqk5uf08CAcw= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 31:ZunRnNhbAXUu2VMqZpwFWtskqdjAeWIjqiAWh85IT5uWfcdJWRNAqmGkCWTCaJAtT9gxsIEZXDoF1hF+w54ViyD27lmUFfkUMeLcyzILY1m9hiXaL2kzgP+xL5t8LuzWsuHmzd5mTsMBSsUXzZfvQ7p2GA0KIzXjVaR15pVZf46xVwODIakW54u+GLnT6juoNB9y3rgqWAISINua+vEYnN9XVsk8bN7C72u6/WQ5zQQ=; 20:8DBJpE81LR7Ah1bqHSYqY9fZjsCvCU682Vo4Vfvetl4sm+QawqL8ni2FlKHNiecDoAxmQqcj+tGuN+l7dGU1pP6bXFZaOzQ1YgCnks7eZGiwOBKQXt4SJmIdIbgnWEPCUYOh19OjBoWYMv4kqUfBXpdQ4klxZrNEoZJRD2VvIqbnKSQOMohZh3eshjwp0HDSOUMCnOJcUZ9w8hkQSxyX2br6EW5WPS15TqXPWJiJJuNuQHpMENCSS2XE/7D+n8iuV0I27RITJR6tg34lY7Ev9lWreAcHc4vsyj7JvG9yAcMmcgvfXl73DBtmLTTpOZCQfzuticC6DCSZfb+ABjxMl6JAr0C2gLCRpdCGazmR0WeH+Hu+ZniDIua8SWQ5Np71zmElhyD1IO2p8iQgMuH8o+BXushcOj8MbCGkWTbIyB0= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(6041248)(20161123560025)(20161123555025)(20161123558100)(20161123562025)(20161123564025)(201703131423075)(201703061421075)(6072148); SRVR:DB6PR0801MB1989; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1989; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 4:1f9loUMZVOXbQfx01293XATtrRRhCa5NYpO4KqZgPZwFff+waas/5aYEKkVKvbF+Ip2p9gTI+i53QB5ykn9ZxDWcJ0+1ARO7huaz9qeuiXDC7XPz3sZ/+gEEVIWiIwMI9KHJFXMMXLvs2D4h2r4+VeWNpOdJA16KCV75ldJ9Uy0il1nCh1CqIuJYIDbDrRQVeEfOxdH966AEF+ok4fABdOm/ap9It+Vy9bo+gOCaG/rFJ1fbMxngND9LgIvND0cmIpQqy2HcQUPib/amT1ouNeN5hZsxBvw9MQ5ci+7BJUumD3vrWLHQmiWO3Y1JSCKDr1VXqhah69u3NcsCxJNDdHIbR8Hd0h5GK9eS9Xo4ZyCFzzKqNijJsBPs605XHuEcS5gYtpjGxlSLu/1/Oi4ataJQjPgCQObG23/uTQwco+9vSB3GSp6AoDlIvwATEohBamg2cmm/eKXU+fBEzxB8wMyWvLAOJY1rVwKjIQ6Rc+R78h9xjHUBk/FdzdLJE/WLW41hr9WHvE9le3+VEi8o354hh0KEjy53rPSy769MDHAI+II8U2ryQaQAma0dHQT8qh8NhneCxHTejtIJkVLjlU3u6Xvml3ntFn4oOzmF5yiP8dGyrFlYVQMkfxarzUm9YJGdyaHMopJCQULn0to1al6EFSTUSyhwBU4FZFTyRe5JMLv0+oNarz8Geo3FCfejhjCqfx4wfozQD+AhsclTSg== X-Forefront-PRVS: 031257FE13 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39400400002)(39450400003)(33646002)(48376002)(5003940100001)(53936002)(38730400002)(25786009)(2351001)(6506006)(6486002)(107886003)(4326008)(110136004)(5660300001)(36756003)(7736002)(6916009)(2950100002)(305945005)(6666003)(66066001)(2906002)(189998001)(50226002)(50466002)(54906002)(508600001)(86362001)(6512007)(81166006)(8676002)(50986999)(53416004)(3846002)(76176999)(42186005); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0801MB1989; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0801MB1989; 23:gzfOkVaZb+FSMmREfaptDm8rkozs+7/WUyeJ3aR?= =?us-ascii?Q?XKnJ1b/lPOx5hseg7IJhSX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q?LzD09A011ao7O79PG/qqITGu1I/mUzOYEphr3iEeiWYCHxOfcZrBH3i1FcUa?= =?us-ascii?Q?o/Tw=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 6:SFP45ZTZe7PX8jixk7ewmXlVzKBSfW0rFS3k5Vt+iD7CctFyXBqSlESRJZfhzefeUye9ljTtdKmD6mkNHFWxQMC5HoNUX6Uj3tElKC3zbNQNTCHjYKuFCo574+VaZWOmZDyIKbyM/DUgerHeaGtRlXxVAr01TPvLAxfyB2Sb7Zg+fOc4bA28Of4HDOs1n/fZBtGFkGBABIsGaHss9wClz7HmE0FkXrlT9onF7Y2IrbmwvDSH9YTvV++tM1ufeJZpZ9qf3EQ8AbnETIgmgK3LbQn1EpwyUx770PCB4qbShewCKS2yHscI3uPuRfbJFi/eP7R/OjEYm+LIXd0urlf2boe9t2Cxo9KHS1Z0sHPNjc8Jez13dyIQ92icgiMoMUmvclTkKnx4mmELWatW8gX6EF/RqCGR2mdNsd/F6v23Mun+ZCT9FUOnc2+RE3K7KuBPWLTEWhtf69hCX/KLKo2ZrI55g2k9w0ZtDSIVnW7xLkvDNgrnyx3TjuTTP/BQbadddqwQZyYbwG+Eq/mTmZNMtA==; 5:xRWdmi9pC0+83H8igeBAvAKHzra9fbXB81jRHeFAG56q0ikzB9GJDRzS2pGYGczksABNtL+khYdCdIcYXsJWhMUy0LY4wiw5Y6CQA4HJxgloJFTow2j3iKSEmkzdK4M9UTqKO7Q81C6YRJQv4DFInw==; 24:+7ptGnhrnu3VelfaIU4T7H3m7hIsgBQQoso0iSZ85lRcNP/QeXvifY+oLse+0izsv9ngMfm1ZA3+o1JSQoHdv6E3LbazfI42EAV1W0PgIcs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1989; 7:e7RcpHXU6Z2sHmJzLbwlMYuw0UWTnCgrswd17ASbnhRyxzQbl+qU4mydJNCbU3BV+pvgvexDJZWZMpkV54TJ5Tbw2shVHArmaC6Vxor5UiyEeCqAcpUODFPIgdaD2JvnTXwUD6OtR8WLznlgOoUwfU9WE2un6Roolr3zPVWwuTDbdTYs3L+bGhCDf+UsZNmmOHfQ7oA8/2mtW8becZw56Jdyai50MjI+X2bxE6pK9j6YWIA9zLihAMdTdfPSufjTFIDoe2mlTEBRja8FPYxJaDHRJlJPXVDaGDdFuYSrATC8vl0H9q0G28GJShm3W034EQ9HIsZgV2bf9a1eoWRMcg==; 20:Inp7sLCjUk6+8n9on7OhmCGFIvr8BrrVO9A9YKGURpuFrFNNfkx8lJxOL1Y0mHodMJZbGt9dT4Hd6e71hwQUKtmK30z2wRXVp+NkNLSW9nlKq/v7LNkBq4QzZ2KIyskhnxl+3+yifjBGbLiao+mW1rlM7A1cuZgN7ikgR2GMZbE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2017 12:47:51.0801 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1989 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.0.136 Subject: [Qemu-devel] [PATCH v2 5/9] 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: pbonzini@redhat.com, Anton Nefedov , den@virtuozzo.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Anton Nefedov --- chardev/char.c | 7 +++++++ include/sysemu/char.h | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/chardev/char.c b/chardev/char.c index 0483f19..36d6f36 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -484,9 +484,16 @@ static Notifier muxes_realize_notify = { Chardev *qemu_chr_fe_get_driver(CharBackend *be) { + /* this is unsafe for the users that support chardev hotswap */ + assert(be->chr_be_change == NULL); return be->chr; } +bool qemu_chr_fe_backend_connected(CharBackend *be) +{ + return !!be->chr; +} + static bool fe_connect(CharBackend *b, Chardev *s, Error **errp) { int tag = 0; diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 92ae57e..fa21535 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -404,10 +404,20 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp); * * Returns the driver associated with a CharBackend or NULL if no * associated Chardev. + * Note: avoid this function as the driver should never be accessed directly, + * especially by the frontends that support chardevice hotswap. + * Consider qemu_chr_fe_backend_connected() to check for driver existence */ Chardev *qemu_chr_fe_get_driver(CharBackend *be); /** + * @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_deinit: * * Dissociate the CharBackend from the Chardev.