NetBSD Problem Report #57883

From www@netbsd.org  Sun Jan 28 15:27:04 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id B7F561A9238
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 28 Jan 2024 15:27:04 +0000 (UTC)
Message-Id: <20240128152703.1B2AC1A9239@mollari.NetBSD.org>
Date: Sun, 28 Jan 2024 15:27:03 +0000 (UTC)
From: hpaluch@seznam.cz
Reply-To: hpaluch@seznam.cz
To: gnats-bugs@NetBSD.org
Subject: Tar opens /dev/(r)fd0* devices on backup hanging when floppy is empty
X-Send-Pr-Version: www-1.0

>Number:         57883
>Category:       bin
>Synopsis:       Tar opens /dev/(r)fd0* devices on backup hanging when floppy is empty
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 28 15:30:00 +0000 2024
>Last-Modified:  Mon Jan 29 06:35:01 +0000 2024
>Originator:     Henryk Paluch
>Release:        NetBSD 9.3 RELEASE
>Organization:
personal
>Environment:
NetBSD netbsd-ssd 9.3 NetBSD 9.3 (GENERIC) #0: Thu Aug  4 15:30:37 UTC 2022  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
When I use ordinary tar to backup /dev directory it will actually access all floppy devices there (It will open each device and query it for extattr_list_fd).

When floppy drive is empty, tar will hang for around 30s for each /dev/fd0* and /dev/rfd0* device - making it nearly impossible to backup /dev in reasonable time.
>How-To-Repeat:
Required bare-metal machine with empty floppy drive. Tried also guest under KVM/Qemu, but it has much shorter timeouts (and no noise) so it was not much noticeable.

Run tar to backup whole /dev/ or just singe floppy character device:

ls -l /dev/rfd0

crw-r-----  1 root  operator  9, 3 Jan 28 08:39 /dev/rfd0

tar cvf /root/backup.tar -C / dev/rfd0

Above tar command will take 31 seconds to backup single character device /dev/rfd0 because it will open it which will make kernel trying read floppy disk and throwing these error message (dmesg output):

[  1798.055846] fdcresult: timeout
[  1802.712653] fdcresult: timeout
[  1802.712653]  (st0 0x20<seek_cmplt> cyl 0)
[  1802.712653] fd0: timeout<3>fdcresult: timeout
[  1810.256803]  (st0 0x20<seek_cmplt> cyl 0)
[  1810.256803] fd0: timeout<3>fdcresult: timeout
[  1817.800953]  (st0 0x20<seek_cmplt> cyl 0)
[  1817.800953] fd0: timeout<3>fdcresult: timeout
[  1825.345103]  (st0 0x20<seek_cmplt> cyl 0)
[  1825.345103] fd0: timeout<3>fdcresult: timeout
[  1829.656978]  (st0 0x20<seek_cmplt> cyl 0)
[  1829.656978] fd0: timeoutfd0d: hard error reading fsbn 0 of 0-2 (st0 0x20<seek_cmplt> st1 0x0 st2 0x0 cyl 0 head 0 sec 0)

Here is relevant output of ktrace/kdump -R which clearly shows that TAR really opens character device, hangs for 31 seconds and attempts to get extattr_list(?)

  6409      1 tar      0.000017480 CALL  openat(5,0x77ac7a933100,4,0)
  6409      1 tar      0.000002600 NAMI  "dev/rfd0"
  6409      1 tar      31.881039760 RET   openat 6
  6409      1 tar      0.000019280 CALL  extattr_list_fd(6,1,0,0)
  6409      1 tar      0.000003480 RET   extattr_list_fd -1 errno 45 Operation not supported
  6409      1 tar      0.000012640 CALL  close(6)


>Fix:
When formatted floppy is inserted in drive, backup of /dev with tar will finish in acceptable time (however it still tries to access floppy several times).

Expected behaviour: TAR should never open backed block or char devices (should just backup node type, major, minor and permissions), because it may have significant and unexpected side effects - including loss of data.

>Audit-Trail:
From: =?ISO-8859-1?Q?J=F6rg?= Sonnenberger <joerg@bec.de>
To: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, gnats-bugs@netbsd.org
Cc: 
Subject:  Re: bin/57883: Tar opens /dev/(r)fd0* devices on backup hanging when floppy
 is empty
Date: Mon, 29 Jan 2024 01:14:07 +0100

 > >Fix:
 > When formatted floppy is inserted in drive, backup of /dev with tar will finish in acceptable time (however it still tries to access floppy several times).
 > 
 > Expected behaviour: TAR should never open backed block or char devices (should just backup node type, major, minor and permissions), because it may have significant and unexpected side effects - including loss of data.

 There is no race free way to get those. There are hundreds of ways to trick
 a program into open a device. It's the fault of the device driver for having
 unusual side effects on open.

 Joerg




From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/57883: Tar opens /dev/(r)fd0* devices on backup hanging when
 floppy is empty
Date: Mon, 29 Jan 2024 00:32:44 +0000 (UTC)

 On Sun, 28 Jan 2024, hpaluch@seznam.cz wrote:

 >> Description:
 > When I use ordinary tar to backup /dev directory it will actually access all floppy devices there (It will open each device and query it for extattr_list_fd).
 >
 > When floppy drive is empty, tar will hang for around 30s for each /dev/fd0* and /dev/rfd0* device - making it nearly impossible to backup /dev in reasonable time.
 >

 Dup of PR bin/55815: tar opens device files

 -RVP

From: mlelstv@serpens.de (Michael van Elst)
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/57883: Tar opens /dev/(r)fd0* devices on backup hanging when floppy is empty
Date: Mon, 29 Jan 2024 06:31:54 -0000 (UTC)

 joerg@bec.de (=?ISO-8859-1?Q?J=F6rg?= Sonnenberger) writes:

 >There is no race free way to get those. There are hundreds of ways to trick
 >a program into open a device.

 True. But the current behaviour of tar doesn't require any tricks as
 opening a device is enforced.


 >It's the fault of the device driver for having
 >unusual side effects on open.

 Device drivers always had usual side effects on open or close.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.