From patchwork Tue May 30 13:57:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9754665 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 CBC7B602B9 for ; Tue, 30 May 2017 14:14:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE3461FF35 for ; Tue, 30 May 2017 14:14:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2F152684F; Tue, 30 May 2017 14:14:05 +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 C7F6F1FF35 for ; Tue, 30 May 2017 14:14:03 +0000 (UTC) Received: from localhost ([::1]:54060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFhuM-0000VF-Of for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 May 2017 10:14:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFhfP-0004wu-GU for qemu-devel@nongnu.org; Tue, 30 May 2017 09:58:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFhfL-0007Dq-0G for qemu-devel@nongnu.org; Tue, 30 May 2017 09:58:35 -0400 Received: from mail-he1eur01on0114.outbound.protection.outlook.com ([104.47.0.114]:16853 helo=EUR01-HE1-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 1dFhfK-0007DL-KU for qemu-devel@nongnu.org; Tue, 30 May 2017 09:58:30 -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=lHuL5UqfxuEN1FuAb2jCpF9T3fFGrEjc1IcwJA5+XFU=; b=hXhsHSX4IHYuNsCCHzF2rHOFDb5PCg85b+1U0rrVYH+i+DQhKBeIBLtgHlrvoRxGQzijXDRZQE1ZrEt4L0d/IIWGkW4iMwfCUiJxotzPvJSLx63YPKFW2euFrE6b2KSkQh/wdnyGfWPx/5Xa4/IfGsJSTRbQVbZ/I5yFI2ecgJM= 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 HE1PR0801MB1993.eurprd08.prod.outlook.com (2603:10a6:3:4f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Tue, 30 May 2017 13:58:27 +0000 From: Anton Nefedov To: Date: Tue, 30 May 2017 16:57:54 +0300 Message-ID: <1496152683-102751-5-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496152683-102751-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1496152683-102751-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR02CA0033.eurprd02.prod.outlook.com (2603:10a6:6:15::46) To HE1PR0801MB1993.eurprd08.prod.outlook.com (2603:10a6:3:4f::23) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0801MB1993: X-MS-Office365-Filtering-Correlation-Id: 5230f208-f225-478f-5de7-08d4a763f2d4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:HE1PR0801MB1993; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 3:BbqLwWFZZXuJj4XRRxtN/lxU30WYo20HKws+HenG0+lwbd9yU79LW/pX6AmEenUihPvSrRyXxr3OLZ4F1jWqC3BMdFZ4PYacB3TF0a4Ao06jPcG/pOcisrlsbZE4ctRqo5RhZw1XKP3WPT7PktIWBmL2QqhLmIDYW6CUqEw8I0awif9U4h0i7vffF/nfK62Ha9jC68MmWoHJTO78tQTa0/wrqhQ5hrxJgqRrBh3fiw3qFPobXxP9sTT2QNF3ClEcpwfagiW0clgcLkoD/XD9kFcbicYg9W4pzbpSmMosH/gVRziwWPMMHWOdzbcW64+H3AXBnDseZrLx07YI3Q5ESQ==; 25:kRLUDBPBDxt3VytHVTdCA9SrCYyUqddNXnUcBu7VwqRQBudgurKPj6L/w50XbjJyGqPS1FXsKrOeBMgdwSn+v0S3SNOudtGpMVxlvTml/PwbEJ9yWFqCJCMliumGeawLQ51gdl9jLB6LzEpbQGmGXZqzilijP8MjPrcXPFyxSmNIEi5RqnYrOxg29NN2MRTmGoXCqWZEJQZsDSF8Gx3b9UeTuiARSzxdMIjm8sxDmo9pq2w5Wl0b18Xcmbj0HNPctVcZe7i70VDNoGdHFjEc2rewk7OPfZ9VXQ3nkgI1AbsvWFNr+beXvVwuQeOY1EyvbBArdNJM0z/bqAvzhfiAQyQEkwwxswr4IDpxCdntu23ocvDzwhDOWrvKlA/hgyQvnpornGY6eULcAzwMMSSLKcvw/5cEog9lwX25xBCdzkHUdAgaLUtUqbN+7+bWej1ltya3EARGmCDlNwzy0V+YinAq0imRwuVmALh08UMksZQ= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 31:8/DMRB8+C+wKlqR5IrUKr6NEoXaYA+ApPmNrW4Ub54UoENQaDyYyx7e1RcQBazbEjyTAAMstLs4B64fKxN5tFl6YGT3EXpfELZ+/3x3lVz2cZYYLsVtFcCkgN7v3Lkk8BiLZB6TMIRa+T9KHKks6+uVf2yNoUUwJLmM6PFg2XSpkgH0kaLiw7e67HNd2bdOWwgXBTZ3Vj37rbA8Hv0ycanXTLD0ACQ2tkbDlQm8FaoI=; 20:djKc1em8BYpsNN0FoVpi1CPgIlgj3c0vlepHD4UVF48rbQR8mc3Czx7m2pdBdUoAh753dVngDRFRbVillTJ3HUNR5K4ndcbEKN8pFZTAUx1OFfX46kdnP7mDZ8QWVa04NG7gZOw8j0qUECo9JrcIWmVrnJaJNkrsx58nPlLiJ9/gd9cBbdy81xglMXqmaXBIYDH2M5pyj9hfBr6zirjau4qOdDGG1jJU8IdUgsQNpSN4Pxutofb2tWK3o2hgQAYMYBXpk9brEWy1b053USJx2fBNmv+zdV3jiBnBM233ZfJqf46eAb+kVF96n50CwReJ+eO/VHvvL6zdMSIVjjPvkmEDeNMz4u1yOnkITnNOilOQajw18f1XeN3irv7ribeYkP/eSwOZKZohhFTK+yzBS3CfVnVXBB//ZliPtA62f2E= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700073)(100105000095)(100000701073)(100105300095)(100000702073)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(100000703073)(100105400095)(10201501046)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123562025)(20161123558100)(20161123555025)(6072148)(100000704073)(100105200095)(100000705073)(100105500095); SRVR:HE1PR0801MB1993; BCL:0; PCL:0; RULEID:(100000800073)(100110000095)(100000801073)(100110300095)(100000802073)(100110100095)(100000803073)(100110400095)(100000804073)(100110200095)(100000805073)(100110500095); SRVR:HE1PR0801MB1993; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0801MB1993; 4:XOmQv7cYUUl0ItCCM67X5rV7pY92+pgedNNwRkwZ?= =?us-ascii?Q?ZJm1mmnFI+gtEi30PDuwJXnGesiQvYIoJf1qki71eR/8v0J2/qV+LV40H2Dr?= =?us-ascii?Q?3f08UMHgqKWH64Z8dhBeiJT/t1T712RHqomOGsleG0VjpfJKtBKm3uvGNywW?= =?us-ascii?Q?zvN9Yk7mAKOMOqOBbLI5Q/tfcnUCNftQIFYMIWrVrfHvJMsSFphKKsj6G8sN?= =?us-ascii?Q?Bsd+2/m+Ppgu3M2WB0mFOb9ZYJYVmZbN1Hsuy1eHlXdhv42ebMB0hXALc9cM?= =?us-ascii?Q?Tl6d8QOLhTNV3f1xfhxAxQklHAm0IEhhzS13wIwAev/2KXao3X2am39IUoTg?= =?us-ascii?Q?mDHwiHiDvOdh31kLUYKRmMrEkTZDZFFfhMQpojIHbLzJR1Cmnl4QPoeLj5uM?= =?us-ascii?Q?/ZZ45mtQ27l3IEDGdTnE2zD72b5D2u9YpZDOj/3fFNComafNyDrohU0vG3su?= =?us-ascii?Q?y0egicrOqfjegY1A1TwH168Y6SazUEgB6W6tnz6wiGEE0NdKgBHrX4rtsIEo?= =?us-ascii?Q?Izqt3WKXotf2M4XZq0g7+zict0lw3xSteedFvzLMBwp0v414QrOKKXtAlgEd?= =?us-ascii?Q?sYOcp4nhH0fAZHX7f59YhLcHNpSr0/jSbMm0t/baIPSksYjZfbmOfypa/tQk?= =?us-ascii?Q?HbEAJZ/aaBk4P3pdZeAuFoXLme7irkUdmjhqTTyoH4XWRKmTOY6OJvsSvlI3?= =?us-ascii?Q?fpI8vSMfs8Qb113nhYicGH3Yw8cPvaVY/CxkUVzl3wOKihs+9y02zjwZQJoV?= =?us-ascii?Q?nXt26bkVxiPBUKdMmmI828flcL+c1n7n1la+Q3blcOzo9kereKUt15s6Ghc0?= =?us-ascii?Q?0XmddHlR/7RLHzSkGjNusHWFH8/N3uNuxJXsa80ioT/G3uLvdPXeSumiR8Ng?= =?us-ascii?Q?eu/iuoTgNbi8BRnVVP0LZgHyJrDsSQr2uYK8uSKtO8jIQfILbblGx/lfurOH?= =?us-ascii?Q?Vz4Qzk0LU55YT33P9m7w5t6R93Fq7eJfZ2mTOE/as/81CAL7qN6NojdNiait?= =?us-ascii?Q?1RqaaHHwrRM+7XuvQyA0Nk7uVCVWtOomlTE2aOfCPP3ZlOtH0y5jDVdtJMoc?= =?us-ascii?Q?xMGBG3cMhWEg0fliSTpK/MppDMG9Pum3QwKcC/Zlo05mFyqopLudDy62t6Jk?= =?us-ascii?Q?TYxBbDEap4GXd1ErHbSrgtMtNaEShVoU?= X-Forefront-PRVS: 032334F434 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39830400002)(39450400003)(39410400002)(39400400002)(6506006)(6486002)(86362001)(6916009)(2950100002)(6666003)(54906002)(38730400002)(53936002)(6512007)(25786009)(478600001)(5660300001)(47776003)(305945005)(7736002)(66066001)(107886003)(5003940100001)(110136004)(189998001)(2906002)(4326008)(50226002)(3846002)(8676002)(81166006)(6116002)(53416004)(50466002)(2351001)(48376002)(76176999)(42186005)(50986999)(33646002)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0801MB1993; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0801MB1993; 23:migaERXL++ErlQw/OEruaWTECI48HRrdYTPY+NQ?= =?us-ascii?Q?hublmnjFCPIV5Y+eFEB1559Gcgryz1XgvA0TEKXMz7OAtQxPRdmszGGm+Wby?= =?us-ascii?Q?iSNAj5AGtz/0Y3T7VLClrrXYLYBEOngrMnP0/UNDXOWoTfJW4eI5ZUJFXddO?= =?us-ascii?Q?lh3wXiXi4MJgLD/xqirl7pkIRLXQAz1rxhN2j4dOlsiStpamcHHB3OUv7ihq?= =?us-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zMWUXo313dyJayQlpW/C6ar1aMSmiebdqIxkYaEZ; 24:wIlsDujMNp1KbGwHLMpaCn8MsO8GE0hUM3jOufWYdhMevOnaVxqbGbK7fzfDweK1rKwcESwNuiYiGBjLMcu4MvjV+dydmY4OxZ6ubHEDcGs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 7:unTsvG5raixApzCSSEAaZuJ+CDz0IyzG7F4qAxXu1DHjz4NmUZpjnthnWeX+PgfhflQKaA7CFJ6E9B832eond8W9fWrY0CZtZOrAYcru6SLpVLg0bKooy/MsiRI4ih19cAlRblc8M2KkCoTUEyVINNch8i6xRlKVs/7eUS3BtisuiBxx6MOuvKPCrFC0Zd34DWDN9Gv7H4eQ9jKGyNv3FxM+VOaSvDG9uFN4N8uNjaPt5/0va4kbpAWNEbGroWMYNwy2P/7xtGsEn4bQ1L4gCaLkJXDzXI0yHfZyJppPkLPddj2uINs0SQv8/F260GPBXDNHsQJAxLSpAJkTMUs2zw==; 20:ackI3KKTWiK/xQp9zVWVKvPU9M/g1M2l4LdxuJVPCYcKBLKisczNBT2jNxIklDDrq5WTiBR2AFvCU+iaznYqvmYtV9xtmyEv/b4F2o9bR+ik8OVEQnBTSYQTUr6rASwcvQRfHhB2oJPhRvY3jcaFovu/s6u0Ny7C6fSE3A2BLD4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2017 13:58:27.5910 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1993 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.114 Subject: [Qemu-devel] [PATCH v3 04/13] 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 Reviewed-by: Marc-André Lureau --- 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 ba1a5f5..1eed934 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 qemu_chr_fe_connect(CharBackend *b, Chardev *s, Error **errp) { int tag = 0; diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 014ebbc..117d628 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -391,10 +391,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.