From patchwork Mon May 25 02:49:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B21EF913 for ; Mon, 25 May 2020 02:51:38 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E5922075F for ; Mon, 25 May 2020 02:51:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a5R6y24h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E5922075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3CX-0004La-KW; Mon, 25 May 2020 02:50:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3CW-0004LS-Cv for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:50:52 +0000 X-Inumbo-ID: 8bc771ba-9e32-11ea-b9cf-bc764e2007e4 Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8bc771ba-9e32-11ea-b9cf-bc764e2007e4; Mon, 25 May 2020 02:50:51 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id l1so12932530qtp.6 for ; Sun, 24 May 2020 19:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TuFE1UFStx7DhYra1LcAmMWFmhp1FfRuQDwhQTRAYLQ=; b=a5R6y24hmZf7dseYfL279Z6P8Y/N4v32REhzXWvuI6RgseeMyz30DzODrA7F59/VeF VVMqWBMdPM43TC/sErMk6cyiuc1FBjV3KVGIpsHiaE463qPFvnucfc980Fw/WStrE4GR KrVpzAQNrqnCiRpbiUPW9pRY9XFfVINzYBEzWYc/se878fXjCqWn1oKwUQJ2YSyQfPjz +ZbawcHb84gd55HRTaBj1auKqYLRYCHR6jWm12LnjRCmDScGxiY3Ok08TxB4I2bffNwL oLZT96v4GZz+VoM1Cxiuy8MhumTmN6AQcU7wS89p+5fn8YnrcG4z7whjDkSl+AntixmM /jOg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TuFE1UFStx7DhYra1LcAmMWFmhp1FfRuQDwhQTRAYLQ=; b=uh41joMsT7lXRpfraetULzxWvqhyJSlCysB58MZdTsZNPXca4lNAfPTCO2mdZEc1we J+MX3kSj2JZiW8kvXY/w+8/HUnZXMVHalgFEN9N6kt4uKCLw+YKYiMXGqlKS95WPe8ld tNURRKM2QsafeWVHBXpiujtQW1YFjyi5sR+Yg5Y/LD0EaofQirE2C+kmkgz9vLti4nTb yjt2rx9DybWA9aQeTJnmotJ+1NgyZJfhXXPfYhrexg5ALxCevkFCtCSg20WmjpvWwgB7 gRy9dbPxD+1snysbwdqnG/Yr1L4sVpmEN4XmPX9aUpsGeUdIoeB5TJ7glPUPNZAw3faV VLtg== X-Gm-Message-State: AOAM531iT4+S2d0p+QaXj08oaIaDHVmOGxgiUXxcrVwrtaXVAi5sgYm7 1c3ohMwP0Tpx2mq+OA7hfq+49Yc7 X-Google-Smtp-Source: ABdhPJx6/03cefrmuDCSXXmpl/Oe1/sw6rOyEM8gKdoi/casVrLcDhpzCbgzgqTwZikXJCpRGw5g0A== X-Received: by 2002:ac8:543:: with SMTP id c3mr25433015qth.8.1590375051323; Sun, 24 May 2020 19:50:51 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:50:50 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 1/8] vchan-socket-proxy: Ensure UNIX path NUL terminated Date: Sun, 24 May 2020 22:49:48 -0400 Message-Id: <20200525024955.225415-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Check the socket path length to ensure sun_path is NUL terminated. This was spotted by Citrix's Coverity. Signed-off-by: Jason Andryuk Reviewed-by: Marek Marczykowski-Górecki --- tools/libvchan/vchan-socket-proxy.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 13700c5d67..6d860af340 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -148,6 +148,12 @@ static int connect_socket(const char *path_or_fd) { return fd; } + if (strlen(path_or_fd) >= sizeof(addr.sun_path)) { + fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n", + path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path)); + return -1; + } + fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) return -1; @@ -174,6 +180,12 @@ static int listen_socket(const char *path_or_fd) { return fd; } + if (strlen(path_or_fd) >= sizeof(addr.sun_path)) { + fprintf(stderr, "UNIX socket path \"%s\" too long (%zd >= %zd)\n", + path_or_fd, strlen(path_or_fd), sizeof(addr.sun_path)); + return -1; + } + /* if not a number, assume a socket path */ fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) From patchwork Mon May 25 02:49:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567891 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17381913 for ; Mon, 25 May 2020 02:51:43 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E79892075F for ; Mon, 25 May 2020 02:51:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A5uYZZ2w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E79892075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cb-0004M2-Ss; Mon, 25 May 2020 02:50:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Ca-0004Lo-Dm for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:50:56 +0000 X-Inumbo-ID: 8d478886-9e32-11ea-b9cf-bc764e2007e4 Received: from mail-qv1-xf42.google.com (unknown [2607:f8b0:4864:20::f42]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8d478886-9e32-11ea-b9cf-bc764e2007e4; Mon, 25 May 2020 02:50:54 +0000 (UTC) Received: by mail-qv1-xf42.google.com with SMTP id p4so7501250qvr.10 for ; Sun, 24 May 2020 19:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T0BiCkhzclg2VvasscglUktTq98DwBMZs8CpLP6l+Lg=; b=A5uYZZ2wzL/XRZaWDvdvR+WIEUjNsUaDYhREgp5q/oggWg9b4VK9We2mfzinR3lXXT EgSB3jM6fAwWsrfr8vuAHnBvoHG5vIMjjiV3Qi9mKi6d/Si+PzsbnzMbgehVJfr8VP8X f+wHjkozqeBFVGi60RXJimffcBsM9e5BBslRc6wWvr58aPIzf2LwV5NxlvO642947tLG Un2+3BLVDfOgPBwDHJOyaVB1edpmnV6YC0DKRFuI6TPSHJZTEtHjsSK95g1Zz9/snez7 DRQHsvXgD5iLVgnUF8d5kHMpteE+NJnqqkC7HoaHv3iZQl8k4Hp43+/iR+dlpWnRtrvF hxhw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=T0BiCkhzclg2VvasscglUktTq98DwBMZs8CpLP6l+Lg=; b=qXt/iXpeiOb3R5aZbOlr8gWxLsLTQBDrY7CU6BiEYMaLBoS6pKyBI9gHe+r3dTryl+ wlQ5jMpn2d8Jw3BNQgWtlvSdNDoIUx+vCNfi1I6jfOxY/vbU14gAlYqv9xwvc+bV5p1x 65r3ipfZbgxdopVrlcpKQIPf06RC4iUtTlp7Jzc3L8C7Qe2AMgciNqO3xVUdMEddDzqh g0eY88OPYSVF551yUQx+Xx5+3sT8vZAAITO4QAwB5TANFmegy3SbhbPCyMNnN+TW0WHk IvK+uScg1Y33pw5GJYFHcjjupGcWb884Nas3XVnX2/PgF5/x45hSE++tEGkhpquSWa5H gAIQ== X-Gm-Message-State: AOAM533V99aojHwSHjQ8Jgg6ldtZbta2pxAaPLS7qHWfsqrRt4PxGhid 6GtgyO6rdPbBjnGl1L7Wcb/JauAs X-Google-Smtp-Source: ABdhPJxUoxNI9bSF8blnHfGiLAFojgcXDTSl8/QBkDtJj1CY8bzGzXHV9M3Dgcidm14+QfZ0s4GmTQ== X-Received: by 2002:a0c:fb4b:: with SMTP id b11mr13428732qvq.96.1590375053889; Sun, 24 May 2020 19:50:53 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:50:53 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 2/8] vchan-socket-proxy: Check xs_watch return value Date: Sun, 24 May 2020 22:49:49 -0400 Message-Id: <20200525024955.225415-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Check the return value of xs_watch and error out on failure. This was found by Citrix's Coverity. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 6d860af340..bd12632311 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -225,8 +225,15 @@ static struct libxenvchan *connect_vchan(int domid, const char *path) { goto out; } /* wait for vchan server to create *path* */ - xs_watch(xs, path, "path"); - xs_watch(xs, "@releaseDomain", "release"); + if (!xs_watch(xs, path, "path")) { + fprintf(stderr, "xs_watch(%s) failed.\n", path); + goto out; + } + if (!xs_watch(xs, "@releaseDomain", "release")) { + fprintf(stderr, "xs_watch(@releaseDomain failed.\n"); + goto out; + } + while ((watch_ret = xs_read_watch(xs, &watch_num))) { /* don't care about exact which fired the watch */ free(watch_ret); From patchwork Mon May 25 02:49:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B4B5913 for ; Mon, 25 May 2020 02:51:46 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7812D2075F for ; Mon, 25 May 2020 02:51:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="myWRm19n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7812D2075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Ch-0004NC-52; Mon, 25 May 2020 02:51:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cf-0004Mo-D8 for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:51:01 +0000 X-Inumbo-ID: 8ec275b8-9e32-11ea-b9cf-bc764e2007e4 Received: from mail-qt1-x843.google.com (unknown [2607:f8b0:4864:20::843]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8ec275b8-9e32-11ea-b9cf-bc764e2007e4; Mon, 25 May 2020 02:50:56 +0000 (UTC) Received: by mail-qt1-x843.google.com with SMTP id o19so12912009qtr.10 for ; Sun, 24 May 2020 19:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3D6lM8zZXrDZrYYs+sM9xLtHGYSewtj+rrLJ+C4zgl4=; b=myWRm19nfnWsV4/CRIazx+Qpwm3OypAgqd6JXVhMlnbvpdVctR7ZkbvcDEmYTTZrB3 rj3W0eFYZeBRWs3DVQafy+38/4VG4sKlqmoeiWnNV0dRPABzREMDEV9IW7+1LqV3BiN4 dvDjxI/dJFSQTzODcueatJRivY0yeUwKyGBjIV203VWeC2pLm6WwtroxWsjD6MchYz0P Cg9iIFgb+mEsaBcPLo0uBBszY5dkcs7hQ9tCIiTXY5tBfg1p45cMDgQTwpd2JM10E9OK SKh/z3ytasVvUOrIPt8g0LRI20bouAewUd3NZHOk6tuMooCImAqGlfIm+7GafZdBbE8p vX3Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=3D6lM8zZXrDZrYYs+sM9xLtHGYSewtj+rrLJ+C4zgl4=; b=q3dt/pPkQPm17sg6+gvwztfRSabZXq4v6er/UbiBvsHEl1Bsess5DiuDtLM75z3FnW 5VFU5/kr1WZsyOHwX0i3vm21Qz9q1FRk82vXd9WIEVKwquVlfOfKVVlMdAywvS83QSHN xrtRmSIDnPJvye4+39GShYCK49kQa4PFdBhJJ6BOWtPbp58wz7xJr+z5j+1ZfNzWLuPd N25g9cuEN2XLEYgotzRMgK1v6/NtG/OK8r0ql2EZNjkONR/JorFJvLxS+dG7c2LXCtzy IAqJ3fUesa64a5bVCwNj4tohOP6X8MekVxnqi/8dki9n3bnqluVBYUGBMDySxghAln+I wjDQ== X-Gm-Message-State: AOAM5300vT6UKmnp7of3e5/mTkt4E8lD2p6FLwWXJ+LXqiNSvPlicqBL T2PUnghwFgkD7xXIo9bzotAC0qLK X-Google-Smtp-Source: ABdhPJx+rgbZ9bRQ3+GrhZW7rJFE2qtB40YncDhT2ua91BgbMD+5muIbaNWUuBv5zcCLqYFB120now== X-Received: by 2002:ac8:65d1:: with SMTP id t17mr18084693qto.46.1590375056329; Sun, 24 May 2020 19:50:56 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:50:55 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 3/8] vchan-socket-proxy: Unify main return value Date: Sun, 24 May 2020 22:49:50 -0400 Message-Id: <20200525024955.225415-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Introduce 'ret' for main's return value and remove direct returns. This is in preparation for a unified exit path with resource cleanup. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index bd12632311..d85e24ee93 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -381,6 +381,7 @@ int main(int argc, char **argv) const char *vchan_path; const char *state_path = NULL; int opt; + int ret; while ((opt = getopt_long(argc, argv, "m:vs:", options, NULL)) != -1) { switch (opt) { @@ -447,6 +448,8 @@ int main(int argc, char **argv) xs_close(xs); } + ret = 0; + for (;;) { if (is_server) { /* wait for vchan connection */ @@ -461,7 +464,8 @@ int main(int argc, char **argv) } if (input_fd == -1) { perror("connect socket"); - return 1; + ret = 1; + break; } if (data_loop(ctrl, input_fd, output_fd) != 0) break; @@ -474,14 +478,16 @@ int main(int argc, char **argv) input_fd = output_fd = accept(socket_fd, NULL, NULL); if (input_fd == -1) { perror("accept"); - return 1; + ret = 1; + break; } set_nonblocking(input_fd, 1); set_nonblocking(output_fd, 1); ctrl = connect_vchan(domid, vchan_path); if (!ctrl) { perror("vchan client init"); - return 1; + ret = 1; + break; } if (data_loop(ctrl, input_fd, output_fd) != 0) break; @@ -493,5 +499,6 @@ int main(int argc, char **argv) ctrl = NULL; } } - return 0; + + return ret; } From patchwork Mon May 25 02:49:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567901 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB87B13B4 for ; Mon, 25 May 2020 02:52:21 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B731B2075F for ; Mon, 25 May 2020 02:52:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cnyTYQB3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B731B2075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cl-0004PA-H9; Mon, 25 May 2020 02:51:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Ck-0004Ol-EJ for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:51:06 +0000 X-Inumbo-ID: 9005aba2-9e32-11ea-ae69-bc764e2007e4 Received: from mail-qv1-xf41.google.com (unknown [2607:f8b0:4864:20::f41]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9005aba2-9e32-11ea-ae69-bc764e2007e4; Mon, 25 May 2020 02:50:59 +0000 (UTC) Received: by mail-qv1-xf41.google.com with SMTP id r3so7548284qve.1 for ; Sun, 24 May 2020 19:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y9V1tgqrbsz8wnP0O1UzYnljlbdkN5+LC5mMxx9pPO4=; b=cnyTYQB33jVd69hyM6RmnHA2+rsRnAQVdhGjUC68MMxQbGsHlnpStndqhrcOoLGwP/ HYVqoiTnWJ2kqpJWiL8Bk0dIOJh3eX0LNrS/pUvRQThjvzfT9VwKZ8VfXIxNJg+fAOVe OWJbriZfk4xqj82/E97TCGsSDT3LwGAzdAJ3uDfIx42sfsBrbuHRv+OZnkfq3eUz1gZr DzzZ1FOcOenLRZTw/6EbgwUfjRpqwyWmTmF1C09A4f7HTCrxgIoES9wTtYs2gJMjZadn llK0U86PwKlQiTIrGqk9zWjaty7YAYwO/nLMPL8S3MGcYtZl55oo2ul0ugX4UK3fFK+C PlVA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=y9V1tgqrbsz8wnP0O1UzYnljlbdkN5+LC5mMxx9pPO4=; b=eRpKNsmN75ja5iSBHa72gxeGSIOr6CSFZNv0pkUNOaT55RuwlY7hllOP8ActCLbIKU O44KDq5bY3n8YwGGcjg/q3ux+IN65ZZVQVBZy4Jfau6yBNkQ80mU7B/cFqWb7bea0MPU mY/S0pMxfNKlFKR5r5TbswTnZi5f7LxPlrp5BIHf/euJXv+ccdFjKqJ79IVmi7UXecWL F3mw1dUdxejdcB7cgN+WimeVzNSBgQSywfc5aXkzS0WIIF6nVE7k2chvR1dXoQcWUiPX L8KHszXRQf/SIzAaM005foTah6Vr1jCjMYon1FW4uAuDEKrBE89NweOlXNC5J6yTwZPB AZcQ== X-Gm-Message-State: AOAM530OFos4XhXiBl7Snty1KSGgDaeb3vL/yZ8gU+/x2GsqHTdytYZw uLtrtbwDUdsW4IwxuX8v7mxh0d+J X-Google-Smtp-Source: ABdhPJyeCUoOdYimoZsXvuzqA0tzdnRAtxmTY6XHOdXIW6cDTT6vGhf5s3BHQpaKoNNCv5yFr+iCog== X-Received: by 2002:ad4:57cb:: with SMTP id y11mr13770669qvx.26.1590375058455; Sun, 24 May 2020 19:50:58 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:50:57 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 4/8] vchan-socket-proxy: Use a struct to store state Date: Sun, 24 May 2020 22:49:51 -0400 Message-Id: <20200525024955.225415-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Use a struct to group the vchan ctrl and FDs. This will facilite tracking the state of open and closed FDs and ctrl in data_loop(). Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 52 +++++++++++++++++------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index d85e24ee93..39f4bb1452 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -89,6 +89,12 @@ int insiz = 0; int outsiz = 0; int verbose = 0; +struct vchan_proxy_state { + struct libxenvchan *ctrl; + int output_fd; + int input_fd; +}; + static void vchan_wr(struct libxenvchan *ctrl) { int ret; @@ -374,8 +380,9 @@ int main(int argc, char **argv) { int is_server = 0; int socket_fd = -1; - int input_fd, output_fd; - struct libxenvchan *ctrl = NULL; + struct vchan_proxy_state state = { .ctrl = NULL, + .input_fd = -1, + .output_fd = -1 }; const char *socket_path; int domid; const char *vchan_path; @@ -415,15 +422,15 @@ int main(int argc, char **argv) socket_path = argv[optind+2]; if (is_server) { - ctrl = libxenvchan_server_init(NULL, domid, vchan_path, 0, 0); - if (!ctrl) { + state.ctrl = libxenvchan_server_init(NULL, domid, vchan_path, 0, 0); + if (!state.ctrl) { perror("libxenvchan_server_init"); exit(1); } } else { if (strcmp(socket_path, "-") == 0) { - input_fd = 0; - output_fd = 1; + state.input_fd = 0; + state.output_fd = 1; } else { socket_fd = listen_socket(socket_path); if (socket_fd == -1) { @@ -453,21 +460,21 @@ int main(int argc, char **argv) for (;;) { if (is_server) { /* wait for vchan connection */ - while (libxenvchan_is_open(ctrl) != 1) - libxenvchan_wait(ctrl); + while (libxenvchan_is_open(state.ctrl) != 1) + libxenvchan_wait(state.ctrl); /* vchan client connected, setup local FD if needed */ if (strcmp(socket_path, "-") == 0) { - input_fd = 0; - output_fd = 1; + state.input_fd = 0; + state.output_fd = 1; } else { - input_fd = output_fd = connect_socket(socket_path); + state.input_fd = state.output_fd = connect_socket(socket_path); } - if (input_fd == -1) { + if (state.input_fd == -1) { perror("connect socket"); ret = 1; break; } - if (data_loop(ctrl, input_fd, output_fd) != 0) + if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) break; /* keep it running only when get UNIX socket path */ if (socket_path[0] != '/') @@ -475,28 +482,29 @@ int main(int argc, char **argv) } else { /* wait for local socket connection */ if (strcmp(socket_path, "-") != 0) - input_fd = output_fd = accept(socket_fd, NULL, NULL); - if (input_fd == -1) { + state.input_fd = state.output_fd = accept(socket_fd, + NULL, NULL); + if (state.input_fd == -1) { perror("accept"); ret = 1; break; } - set_nonblocking(input_fd, 1); - set_nonblocking(output_fd, 1); - ctrl = connect_vchan(domid, vchan_path); - if (!ctrl) { + set_nonblocking(state.input_fd, 1); + set_nonblocking(state.output_fd, 1); + state.ctrl = connect_vchan(domid, vchan_path); + if (!state.ctrl) { perror("vchan client init"); ret = 1; break; } - if (data_loop(ctrl, input_fd, output_fd) != 0) + if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) break; /* don't reconnect if output was stdout */ if (strcmp(socket_path, "-") == 0) break; - libxenvchan_close(ctrl); - ctrl = NULL; + libxenvchan_close(state.ctrl); + state.ctrl = NULL; } } From patchwork Mon May 25 02:49:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADA90913 for ; Mon, 25 May 2020 02:52:03 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A9B92075F for ; Mon, 25 May 2020 02:52:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oC0Y6l2L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A9B92075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cw-0004UQ-44; Mon, 25 May 2020 02:51:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cu-0004TA-E9 for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:51:16 +0000 X-Inumbo-ID: 919bb92a-9e32-11ea-ae69-bc764e2007e4 Received: from mail-qv1-xf42.google.com (unknown [2607:f8b0:4864:20::f42]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 919bb92a-9e32-11ea-ae69-bc764e2007e4; Mon, 25 May 2020 02:51:01 +0000 (UTC) Received: by mail-qv1-xf42.google.com with SMTP id dh1so7485372qvb.13 for ; Sun, 24 May 2020 19:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c+GBcLzdTfVlujqDgxVJJIXEMu0nDYhq6Ss2jg+Z8wQ=; b=oC0Y6l2LjLu/Y0zlJEc2vdTDFQkI7DecoziRTK9np3LNgQrgm0tm0uju7/F7CcyB7z 70mb+ThUac1YUdZ2oOpOpc75eye9eO9erLaAwY2b3FEiqFIhERCW7h8FOK268/jl8ON2 8M6TyCD2r44k3StyFFcNDIWLp/aSZsARlM4gF1HOKhQQaj3OT8CTnQK4GRqoVbyH8+Pj NTzRorLfvgL1Wrq0sn3h5KxeMlgKti7qJnXzsU4urdQiKCRz6Gtgw3nhgxGYn8n9/mou JJjmQETY1UrLpEOpWf4+iuegaT4OAvSy2YkTD1w11fLniGeZnMmq7ilZAa1Ym8K5xIrT 7drA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=c+GBcLzdTfVlujqDgxVJJIXEMu0nDYhq6Ss2jg+Z8wQ=; b=PKnA99fc8izHIhesYHei0vq8dgo/u29VdnO7gE1k3GK4EDiDXe+HAoz6OmgwGRJ5eE J8/9vI9WAFCY+pXobdUBNQEfNPm8O8DOWCmdPti5U0j+2jhjOrzMUhhRYXpCrpnokTh9 qep0P32xXAIQk4Y+2AX27oEAqR9LqYyUzdXZMaCpN4dHR3+uBEMM1KKUqOpEIg9N5u9b PhetEomxyoD5Pw7FGAZy/2Urc4vOP2hgmZuoRs87VEeOEwjjGE++IMyK5YtTYTXz7NmZ CXgmFgaOU333xo2MBl7DMtMJqwgKkFaRoo3AqFDtialbVg4w4ZTHYbN3amPQGiDCdnlm QXvw== X-Gm-Message-State: AOAM533noFIgm6V/VJ46rfCWIKXSlzPIlhenJQMdif5e9h//k1Xvdcek lHgwC5cu1c1Ba1KqJHa5z0X63js8 X-Google-Smtp-Source: ABdhPJySewG2QNC01azxs4/d/Rg6cedR6xmr/aJH5EFOXstoH8Bi1+nJsZncrKYTGqifOvtadjfq9Q== X-Received: by 2002:a0c:ee25:: with SMTP id l5mr13346075qvs.5.1590375060651; Sun, 24 May 2020 19:51:00 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:51:00 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 5/8] vchan-socket-proxy: Switch data_loop() to take state Date: Sun, 24 May 2020 22:49:52 -0400 Message-Id: <20200525024955.225415-6-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Switch data_loop to take a pointer to vchan_proxy_state. No functional change. This removes a dead store to input_fd identified by Coverity. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 65 +++++++++++++++-------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 39f4bb1452..32be410609 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -279,13 +279,13 @@ static void discard_buffers(struct libxenvchan *ctrl) { } } -int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd) +int data_loop(struct vchan_proxy_state *state) { int ret; int libxenvchan_fd; int max_fd; - libxenvchan_fd = libxenvchan_fd_for_select(ctrl); + libxenvchan_fd = libxenvchan_fd_for_select(state->ctrl); for (;;) { fd_set rfds; fd_set wfds; @@ -293,15 +293,15 @@ int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd) FD_ZERO(&wfds); max_fd = -1; - if (input_fd != -1 && insiz != BUFSIZE) { - FD_SET(input_fd, &rfds); - if (input_fd > max_fd) - max_fd = input_fd; + if (state->input_fd != -1 && insiz != BUFSIZE) { + FD_SET(state->input_fd, &rfds); + if (state->input_fd > max_fd) + max_fd = state->input_fd; } - if (output_fd != -1 && outsiz) { - FD_SET(output_fd, &wfds); - if (output_fd > max_fd) - max_fd = output_fd; + if (state->output_fd != -1 && outsiz) { + FD_SET(state->output_fd, &wfds); + if (state->output_fd > max_fd) + max_fd = state->output_fd; } FD_SET(libxenvchan_fd, &rfds); if (libxenvchan_fd > max_fd) @@ -312,52 +312,53 @@ int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd) exit(1); } if (FD_ISSET(libxenvchan_fd, &rfds)) { - libxenvchan_wait(ctrl); - if (!libxenvchan_is_open(ctrl)) { + libxenvchan_wait(state->ctrl); + if (!libxenvchan_is_open(state->ctrl)) { if (verbose) fprintf(stderr, "vchan client disconnected\n"); while (outsiz) - socket_wr(output_fd); - close(output_fd); - close(input_fd); - discard_buffers(ctrl); + socket_wr(state->output_fd); + close(state->output_fd); + close(state->input_fd); + discard_buffers(state->ctrl); break; } - vchan_wr(ctrl); + vchan_wr(state->ctrl); } - if (FD_ISSET(input_fd, &rfds)) { - ret = read(input_fd, inbuf + insiz, BUFSIZE - insiz); + if (FD_ISSET(state->input_fd, &rfds)) { + ret = read(state->input_fd, inbuf + insiz, BUFSIZE - insiz); if (ret < 0 && errno != EAGAIN) exit(1); if (verbose) fprintf(stderr, "from-unix: %.*s\n", ret, inbuf + insiz); if (ret == 0) { /* EOF on socket, write everything in the buffer and close the - * input_fd socket */ + * state->input_fd socket */ while (insiz) { - vchan_wr(ctrl); - libxenvchan_wait(ctrl); + vchan_wr(state->ctrl); + libxenvchan_wait(state->ctrl); } - close(input_fd); - input_fd = -1; + close(state->input_fd); + state->input_fd = -1; /* TODO: maybe signal the vchan client somehow? */ break; } if (ret) insiz += ret; - vchan_wr(ctrl); + vchan_wr(state->ctrl); } - if (FD_ISSET(output_fd, &wfds)) - socket_wr(output_fd); - while (libxenvchan_data_ready(ctrl) && outsiz < BUFSIZE) { - ret = libxenvchan_read(ctrl, outbuf + outsiz, BUFSIZE - outsiz); + if (FD_ISSET(state->output_fd, &wfds)) + socket_wr(state->output_fd); + while (libxenvchan_data_ready(state->ctrl) && outsiz < BUFSIZE) { + ret = libxenvchan_read(state->ctrl, outbuf + outsiz, + BUFSIZE - outsiz); if (ret < 0) exit(1); if (verbose) fprintf(stderr, "from-vchan: %.*s\n", ret, outbuf + outsiz); outsiz += ret; - socket_wr(output_fd); + socket_wr(state->output_fd); } } return 0; @@ -474,7 +475,7 @@ int main(int argc, char **argv) ret = 1; break; } - if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) + if (data_loop(&state) != 0) break; /* keep it running only when get UNIX socket path */ if (socket_path[0] != '/') @@ -497,7 +498,7 @@ int main(int argc, char **argv) ret = 1; break; } - if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0) + if (data_loop(&state) != 0) break; /* don't reconnect if output was stdout */ if (strcmp(socket_path, "-") == 0) From patchwork Mon May 25 02:49:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AF3014C0 for ; Mon, 25 May 2020 02:51:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 362EA2075F for ; Mon, 25 May 2020 02:51:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dUU5g9Gx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 362EA2075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cq-0004R0-Pt; Mon, 25 May 2020 02:51:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cp-0004Qe-EC for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:51:11 +0000 X-Inumbo-ID: 92a2e492-9e32-11ea-ae69-bc764e2007e4 Received: from mail-qv1-xf44.google.com (unknown [2607:f8b0:4864:20::f44]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 92a2e492-9e32-11ea-ae69-bc764e2007e4; Mon, 25 May 2020 02:51:03 +0000 (UTC) Received: by mail-qv1-xf44.google.com with SMTP id p4so7501325qvr.10 for ; Sun, 24 May 2020 19:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=11/9Z+esWpnjGME4OYhJ11vNo1bXthXQQy5dVc6MS2w=; b=dUU5g9Gx88n6jfEOpIMwOpx2rQOev5secFI/pcOIwqVQs7iia4Ks117tv6/vjBQoK6 ndINVcAH47xkE/9+cFfL4Sv2T/0ZQAI3yvLSZ6rdycRPTdjpZEi3MbPqzuTNc+6lnHJW LpG5CKzDTQ5zRmgnE+SU9Y/uCzW8NRnT/hziA/ckmkMBJDYWuGJdK1g+Z0X1Ls7sRrQ3 3cI3jHxFHPtTc3zshG8RJ96sUeOtE4UyWPpVHjKsOchp6P5LpcbS59LuZtmlePy6vuQE 4cbCRBcmD744cJqURtaHNIOtoYnAa6cC/Y7WI9Dq2zT+Ce4uoZ9zYbleWYuLdNeJlOiu Gvow== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=11/9Z+esWpnjGME4OYhJ11vNo1bXthXQQy5dVc6MS2w=; b=NkkTi0M4OodIwv5mDVKjKwtAb8eCRm6u12/hTLc5AHuoZMczSQfCUbszuHKKMH4lxO rJVx51edUuOdJbz7Bv0yLhUEc9PAW2FWON0iSkvBPzEMtvSSBkPqJLFC/HhbLhXvqNxv b/KHtqVyVKLNRRldiSyVRc78Jng/kESHwMD/NUIRe+hu2U35X92gjsvkTKt0/nZDWIWM nzHAPPqu9N895gagXRUTWStcBuoSCwQsEup3JsH+1M4QwfiQagOW/12P96Plvc0TkQyT VN/0nPASUmqWTIEGDfNOTrzSdLq4Y+9CTYFugVmT7PExxbTLp8eyGkytxwrlUsbNOSLm V8vQ== X-Gm-Message-State: AOAM532+d0//xbTS/1dB1R9pjFDcfwpy1DwI1EWPFqa8oI40tUqI1eUL aCFpbAV/Nzq0g4lI1OAxo8639AgJ X-Google-Smtp-Source: ABdhPJxh5j5c3BvA8/blIR/5rb6cXSRpiv6MBzO1RF04GCNvAYfvlxsJ2jqcP5+ri/t0wK0Thqws0Q== X-Received: by 2002:a0c:a144:: with SMTP id d62mr13412979qva.229.1590375062897; Sun, 24 May 2020 19:51:02 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:51:02 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 6/8] vchan-socket-proxy: Set closed FDs to -1 Date: Sun, 24 May 2020 22:49:53 -0400 Message-Id: <20200525024955.225415-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" These FDs are closed, so set them to -1 so they are no longer valid. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index 32be410609..f3f6e5ec09 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -319,7 +319,9 @@ int data_loop(struct vchan_proxy_state *state) while (outsiz) socket_wr(state->output_fd); close(state->output_fd); + state->output_fd = -1; close(state->input_fd); + state->input_fd = -1; discard_buffers(state->ctrl); break; } From patchwork Mon May 25 02:49:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567895 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E59213B4 for ; Mon, 25 May 2020 02:51:57 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DFD142075F for ; Mon, 25 May 2020 02:51:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H//Y5Qfj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFD142075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3D0-0004XS-Eq; Mon, 25 May 2020 02:51:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3Cz-0004Wx-Ds for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:51:21 +0000 X-Inumbo-ID: 940556bc-9e32-11ea-9887-bc764e2007e4 Received: from mail-qk1-x743.google.com (unknown [2607:f8b0:4864:20::743]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 940556bc-9e32-11ea-9887-bc764e2007e4; Mon, 25 May 2020 02:51:05 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id b27so6457948qka.4 for ; Sun, 24 May 2020 19:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T3VIo617dxU+JNhTIh5muYXiVHbUoUU/vbppSclO4R4=; b=H//Y5QfjKCvFbeIzygw4SVcQFuOlrO12RIEjI8DQTOOE+qbkmX7/0YTKPVn5s1L/v8 l+w9aN4jdqWihCj9TawrZN28mG674NgdJW1Fg6kClyaezu8wv1hdAiHPb/vbJYu/IUQc cTsJjwCJ+rBrNR6tWK/1frwx1HfgPpXr2Cn9WyEB91lPH3nyG30FDMiDLcaZOqUKb3my cWrygZpzPAyXmRh/PsSInNZEKQfJcmWpdeWiD1uLHurVmaChHLEbb590JT6ybJbhwL5l ZUAGYI0jDTi+AA6RqGsFnPVYUOHtCyDGlpZyqVKFgwrg+3PJImzFiKmnnHA8v3mIfFzA UTtA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=T3VIo617dxU+JNhTIh5muYXiVHbUoUU/vbppSclO4R4=; b=fFERzSq6w5k7aHGPtaiZaQakK2M5TZ5mQIHitoNHNAJuPWYFTFHyeGHKjqpY3i+TcP briLO9fCKjEfiUSMVAcgjwysleSO52VS0+aAymgwUoCZSnxd2Gvmh7Sxss0rmZksgWoh A1Z4LZGLdhSKdagexUKzqP5hMF5P5nATw5FoWMdUSRf3B1VEmD5xyfQzPA8RnAHQTQD7 qBjWEKM9HqJ44pbPRVX2K/SkuP2Sh80zp+Fnk6UKIhFFXij+JvsYVwZ7E1A/E+eHYlC5 DgBauTk0s5Fwlbx2UpiWKrUEJLu53OkgUMazyYgqSCjMpFuE26lWVt2OA0BgxDiUn11i o+kQ== X-Gm-Message-State: AOAM5338D6qXK9ZTgnKhOrE2hI0ik5q6CiCnpslCPUav48lnqIQzRYmu mKsVLX8dG+PgMNw4PjI37i3AGLgf X-Google-Smtp-Source: ABdhPJz87lVhG4951kT7XtwU45jYIGytRok/y5eoofYCmkEqwqVqOBqV4LiWrWTA+t0mWR5DoZGHpg== X-Received: by 2002:ae9:f214:: with SMTP id m20mr25017275qkg.232.1590375065126; Sun, 24 May 2020 19:51:05 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:51:04 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 7/8] vchan-socket-proxy: Cleanup resources on exit Date: Sun, 24 May 2020 22:49:54 -0400 Message-Id: <20200525024955.225415-8-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Close open FDs and close th vchan connection when exiting the program. This addresses some Coverity findings about leaking file descriptors. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index f3f6e5ec09..a04b46ee04 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -511,5 +511,14 @@ int main(int argc, char **argv) } } + if (state.output_fd >= 0) + close(state.output_fd); + if (state.input_fd >= 0) + close(state.input_fd); + if (state.ctrl) + libxenvchan_close(state.ctrl); + if (socket_fd >= 0) + close(socket_fd); + return ret; } From patchwork Mon May 25 02:49:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11567899 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AC8E13B4 for ; Mon, 25 May 2020 02:52:13 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 381632075F for ; Mon, 25 May 2020 02:52:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FE8JO6G2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 381632075F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3D5-0004c9-OI; Mon, 25 May 2020 02:51:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jd3D4-0004b4-FE for xen-devel@lists.xenproject.org; Mon, 25 May 2020 02:51:26 +0000 X-Inumbo-ID: 95a74246-9e32-11ea-b9cf-bc764e2007e4 Received: from mail-qk1-x744.google.com (unknown [2607:f8b0:4864:20::744]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 95a74246-9e32-11ea-b9cf-bc764e2007e4; Mon, 25 May 2020 02:51:08 +0000 (UTC) Received: by mail-qk1-x744.google.com with SMTP id n11so10967497qkn.8 for ; Sun, 24 May 2020 19:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vlm0vRlSx5YbGIPqCOuB7/AqLs+Hl6v+Oi0EjKoqVGw=; b=FE8JO6G2FC2LN9LRfxO8JC1zcOYD8p79JwblsTCdvw+HETKRl1qYtuFao3GJ1cn9k0 Yu7pzPYZpk6OHjjdjoh1WBJZHt6s5cuE954MfHPoztKvITO1t8CBHOXMpHYMJfbDIHeH TJTAmrPKs0pL4avp+EMaOuclniWL0MjJ5URGDkD+KuHBlETcXHb9w9WniHEtvVIyiFhr qtoFhDkbx15ycWXpLAKr32KsrEn/QDEIidSpr4ZdWIELD6QcsirudHXGNknzdn7lx6Gp SAgbbd+HYRF4jJTsuEZ4jn7zdW2xJdDBPB0GFmO0PRE93q7iv0jcAMuCfsOU+hYrG31l 0iTQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vlm0vRlSx5YbGIPqCOuB7/AqLs+Hl6v+Oi0EjKoqVGw=; b=Pld02SXTaGSR/kUZjD92aLWBP0wKdLAb0BQ87CZuM8WxIqHgR0LEo20uJqbFfcTn2r NMxNyJcEcm4zd7z7/z1b8DigesSukAhXI6qp86lvnihHxrWyZdnvJd6aDKWZt9SZ/sYz SAikjkixswIbGZGa6Py8avxEfgYtTYgjrwOM2jgLi6qYd21nZh8q3Ws9KMs5Irabyloh 0QtHwtS2yX3bvCtyPD6xwACvQSLZ3W7xj3WeKvjx0Fmw2cHxoADZxNd8rfMNfUco6DTc 6J/5S3EEmb2PBEqKI0NRfKu1H50aqaXlAvH1rz0+QY0kKLDiv/gIZ1mBHywMmn2ajTHv Lrow== X-Gm-Message-State: AOAM5313bk61MvTgXuDS0g8XeIAw8TwgpMuSqZC9FETQQG/boZRP0GwX YfJcVlkkhZb9yZectfsjRrPU/iEw X-Google-Smtp-Source: ABdhPJy3ohNXkaaZhuxn/Fk6T6gmp+Y4SLoqqiX7Y6XxduJszM+OOBBfOp6+MpVwoI2b1eYyXz9pDA== X-Received: by 2002:a37:b3c7:: with SMTP id c190mr24190289qkf.466.1590375067957; Sun, 24 May 2020 19:51:07 -0700 (PDT) Received: from shine.lan ([2001:470:8:67e:344b:9349:9475:b6a2]) by smtp.gmail.com with ESMTPSA id h134sm13539512qke.6.2020.05.24.19.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 19:51:07 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Subject: [PATCH 8/8] vchan-socket-proxy: Handle closing shared input/output_fd Date: Sun, 24 May 2020 22:49:55 -0400 Message-Id: <20200525024955.225415-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525024955.225415-1-jandryuk@gmail.com> References: <20200525024955.225415-1-jandryuk@gmail.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , marmarek@invisiblethingslab.com, Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" input_fd & output_fd may be the same FD. In that case, mark both as -1 when closing one. That avoids a dangling FD reference. Signed-off-by: Jason Andryuk --- tools/libvchan/vchan-socket-proxy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c index a04b46ee04..07ead251a2 100644 --- a/tools/libvchan/vchan-socket-proxy.c +++ b/tools/libvchan/vchan-socket-proxy.c @@ -342,6 +342,8 @@ int data_loop(struct vchan_proxy_state *state) libxenvchan_wait(state->ctrl); } close(state->input_fd); + if (state->input_fd == state->output_fd) + state->output_fd = -1; state->input_fd = -1; /* TODO: maybe signal the vchan client somehow? */ break;