>Synopsis: rm -P doesn't overwrite a user owned read-only file
>Category: user
>Environment:
System : OpenBSD 5.6
Details : OpenBSD 5.6 (GENERIC) #274: Fri Aug 8 00:05:13 MDT 2014
[email protected]:/usr/src/sys/arch/i386/compile/GENERIC
Architecture: OpenBSD.i386
Machine : i386
>Description:
When rm(1) a user owned read-only file, with the -P pattern overwrite
option,
rm removes the file without overwriting it.
rm exits with 'Permission denied' (code 1), yet the file is removed.
As the file is user owned, could it be auto chmoded +w before overwite,
to ensure the random pattern deletion takes place?
>How-To-Repeat:
### OK:
$ secrets=$(mktemp)
$ print 'Wonky donkey' > $secrets
$ ls -l $secrets
-rw------- 1 craig wheel 13 Feb 26 10:18 /tmp/tmp.8ryBzZfPEH
$ rm -iP $secrets
remove /tmp/tmp.8ryBzZfPEH? y
$ print $?
0
$ ls -l $secrets
ls: /tmp/tmp.8ryBzZfPEH: No such file or directory
### Problem:
$ secrets=$(mktemp)
$ print 'Honky donkey' > $secrets
$ chmod -w $secrets
$ ls -l $secrets
-r-------- 1 craig wheel 13 Feb 26 10:23 /tmp/tmp.yJ6WgAE54n
$ rm -iP $secrets
remove /tmp/tmp.yJ6WgAE54n? y
rm: /tmp/tmp.yJ6WgAE54n: Permission denied
$ print $?
1
$ ls -l $secrets
ls: /tmp/tmp.yJ6WgAE54n: No such file or directory
>Fix:
dmesg:
OpenBSD 5.6 (GENERIC) #274: Fri Aug 8 00:05:13 MDT 2014
[email protected]:/usr/src/sys/arch/i386/compile/GENERIC
cpu0: Intel Pentium II ("GenuineIntel" 686-class, 512KB L2 cache) 349 MHz
cpu0:
FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,PSE36,MMX,FXSR,PERF
real mem = 536363008 (511MB)
avail mem = 515149824 (491MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: AT/286+ BIOS, date 07/19/99, BIOS32 rev. 0 @ 0xfd861, SMBIOS
rev. 2.1 @ 0xf7d95 (32 entries)
bios0: vendor IBM version "PDKT27AUS" date 07/19/99
bios0: IBM 6275500
acpi0 at bios0: rev 0
acpi0: sleep states S0 S1 S4 S5
acpi0: tables DSDT FACP
acpi0: wakeup devices PCI0(S5) PS2K(S1) PS2M(S1) COM1(S5) COM2(S5) USB0(S1)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpiprt0 at acpi0: bus 0 (PCI0)
acpicpu0 at acpi0
bios0: ROM list: 0xc0000/0x8000
cpu0 at mainbus0: (uniprocessor)
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
pci0 at mainbus0 bus 0: configuration mode 1 (bios)
pchb0 at pci0 dev 0 function 0 "Intel 82443BX AGP" rev 0x03
intelagp0 at pchb0
agp0 at intelagp0: aperture at 0xec000000, size 0x4000000
ppb0 at pci0 dev 1 function 0 "Intel 82443BX AGP" rev 0x03
pci1 at ppb0 bus 1
vga1 at pci1 dev 1 function 0 "S3 Trio3D AGP" rev 0x01
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
piixpcib0 at pci0 dev 2 function 0 "Intel 82371AB PIIX4 ISA" rev 0x02
pciide0 at pci0 dev 2 function 1 "Intel 82371AB IDE" rev 0x01: DMA, channel 0
wired to compatibility, channel 1 wired to compatibility
wd0 at pciide0 channel 0 drive 0: <ST3250820A>
wd0: 16-sector PIO, LBA48, 238475MB, 488397168 sectors
wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 2
wd1 at pciide0 channel 1 drive 0: <Maxtor 5A320J0>
wd1: 16-sector PIO, LBA48, 308921MB, 632672208 sectors
atapiscsi0 at pciide0 channel 1 drive 1
scsibus1 at atapiscsi0: 2 targets
cd0 at scsibus1 targ 0 lun 0: <TEAC, DV-516D, 1.06> ATAPI 5/cdrom removable
wd1(pciide0:1:0): using PIO mode 4, Ultra-DMA mode 2
cd0(pciide0:1:1): using PIO mode 4, Ultra-DMA mode 2
uhci0 at pci0 dev 2 function 2 "Intel 82371AB USB" rev 0x01: irq 10
piixpm0 at pci0 dev 2 function 3 "Intel 82371AB Power" rev 0x02: SMI
iic0 at piixpm0
spdmem0 at iic0 addr 0x50: 256MB SDRAM non-parity PC133CL2
spdmem1 at iic0 addr 0x51: 256MB SDRAM non-parity PC133CL2
spdmem2 at iic0 addr 0x55: 1GB DDR2 SDRAM PC2-6500CL5
xl0 at pci0 dev 16 function 0 "3Com 3c905B 100Base-TX" rev 0x30: irq 11,
address 00:10:5a:f2:85:2c
exphy0 at xl0 phy 24: 3Com internal media interface
xl1 at pci0 dev 18 function 0 "3Com 3c905B 100Base-TX" rev 0x30: irq 9, address
00:10:5a:f1:9d:a7
exphy1 at xl1 phy 24: 3Com internal media interface
isa0 at piixpcib0
isadma0 at isa0
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com0: console
com1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo
pckbc0 at isa0 port 0x60/5
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
lpt0 at isa0 port 0x378/4 irq 7
npx0 at isa0 port 0xf0/16: reported by CPUID; using exception 16
fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
usb0 at uhci0: USB revision 1.0
uhub0 at usb0 "Intel UHCI root hub" rev 1.00/1.00 addr 1
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
root on wd0a (0e3aa2ac975978d6.a) swap on wd0b dump on wd0b
acpi0: PM1 stuck (en 0x500 st 0x400), clearing
usbdevs:
Controller /dev/usb0:
addr 1: full speed, self powered, config 1, UHCI root hub(0x0000),
Intel(0x8086), rev 1.00
port 1 powered
port 2 powered