From patchwork Fri Nov 10 17:10:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 118599 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp8180601qgn; Fri, 10 Nov 2017 09:13:12 -0800 (PST) X-Google-Smtp-Source: AGs4zMbKJNLpvv3/x81M7Vya5bdBQBTTC1FoNe/k/faNyF4hM1AsD9U6TUlac8/QO0jxK9kd3Ige X-Received: by 10.107.5.142 with SMTP id 136mr1089794iof.229.1510333991911; Fri, 10 Nov 2017 09:13:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510333991; cv=none; d=google.com; s=arc-20160816; b=pXn9n6wsMl2m2l8VV/5CRvkCkU/Xga1rWHEqbAhZi5YOo/CQAlbL9cesuytN6GB6fM liUBO0pzdNdkr2z4sW7DsZL5aug0JkmvHWbI2D3ZJySkCu3DhL0enrkGlQLCkbBKGNju r7fhGlGFiPFhAIq72zJcC5Uee1A+VytgwMszd+q9qZadAIgZqasung5C7EDwK8OuE8iy cLKXS8176HBDn+zPrnYKHknrdcm5JccZkp3apJWCwgggs9aQ8Gqv8Jp2Q5EQWpHefZzt wV43BR9IPYxUcihtiDdKCy+Y07LO8xuAP7CJhnw0GMDbESlIyA/NValNm64KTG/drHLB Fzyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:message-id:date:to:from:dkim-signature :arc-authentication-results; bh=O2nEC6spaSUeESkONBdm3GCN70IiMhROq9v4Z871NeA=; b=TUVv7XnH6oHU1dxYHfTv3g/NIVJoOTC5yl5tuZ+lqxFifjFQZrx3f0LpzpElRcuiQK 5iGh2HP42vccUzi0KUvmaVQM5tLqeoYy6gPjWaxsmolrnUPSWOfCmfBHDQBORBBlkldG nKEPzEldU6k9wN0PY+IWo70X1G7H+3zSi0qBIUUEadCEFvdIeYDtE8j734KUjBp4oik5 mjsZlniOpqT1jde2PA/VxFTnAr14n40F7erqtCYddOjbMOjjfbg1AU+5n0L1swy65IBp fKmWtsC5Dqld7+38hOWqcc2+0rqdWP2mZVntRNF4Fo0eo6opKosceijj3XcbTcbOtk8x zuoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=kM3jUjCz; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g11si1775138itf.8.2017.11.10.09.13.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 09:13:11 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=kM3jUjCz; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eDCpX-0004jc-Ap; Fri, 10 Nov 2017 17:10:59 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eDCpW-0004jW-Bo for xen-devel@lists.xen.org; Fri, 10 Nov 2017 17:10:58 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 47/34-00647-1ADD50A5; Fri, 10 Nov 2017 17:10:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLIsWRWlGSWpSXmKPExsXiVRvkpDvvLmu UwYWjyhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8biQxOZCj7zVGzc/ISxgfE7VxcjF4eQwARG ic0nH7GBOCwC7cwSi9tusIM4EgLvWCQu9nSydDFyAjl5Eg8/tjNB2GkSB7qPsULYlRLf7m4Bq uEAGqUmseZNFMTUPiaJhz9fM4LE2QR0JNbNqAUpFxGQlrj2+TIjiM0sUCGxY8FPsFZhgWCJqU cqQUwWAVWJY/3pIBW8AjYSqy/vY4dYJC+xq+0i6wRG/gWMDKsYNYpTi8pSi3SNTPWSijLTM0p yEzNzdA0NjPVyU4uLE9NTcxKTivWS83M3MQKDp56BgXEHY+sJv0OMkhxMSqK8hhdYo4T4kvJT KjMSizPii0pzUosPMcpwcChJ8L6/A5QTLEpNT61Iy8wBhjFMWoKDR0mENwYkzVtckJhbnJkOk TrFaMmxb8+tP0wcz2a+bmDmmHa1tYlZiCUvPy9VSpz3DEiDAEhDRmke3DhYrF1ilJUS5mVkYG AQ4ilILcrNLEGVf8UozsGoJMx7GWQKT2ZeCdzWV0AHMQEdFM3OAnJQSSJCSqqB0ThUIn5tC2s zA+OzbbahLmwRu/4w+HNfcc+4Fem840zwoXOM8+5tMWVnXih4sf3OopPGH/v+/Uk+8GnSk4wX +77UW/oxP/90+V7ZFM0qucz96/aY/GBW3L9C1iBVtGOPY2bxs8c3m1cInXyqfaHZ+cLSK9Peu B83W9m3YmVzjE4bX+yFFqMT+5RYijMSDbWYi4oTARRSaL+wAgAA X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-13.tower-31.messagelabs.com!1510333854!109876125!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53889 invoked from network); 10 Nov 2017 17:10:54 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-13.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 10 Nov 2017 17:10:54 -0000 Received: by mail-wm0-f66.google.com with SMTP id p75so4077002wmg.3 for ; Fri, 10 Nov 2017 09:10:54 -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; bh=fo7KOJ2W9rmWPHtc9yZTXbGKxRGazb3vksHN/269JCI=; b=kM3jUjCzcSZ31GDC8w2PPQyzvlVSJLAP62jUOFfH5v4hRwYmMnQKSC9CDfSgizx8Hg IqEB82fPFII3WO9qJUahQDKii00wXxAuMbiRWaeslMChGgG1kjKOfZ33PUVuPzbpr39P pBuZ+Q9HVho3b4TAuy12+oSi639PYmQMX1S18= 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; bh=fo7KOJ2W9rmWPHtc9yZTXbGKxRGazb3vksHN/269JCI=; b=GRcXskGj4bwv6caJNbvAUDzWl8FpJU7LeF9x7wwoFG+Rm+CvAfxzzX60+jIwheg55U zSnMfq8grQXflGIN/SYVtQ8mZ7xZtFBCsbS6GAltFBLTQNd7nKiifGfLy/SvT6cuNIhT WUWqAEwNnbx6TltWvgLOvAn4yBbb73ZNZWjEgCGcd+/tp/9t9fkMeBR92wnO7il3p18N M6lYD4FgEvnFQH3ln2O2ibD0R2ZOmDolI9JIeOzgo8pMvSokXRuLP1xak+OpOeZzE01Q +DNTuTSwkG805dUMtowEna4QI0dzhiwHBUwb4r8/br0PlP8Vzb+oI+UEKfuuKf8Aigzx fx+g== X-Gm-Message-State: AJaThX6d8SsEIxjX86UWF9TTqGJTraEfTm/U66mOutXhuslEbR1r0NXl UnqXKVHTVGO9svPJ+EAR6l0ZSg56MXg= X-Received: by 10.28.230.140 with SMTP id e12mr723118wmi.118.1510333853920; Fri, 10 Nov 2017 09:10:53 -0800 (PST) Received: from e108454-lin.cambridge.arm.com ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id p23sm18075507wrb.76.2017.11.10.09.10.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 09:10:53 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Fri, 10 Nov 2017 17:10:50 +0000 Message-Id: <20171110171050.19836-1-julien.grall@linaro.org> X-Mailer: git-send-email 2.11.0 Cc: ross.lagerwall@citrix.com, Julien Grall , wei.liu2@citrix.com, ian.jackson@eu.citrix.com Subject: [Xen-devel] [PATCH for-4.10] libs/evtchn: Remove active handler on clean-up or failure X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" Commit 89d55473ed16543044a31d1e0d4660cf5a3f49df "xentoolcore_restrict_all: Implement for libxenevtchn" added a call to register allowing to restrict the event channel. However, the call to deregister the handler was not performed if open failed or when closing the event channel. This will result to corrupt the list of handlers and potentially crash the application later one. Fix it by calling xentoolcore_deregister_active_handle on failure and closure. Signed-off-by: Julien Grall Acked-by: Ian Jackson Acked-by: Wei Liu Reviewed-by: Ross Lagerwall --- This patch is fixing a bug introduced after the code freeze by "xentoolcore_restrict_all: Implement for libxenevtchn". The call to xentoolcore_deregister_active_handle is done at the same place as for the grants. But I am not convinced this is thread safe as there are potential race between close the event channel and restict handler. Do we care about that? --- tools/libs/evtchn/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/libs/evtchn/core.c b/tools/libs/evtchn/core.c index 14b7549a6b..2dba58bf00 100644 --- a/tools/libs/evtchn/core.c +++ b/tools/libs/evtchn/core.c @@ -56,6 +56,7 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags) err: osdep_evtchn_close(xce); + xentoolcore__deregister_active_handle(&xce->tc_ah); xtl_logger_destroy(xce->logger_tofree); free(xce); return NULL; @@ -69,6 +70,7 @@ int xenevtchn_close(xenevtchn_handle *xce) return 0; rc = osdep_evtchn_close(xce); + xentoolcore__deregister_active_handle(&xce->tc_ah); xtl_logger_destroy(xce->logger_tofree); free(xce); return rc;