Messages in this thread Patch in this message | | | From | rohloff@informat ... | Date | Thu, 1 Oct 1998 05:02:10 +0000 | Subject | Patch for drivers/block/loop.c (for encryption to work). |
| |
Hi,
I'm very interested in encryption using the loop device. (In fact I just coded the brand new Twofish algorithm by Bruce Schneier and others as module for the linux kernel. It will be released tomorrow.)
First thanks for making the changes to loop.c so that encryption algorithms can now be written as modules.
The bad thing is that I found out that loop.c handles calls to
loop_release_xfer() wrong (The function which releases a transfer function from a loop-device).
It is called in
lo_release(), which means it is called when a loop device is closed.
This is wrong (even if it seems right :-)). The reason: As long as a loop device is associated with a file the transfer function shouldn't be released! Example:
losetup -e twofish /dev/loop0 test_file
will ask for the password, setup the loop device and then close the device again. This means that the device immediately forgets the password and the encryption, which is bad.
if this is followed by an
dd if=/dev/zero of=/dev/loop0 count=1024 bs=1024
the transfer will fail, because the encryption and the required function will already be forgotten.
Two solutions:
1. losetup doesn't setup /dev/loop0 for encryption. Only programs like mount, etc which actually keep the device open do that. (Bad idea, this would mean you couldn't do mke2fs /dev/loop0 without modifying mke2fs to setup the password and encryption.)
2. Call loop_release_xfer() in loop_clr_fd, which will be called when the connection to a file is removed.
Patch for this simple change follows. It applies to a 2.1.123 kernel.
I don't know who the maintainer of loop.c is, so I post it here. Please include the patch in the regular kernels, because it's wonderful just to compile cryption modules (without modifying your kernel source, except for loop.h) and load them in if you want! (Have look at my home-page http://www.informatik.tu-muenchen.de/~rohloff. blowfish and twofish are available at the moment, plus the patches to loop.h and loop.c)
Patch:
--- loop.c Tue Sep 15 05:06:57 1998 +++ loop.c Thu Oct 1 04:44:38 1998 @@ -430,7 +430,7 @@ } static int loop_clr_fd(struct loop_device *lo, kdev_t dev) -{ +{ int err; struct dentry *dentry = lo->lo_dentry; if (!dentry) @@ -448,7 +448,8 @@ } else { dput(dentry); } - + + err=loop_release_xfer(lo); lo->transfer = NULL; lo->ioctl = NULL; lo->lo_device = 0; @@ -460,7 +461,7 @@ loop_sizes[lo->lo_number] = 0; invalidate_buffers(dev); MOD_DEC_USE_COUNT; - return 0; + return err; } static int loop_set_status(struct loop_device *lo, struct loop_info *arg) @@ -611,8 +612,7 @@ if (lo->lo_refcnt <= 0) printk(KERN_ERR "lo_release: refcount(%d) <= 0\n", lo->lo_refcnt); else { - if (--lo->lo_refcnt == 0) - err = loop_release_xfer(lo); + lo->lo_refcnt--; MOD_DEC_USE_COUNT; } return err; - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |