From owner-freebsd-questions@FreeBSD.ORG Sat May 24 17:08:17 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C69A923B for ; Sat, 24 May 2014 17:08:17 +0000 (UTC) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6007B2B8B for ; Sat, 24 May 2014 17:08:16 +0000 (UTC) Received: from r56.edvax.de (port-92-195-4-63.dynamic.qsc.de [92.195.4.63]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id 602BC276F5; Sat, 24 May 2014 19:08:13 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id s4OH8CX2001997; Sat, 24 May 2014 19:08:12 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sat, 24 May 2014 19:08:12 +0200 From: Polytropon To: Arthur Chance Subject: Re: write-protected usb flash drive Message-Id: <20140524190812.ffe1a488.freebsd@edvax.de> In-Reply-To: <5380CEB3.3040002@qeng-ho.org> References: <537FE744.3030002@dreamchaser.org> <20140524080127.f2e788d5.freebsd@edvax.de> <5380AB17.2070300@dreamchaser.org> <5380B953.5090700@qeng-ho.org> <20140524174102.66eff3da.freebsd@edvax.de> <5380CEB3.3040002@qeng-ho.org> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing List X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 May 2014 17:08:17 -0000 On Sat, 24 May 2014 17:54:11 +0100, Arthur Chance wrote: > On 24/05/2014 17:32, Warren Block wrote: > > On Sat, 24 May 2014, Polytropon wrote: > > > >> On Sat, 24 May 2014 16:22:59 +0100, Arthur Chance wrote: > >>> OK, thought I'd better try my own advice rather than just handing it > >>> out. I put a microSD card out of an old phone into a SanDisk mSD -> SD > >>> adapter and plugged that into my SanDisk SD -> USB adapter, mounted it > >>> (FAT32 file system already on it) and wrote a file to it. Worked as > >>> you'd expect. I then unmounted and unplugged it, flipped the write > >>> protect switch and tried to remount. Result was > >>> > >>> mount_msdosfs: /dev/da5s1: Input/output error > >>> > >>> Mounting it read-only was fine. So, the write protect is honoured by at > >>> least some SD -> USB adapters. > >> > >> This is already on file system level. It _should_ work the same > >> at upper layers, for example when using dd to write NULs to the > >> device with the write protection on - an error should (correctly) > >> occur in that case. > >> > >> When a r/o mount is forced, the routines accessing that file > >> system cannot avoid the write protection. Still writes are > >> possible _aside of_ the file system which should be prevented > >> by the switch as well. It's probably a good idea to check that > >> too, e. g. put in the card with write protection on and then > >> try dd or newfs on it. > > > > These are worthwhile tests, but remember that they are done in an > > environment where everything is playing by the rules and trying to do > > the right thing. The drivers will try to support the write-protect switch. This is, on FreeBSD for example, things work as they are supposed to work. > > Malicious software could use custom or patched drivers to ignore the > > settings of the switch or anything else. This is especially problematic in closed-source products where no real indication of operating system and driver functionality can be obtained. "Trial & error" is the only way here, and even then you can't be fully sure. > > The card reader microcontroller might be responsible for the write > > protect, which would make it much safer than just being honored by > > higher-level drivers. > > I'm not sure how one could easily test that. It seems there are too many "moving parts" involved here. :-( > I will note that when I tried using dd to write to a write protected > card the IO indication light on the USB adapter blinked, which I presume > meant the write attempt wasn't thwarted at the driver level, but I'd > have to plough through at least the umass and cam code to even start to > get some degree of certainty on that. A good idea! Think about "camcontrol format" for example. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...