From patchwork Mon May 8 22:00:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9716757 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 6BA3760365 for ; Mon, 8 May 2017 22:01:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6724E20683 for ; Mon, 8 May 2017 22:01:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BD0A24B5B; Mon, 8 May 2017 22:01:07 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 14A2220683 for ; Mon, 8 May 2017 22:01:06 +0000 (UTC) Received: from localhost ([::1]:33880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7qiH-0003fz-W6 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 May 2017 18:01:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7qhk-0003fs-5R for qemu-devel@nongnu.org; Mon, 08 May 2017 18:00:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7qhg-0000Kg-9g for qemu-devel@nongnu.org; Mon, 08 May 2017 18:00:32 -0400 Received: from mail.kernel.org ([198.145.29.136]:49342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d7qhg-0000KK-4A for qemu-devel@nongnu.org; Mon, 08 May 2017 18:00:28 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58F5A20219; Mon, 8 May 2017 22:00:26 +0000 (UTC) Received: from [10.149.184.130] (unknown [99.165.194.18]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D94B20220; Mon, 8 May 2017 22:00:25 +0000 (UTC) Date: Mon, 8 May 2017 15:00:24 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: Stefano Stabellini In-Reply-To: Message-ID: References: <1f0bf90b-a706-01c8-cad1-6dea6620deef@redhat.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 198.145.29.136 Subject: Re: [Qemu-devel] [PATCH] Fix issues affecting Xen 9pfs discovered by Coverity 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: xen-devel@lists.xensource.com, groug@kaod.org, qemu-devel@nongnu.org, aneesh.kumar@linux.vnet.ibm.com, anthony.perard@citrix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 8 May 2017, Stefano Stabellini wrote: > On Mon, 8 May 2017, Eric Blake wrote: > > On 05/08/2017 03:45 PM, Stefano Stabellini wrote: > > > Fix two resource leaks on error paths, discovered by Coverity. > > > Check for errors returned by fcntl, also found by Coverity. > > > > > > CID:1374836 > > > CID:1374831 > > > > > > > > @@ -378,7 +380,10 @@ static int xen_9pfs_connect(struct XenDevice *xendev) > > > if (xen_9pdev->rings[i].evtchndev == NULL) { > > > goto out; > > > } > > > - fcntl(xenevtchn_fd(xen_9pdev->rings[i].evtchndev), F_SETFD, FD_CLOEXEC); > > > + if (fcntl(xenevtchn_fd(xen_9pdev->rings[i].evtchndev), > > > + F_SETFD, FD_CLOEXEC) == -1) { > > > + goto out; > > > > Directly calling fcntl(F_SETFD) without first reading fcntl(F_GETFD) is > > (theoretically) incorrect. Better might be using qemu_set_cloexec() > > instead of open-coding something. > > Makes sense but the unchecked return of fcntl, discovered by Coverity, > would remain unfixed by calling qemu_set_cloexec here. I don't think I > am up for fixing all the call sites of qemu_set_cloexec. > > I am going to drop this change, and resend this patch was only the other > two fixes, fixing 1374836 only. Unless you would be fine with: diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 4d9189e..16894ad 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -182,7 +182,9 @@ void qemu_set_cloexec(int fd) { int f; f = fcntl(fd, F_GETFD); - fcntl(fd, F_SETFD, f | FD_CLOEXEC); + assert(f != -1); + f = fcntl(fd, F_SETFD, f | FD_CLOEXEC); + assert(f != -1); } /*