From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_2 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7F69C63697 for ; Thu, 26 Nov 2020 18:29:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 C1D3F21D7F for ; Thu, 26 Nov 2020 18:29:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1D3F21D7F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kiM0z-0006Zz-Rt for qemu-devel@archiver.kernel.org; Thu, 26 Nov 2020 13:29:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiLzS-0005cB-S0; Thu, 26 Nov 2020 13:27:34 -0500 Received: from smtpout1.mo804.mail-out.ovh.net ([79.137.123.220]:55839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiLzQ-0001cU-MF; Thu, 26 Nov 2020 13:27:34 -0500 Received: from mxplan5.mail.ovh.net (unknown [10.108.20.177]) by mo804.mail-out.ovh.net (Postfix) with ESMTPS id ABF6475ACA19; Thu, 26 Nov 2020 19:27:21 +0100 (CET) Received: from kaod.org (37.59.142.105) by DAG8EX1.mxp5.local (172.16.2.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Thu, 26 Nov 2020 19:27:21 +0100 Authentication-Results: garm.ovh; auth=pass (GARM-105G006b7b33361-ce64-401b-b4ad-2cc815f99f38, 3D9671329B6E73EAAA72C004E5562AE56C463AC8) smtp.auth=groug@kaod.org Date: Thu, 26 Nov 2020 19:27:19 +0100 From: Greg Kurz To: Christian Schoenebeck Subject: Re: [PATCH] virtfs-proxy-helper: Fix a resource leak in main() Message-ID: <20201126192719.7ea20846@bahia.lan> In-Reply-To: <2017010.0bgJjaKMus@silver> References: <20201126101624.55714-1-alex.chen@huawei.com> <20201126130734.56f2a84a@bahia.lan> <5FBFAA87.5000400@huawei.com> <2017010.0bgJjaKMus@silver> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [37.59.142.105] X-ClientProxiedBy: DAG1EX1.mxp5.local (172.16.2.1) To DAG8EX1.mxp5.local (172.16.2.71) X-Ovh-Tracer-GUID: 3511e01f-556f-409d-882d-cd562bc06e2a X-Ovh-Tracer-Id: 17548557425123498403 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedujedrudehvddguddugecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvuffkjghfofggtgfgihesthejredtredtvdenucfhrhhomhepifhrvghgucfmuhhriicuoehgrhhouhhgsehkrghougdrohhrgheqnecuggftrfgrthhtvghrnhepfedutdeijeejveehkeeileetgfelteekteehtedtieefffevhffflefftdefleejnecukfhppedtrddtrddtrddtpdefjedrheelrddugedvrddutdehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepmhigphhlrghnhedrmhgrihhlrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehgrhhouhhgsehkrghougdrohhrghdprhgtphhtthhopeiihhgrnhhgrdiihhgrnhhghhgrihhlihgrnhhgsehhuhgrfigvihdrtghomh Received-SPF: pass client-ip=79.137.123.220; envelope-from=groug@kaod.org; helo=smtpout1.mo804.mail-out.ovh.net X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_BL_SPAMCOP_NET=1.347, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Chen , qemu-trivial@nongnu.org, qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Thu, 26 Nov 2020 18:52:39 +0100 Christian Schoenebeck wrote: > On Donnerstag, 26. November 2020 14:15:51 CET Alex Chen wrote: > > Hi Greg, > > > > Thanks for your review. > > > > On 2020/11/26 20:07, Greg Kurz wrote: > > > On Thu, 26 Nov 2020 10:16:24 +0000 > > > > > > Alex Chen wrote: > > >> Only one of the options -s and -f can be used. When -f is used, > > >> the fd is created externally and does not need to be closed. > > So somebody is really using the 9p proxy driver for something; interesting. > > > > > > > The process running virtfs-proxy-helper has its own copy of > > > the fd inherited from its parent. And this fd will be closed > > > eventually when the process terminates. > > > > > >> When -s is used, a new socket fd is created, and this socket fd > > >> needs to be closed at the end of main(). > > > > > > Same here, the new socket fd is closed when the process > > > terminates. > > Does it? I haven't reviewed much of the 9p proxy code yet, however if chroot() > fails for instance, the fd would leak right now, wouldn't it? > This is done just at the end of main()... the leak won't last long. > Or was your argument that it's the OS's job to free any file descriptor > automatically on process terminations in general? > That's exactly my point. The only justification that'd deserve to be in the changelog of such a patch is something like "because this is good practice to rollback in case code moves to another function than main()". > > IMO, it's best to explicitly release resources before the process > > terminates, just as the variable 'rpath' is explicitly freed in main(), > > so socket fd also needs to be explicitly closed here. > > > > Looking forward to your reply. > > > > > The only justification to merge such a change would be if > > > the code was sitting in some other function, in which > > > case we should indeed do proper rollback. But it is main() > > > here, so this patch isn't needed. > > > > > >> Reported-by: Euler Robot > > > > > > Can you provide a copy of the report in case I'm > > > missing something ? > > > > Our codecheck tool reports a resource leak here, which is relatively simple, > > like the one below, I did not attach it. > > > > --------------------- > > "Resource leak: sock" > > --------------------- > > Yeah, not very helpful that output. > Indeed :D > > > > Thanks, > > Alex > > Best regards, > Christian Schoenebeck > >