Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6023571ybe; Tue, 10 Sep 2019 12:18:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfVVSUqh5yRI/Vs0fUvc81OhCP4ByWunaxmQ+2oj0y95Jwj8Jme2SGQqmK/FwcAscXqSiW X-Received: by 2002:aa7:c1d0:: with SMTP id d16mr21940716edp.82.1568143106976; Tue, 10 Sep 2019 12:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568143106; cv=none; d=google.com; s=arc-20160816; b=loUGv2SDZy8ZTd/TLvTK5nxOnei9WKIe9sSa/GgustI+ILKISNSGgBrPOY1Zz4oarX Z9Ud1+ejP3bDY4jNQ6OUTHEZHDq3Ny4DyN5koif/gTT5LL9r0oZmVdMsRSt4l76WdJHA AUINaTR3r3f4G5jAFza1o6hSLHinZmsebO50tOERn50Z+fSsWDUPKRP+FUCb5G3Zbi5M vVE4FMYE7RXVXWeUD1J95nh0gp1si6s8oP51MFMIWQPuZxr0HNOUMOvI6DnAZRgdJhtW NIMzeiVmnCusbAb/n3xOrh7+ErCd9w0cPHhE5+1bL+ZzXwLaaO9IUY99V5Kb1en1XXqi r92A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=FRcQL1GjkhCQgIcEqhlR8Ih5N2Sc6cLa2PVDy28KLXQ=; b=aSPzxV9oUpQjUYjeZc8klwCzRkjUEcUf171K+HgMvuhgwMADBDPRKkGIonNJE7UxyU KL9if2VmX7WVFFs/uLTbA4Xg91wHdpeuvVQztZfbzc/DDXXkCy9JMDvUHPa9b2APEQk0 uKctVIPSZG2LukhAdovlXk43yXuczHsPWwpOanyB8rCQMDeGgpJDo+qGfS4KCrz5ONyl NBrz12+7xKoz57ObzhsAy75K0U9wysabOWIWZx6YrEfVLu0kerYury0HzbQ4tjLvuzWq /JWs0ZP7G2vzggTETKs9E7I9T3qci3EMepmgx4z3CKF6x1+YvUqgC8evvPoJXNMjlGEe /fDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f14si11358987edd.134.2019.09.10.12.18.02; Tue, 10 Sep 2019 12:18:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436776AbfIJQ1L (ORCPT + 99 others); Tue, 10 Sep 2019 12:27:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34017 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436494AbfIJQ1L (ORCPT ); Tue, 10 Sep 2019 12:27:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC52C3016F49; Tue, 10 Sep 2019 16:27:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A009C60BFB; Tue, 10 Sep 2019 16:27:10 +0000 (UTC) Received: from zmail17.collab.prod.int.phx2.redhat.com (zmail17.collab.prod.int.phx2.redhat.com [10.5.83.19]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9008224F2F; Tue, 10 Sep 2019 16:27:10 +0000 (UTC) Date: Tue, 10 Sep 2019 12:27:10 -0400 (EDT) From: Jan Stancek To: OGAWA Hirofumi Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, systemd-devel@lists.freedesktop.org, Jan Stancek Message-ID: <1802022622.11216716.1568132830207.JavaMail.zimbra@redhat.com> In-Reply-To: <87r24o24eo.fsf@mail.parknet.co.jp> References: <87v9u3xf5q.fsf@mail.parknet.co.jp> <339755031.10549626.1567969588805.JavaMail.zimbra@redhat.com> <87r24o24eo.fsf@mail.parknet.co.jp> Subject: Re: [PATCH] fat: fix corruption in fat_alloc_new_dir() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.43.17.163, 10.4.195.13] Thread-Topic: fix corruption in fat_alloc_new_dir() Thread-Index: btCRHWvdReVkaymHhT2xSAQwL/tLmw== X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 10 Sep 2019 16:27:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Original Message ----- > Jan Stancek writes: > > >> Using the device while mounting same device doesn't work reliably like > >> this race. (getblk() is intentionally used to get the buffer to write > >> new data.) > > > > Are you saying this is expected even if 'usage' is just read? > > Yes, assuming exclusive access. Seems we were lucky so far to only hit this with FAT. I also tried couple variations of reproducer: - Disabling udevd and running just "blkid --probe" in parallel also reproduced it - Disabling udevd and running read() on first 1024 sectors in parallel also reproduced it - aio_read() submitted prior to mount could reproduce it, as long as fd was held open - I couldn't reproduce it with fadvise/madvise WILLNEED submitted prior to mount > > >> mount(2) internally opens the device by EXCL mode, so I guess udev opens > >> without EXCL (I dont know if it is intent or not). > > > > I gave this a try and added O_EXCL to udev-builtin-blkid.c. My system had > > trouble > > booting, it was getting stuck on mounting LVM volumes. > > > > So, I'm not sure how to move forward here. > > OK. I'm still think the userspace should avoid to use blockdev while > mounting though, this patch will workaround this race with small race. https://systemd.io/BLOCK_DEVICE_LOCKING.html mentions flock(LOCK_EX) as a way to avoid probing while "another program concurrently modifies a superblock or partition table". Adding flock(LOCK_EX) works around the problem too, but that would address problem only for LTP (and tools/scripts that use this approach). > > Can you test this? > > Thanks. > -- > OGAWA Hirofumi > > > [PATCH] fat: Workaround the race with userspace's read via blockdev while > mounting I ran reproducer on patched kernel for 5 hours, it made over 25000 iterations, there was no corruption. Thank you for looking at this. Regards, Jan