NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/53949: SCSI st driver /dev/{e,}nrst? file mark handling broken - may overwrite tapes
>Number: 53949
>Category: kern
>Synopsis: SCSI st driver /dev/{e,}nrst? file mark handling broken - may overwrite tapes
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Feb 05 13:50:01 +0000 2019
>Originator: Frank Kardel
>Release: NetBSD 8.99.34
>Organization:
>Environment:
System: NetBSD pip.kardel.name 8.99.34 NetBSD 8.99.34 (GENERIC) #2: Sun Feb 3 13:31:03 CET 2019 kardel%pip.kardel.name@localhost:/src/NetBSD/cur/src/obj.amd64/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
The SCSI st driver does not behave correctly with respect to file mark handling when the non-rewinding device modes are used.
Writing <data>+ <file mark> to a non-rewinding device, ejecting the tape (possible since 2012-02-28 -
ALLOW for robots within mount session), loading the same or another tape will lead to a file mark
being written at the beginning of the freshly loaded tape even if opened O_RDONLY => empty tape (DATA LOSS)
Additionally the SUN compatibility code to write terminating file marks when a tape is only
opened and closed in O_WRONLY mode is broken.
>How-To-Repeat:
(test program source enclosed below)
Script started on Tue Feb 5 11:09:12 2019
# TAPE=/dev/nrst1
# export TAPE
# mt st
SCSI tape drive, residual=0
ds=3<Mounted>
er=0
blocksize: 0 (0, 0, 0, 0)
density: 92 (0, 0, 0, 0)
current file number: 0
current block number: 0
>>> write above pattern
# ./tapetest -W $TAPE -S -w Block-1 -w Block-2 -f -C
OPEN(W) [ds=3, err=0, res=0, file=0, blk=2]
MTREW [ds=3, err=0, res=0, file=0, blk=0]
WRITE Block-1... [ds=3, err=0, res=0, file=0, blk=1]
WRITE Block-2... [ds=3, err=0, res=0, file=0, blk=2]
MTWEOF [ds=3, err=0, res=0, file=1, blk=2]
CLOSE
>>> re-read with MTREW (properly terminates tape)
# ./tapetest -R $TAPE -S -r Block-1 -r Block-2 -C
OPEN(R) [ds=3, err=0, res=0, file=1, blk=2]
MTREW [ds=3, err=0, res=0, file=0, blk=0]
READ Block-1[1024]... OK [ds=3, err=0, res=0, file=0, blk=1]
READ Block-2[1024]... OK [ds=3, err=0, res=0, file=0, blk=2]
CLOSE
>>> remove tape from drive
# chio move drive 0 slot 13
>>> insert tape into drive
# chio move slot 13 drive 0
# ./tapetest -R $TAPE -r Block-1 -r Block-2 -C
>>> OPEN O_RDONLY - observe UNIT ATTENTION error (err=6)
OPEN(R) [ds=3, err=6, res=0, file=0, blk=0]
READ Block-1[1024]... OK [ds=3, err=0, res=0, file=0, blk=1]
READ Block-2[1024]... OK [ds=3, err=0, res=0, file=0, blk=2]
CLOSE
>>> write critical pattern again
# ./tapetest -W $TAPE -S -w Block-1 -w Block-2 -f -C
OPEN(W) [ds=3, err=0, res=0, file=0, blk=2]
MTREW [ds=3, err=0, res=0, file=0, blk=0]
WRITE Block-1... [ds=3, err=0, res=0, file=0, blk=1]
WRITE Block-2... [ds=3, err=0, res=0, file=0, blk=2]
MTWEOF [ds=3, err=0, res=0, file=1, blk=2]
CLOSE
>>> remove tape from drive without rewinding -> mount session still exists!
# chio move drive 0 slot 13
>>> re-insert tape (can also be another tape) into drive
# chio move slot 13 drive 0
# ./tapetest -R $TAPE -r Block-1 -r Block-2 -C
>>> OPEN O_RDONLY - observe UNIT ATTENTION error (err=6)
>>> leads to mount error due to UNIT ATTENTION in an existing mount session
>>> mount error recovery happily writes a file mark at the beginning of the
>>> inserted tape (ST_WRITTEN is still set in the mount session state)
OPEN(R) [ds=3, err=6, res=0, file=0, blk=0]
>>> discover DATA LOSS
>BOOM< READ Block-1[0]... EOF
tapetest: UNEXPECTED EOF
# exit
---
dmesg output:
st0: mount error (key=6)
Script done on Tue Feb 5 11:23:29 2019
Test program:
begin 644 tapetest.c.gz
M'XL("*Q?65P``W1A<&5T97-T+F,`I5AM4]LX$/Y,?L4V!\7A`@3N.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>`W.#*'!A;3H-.)LS@4:E<$0*43+%+;B0U+M/3E0F4M96G1(;S2F=T
M`I,?OL5R1!$I)*7;'X[,*IO)9RUG/),SRCX5]26G%=](H,N6,%6K#T]:'@=E
MUJCLFEB2J^3EIATP+P9_G?;A^W>E>H_AH"HX@3<'ASM4TNKJUG&T*1XJ2IR[
M<+"WAX>VGP%N3^ASY(^B%4M_CU8M.[A<^U*N739[WD=*K:92+0ZSQUISNRT\
M%^VWYI&B/RLJSXLY;2EZ45X,V/<ROT%9E?GNHBQRDON2[1;)?XH<DZ?C]4P=
M>3,>K;DG^)4.FR9L?VEM*]XPMRA6\Y<_?]>^1JG(1<LMM^$=;F^[[$%<'4H.
M49*7A^3(Y7OOJ8W)9.;E72#KL60GDCH@PWW.P?1_'9QI#DI3)DU9'*XWQ)OF
MN9E'1='0U;+>`S+EYSQX:E665]!Z5_0,>,[7.U&D!04D7,Y_A(UR@CT(4I53
8Q):XON0WD9O]>+8IOJ[Z#^TCD[C@%0``
`
end
>Fix:
Properly terminate the tape with sufficient file marks if a data block has been written
before close without enough file marks. This reinstates the behavior described in
"man 4 st" with respect to file marks and close(2).
Script started on Tue Feb 5 13:35:55 2019
# chio move slot 13 drive 0
# ./tapetest -W $TAPE -S -w Block-1 -w Block-2 -f -C
OPEN(W) [ds=3, err=6, res=0, file=0, blk=0]
MTREW [ds=3, err=0, res=0, file=0, blk=0]
WRITE Block-1... [ds=3, err=0, res=0, file=0, blk=1]
WRITE Block-2... [ds=3, err=0, res=0, file=0, blk=2]
MTWEOF [ds=3, err=0, res=0, file=1, blk=2]
CLOSE
# ./tapetest -R $TAPE -S -r Block-1 -r Block-2 -C
OPEN(R) [ds=3, err=0, res=0, file=1, blk=-1]
MTREW [ds=3, err=0, res=0, file=0, blk=0]
READ Block-1[1024]... OK [ds=3, err=0, res=0, file=0, blk=1]
READ Block-2[1024]... OK [ds=3, err=0, res=0, file=0, blk=2]
CLOSE
# chio move drive 0 slot 13
# chio move slot 13 drive 0
# ./tapetest -R $TAPE -r Block-1 -r Block-2 -C
OPEN(R) [ds=3, err=6, res=0, file=0, blk=0]
READ Block-1[1024]... OK [ds=3, err=0, res=0, file=0, blk=1]
READ Block-2[1024]... OK [ds=3, err=0, res=0, file=0, blk=2]
CLOSE
# ./tapetest -W $TAPE -S -w Block-1 -w Block-2 -f -C
OPEN(W) [ds=3, err=0, res=0, file=0, blk=2]
MTREW [ds=3, err=0, res=0, file=0, blk=0]
WRITE Block-1... [ds=3, err=0, res=0, file=0, blk=1]
WRITE Block-2... [ds=3, err=0, res=0, file=0, blk=2]
MTWEOF [ds=3, err=0, res=0, file=1, blk=2]
CLOSE
# chio move drive 0 slot 13
# chio move slot 13 drive 0
# ./tapetest -R $TAPE -r Block-1 -r Block-2 -C
>>> UNIT ATTENTION
OPEN(R) [ds=3, err=6, res=0, file=0, blk=0]
>GOOD< READ Block-1[1024]... OK [ds=3, err=0, res=0, file=0, blk=1]
READ Block-2[1024]... OK [ds=3, err=0, res=0, file=0, blk=2]
CLOSE
# exit
Script done on Tue Feb 5 13:41:34 2019
Patch:
begin 644 st-bugfix.diff.gz
M'XL("/)J65P``W-T+6)U9V9I>"YD:69F`*U665/C1A!^MG]%AQ2LC"5;MCF,
M"10&S):S'%O8)`^;+94LC;!B><:E&6$H(+\]W3.2C\UN+9M$+])H^NZOCSX/
MV6,'I*H%Y:/__I1OSP80Q0GK0#UXD*D0JB[3H"Z?9#UD#W49R'@6UTF=_5!.
MF4IC]A#S>TCQ)6/!H5%KMG;+81Q%X&3@I/IL[',<1W^46G#!1M!T&P?@MCJ-
M@TZS#8Z+3\EP5ZM50[B[)&RXG=UFI[5C",LG)^#L-_?MA@M5_=Z!DY,RE&"[
M7@9\2_7X"$<HQ3F.$O]>PA98@Z'W^VU_..Q=PPO@X>*J.%<.RTXICL"RK(+Z
M@JYZ%=C:`B/K");\%7AY00[`9\EQXW7/SJYNSI$)B0W_*KM;J<`S<I5BKH!/
M#\M5H_)+C3\1*5)6"TKTPSW4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