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=-6.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 6D5D6C433DF for ; Thu, 25 Jun 2020 13:27:59 +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 488F720781 for ; Thu, 25 Jun 2020 13:27:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 488F720781 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1joRus-00038o-Kq; Thu, 25 Jun 2020 13:27:46 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1joRur-00038d-Hs for xen-devel@lists.xenproject.org; Thu, 25 Jun 2020 13:27:45 +0000 X-Inumbo-ID: a6d72c52-b6e7-11ea-81b8-12813bfff9fa Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a6d72c52-b6e7-11ea-81b8-12813bfff9fa; Thu, 25 Jun 2020 13:27:44 +0000 (UTC) Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: SWtdBJRQAudwXIRNa0FPay5Mh7nIrZFc4DeCcEhl7mIaI1gZ6V/h1YGQ7y6UV71voheIS/lmrZ Zj6oJh6T5ACJq0NUWkAwNDb5yKCMn169xBZJTIt9f57nqU96LkKasmqvsYEVUJ1I6HNTlgbl4D dUc+d0NXRkLcnXv4qQ5T0u+wVhNbF+kWwZxz1YNS2H7Pr0HLH/Pe4zWBflT6zn7K5r7TQZH8kU E6wkuEhlj3cJQpavht/686f58pLSVqTnV2gnVZRF6LxTAEDbmt5IgDmBy7vNsiS04SFwaZjtR/ ixc= X-SBRS: 2.7 X-MesageID: 20917201 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,279,1589256000"; d="scan'208";a="20917201" From: Ian Jackson MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-ID: <24308.42571.430322.191817@mariner.uk.xensource.com> Date: Thu, 25 Jun 2020 14:27:39 +0100 To: Jason Andryuk Subject: Re: [XEN RFC for-4.14] Re: use of "stat -" In-Reply-To: References: <3bfd6384-fcaf-c74a-e560-a35aafa06a43@suse.com> <20200512141947.yqx4gmbvqs4grx5g@liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net> <4b90b635-84bb-e827-d52e-dfe1ebdb4e4d@citrix.com> <814db557-4f6a-020d-9f71-4ee3724981e3@suse.com> <20200512195005.GA96154@mattapan.m5p.com> <049e0022-f9c1-6dc9-3360-d25d88eeb97f@citrix.com> <20200512225458.GA1530@mattapan.m5p.com> <24253.9543.974853.499775@mariner.uk.xensource.com> <0b449d5a-9629-8e41-5354-b985a063eba4@suse.com> <24307.32018.502303.817846@mariner.uk.xensource.com> X-Mailer: VM 8.2.0b under 24.5.1 (i686-pc-linux-gnu) 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: Jan Beulich , Wei Liu , Paul Durrant , Andrew Cooper , Elliott Mitchell , "xen-devel@lists.xenproject.org" Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Jason Andryuk writes ("Re: [XEN RFC for-4.14] Re: use of "stat -""): > I was going to just write a patch to replace - with /dev/stdin and ask > Jan to test it. When I opened the script, this comment was staring at > me: > # We can't just stat /dev/stdin or /proc/self/fd/$_lockfd or > # use bash's test -ef because those all go through what is > # actually a synthetic symlink in /proc and we aren't > # guaranteed that our stat(2) won't lose the race with an > # rm(1) between reading the synthetic link and traversing the > # file system to find the inum. > > On my system: > $ ls -l /dev/stdin > lrwxrwxrwx 1 root root 15 Jun 24 21:13 /dev/stdin -> /proc/self/fd/0 > $ ls -l /proc/self/fd/0 0 lrwx------ 1 jason jason 64 Jun 24 21:26 /proc/self/fd/0 -> /home/jason/lockfile > > stat /dev/stdin will work around the lack of `stat -` support, but it > doesn't address the race in the comment. Is the comment valid? Thanks, but: The tests in my transcript show that the comment (which I wrote) is false. It shows that stat /dev/stdin works on deleted files, and stats the right file even if the name has been rused. > How would we prove there is no race for /dev/stdin? It is easy to create the "bad" situation by hand, without racing. The transcript shows that the output from readlink(2) is a fiction and that stat works to stat the actual open-file. > I've mentioned it before, but maybe we should just use the Qubes > patch. It leaves the lockfile even when no-one is holding the lock, > but it simplifies the code and sidesteps the issues we are discussing > here. > https://github.com/QubesOS/qubes-vmm-xen/blob/xen-4.13/patch-tools-hotplug-drop-perl-usage-in-locking-mechanism.patch I don't like that because this locking code might be reused (or maybe already is used) in contexts with a varying lockfile filename, leaving many lockfiles. And because having lockfiles lying about might confuse sysadmins who are used to programs which use (the broken) LOCK_EX-style locking paradigm. So tl;dr: yes, we need that patch to replace - with /dev/stdin. Thanks, Ian.