[PATCH] mkfs.cramfs: fix potential uid, gid or mode drop.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Arnaud Mouiche <arnaud.mouiche@xxxxxxxxxxx>

find_identical_file() may squash files with identical contents, but
different uid/gid or mode.

here is a test script to show the problem (to run as root):
without this patch, the output is

  -rw-r--r-- 1 root root 4 janv.  1  1970 a
  -rw-r--r-- 1 root root 4 janv.  1  1970 b
  -rw-r--r-- 1 root root 4 janv.  1  1970 c

whereas the expected result should be

  -rw-r--r-- 1 root   root 4 janv.  1  1970 a
  -rw------- 1 root   root 4 janv.  1  1970 b
  -rw-r--r-- 1 daemon root 4 janv.  1  1970 c



#!/bin/sh
mkdir -p /tmp/fs
cd /tmp/fs

echo foo > a
cp a b
cp a c
chmod 600 b
chown 1 c

cd /tmp
mkfs.cramfs -v /tmp/fs /tmp/fs.cramfs

losetup -f /tmp/fs.cramfs
mkdir -p /tmp/fs_mnt

DEVICE=$(sudo losetup -j /tmp/fs.cramfs -o 0 | sed -e 's/:.*//')
mount $DEVICE /tmp/fs_mnt -o ro
ls -l /tmp/fs_mnt

umount $DEVICE
losetup -d $DEVICE


Signed-off-by: Arnaud Mouiche <arnaud.mouiche@xxxxxxxxxxx>
---
 disk-utils/mkfs.cramfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index 6f412d8..b217645 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -242,7 +242,11 @@ static int find_identical_file(struct entry *orig, struct entry *new, loff_t *fs
 		return 1;
 	if (!orig)
 		return 0;
-	if (orig->size == new->size && orig->path) {
+	if (orig->size == new->size &&
+		orig->uid == new->uid &&
+		orig->gid == new->gid &&
+		orig->mode == new->mode &&
+		orig->path) {
 		if (!orig->flags)
 			mdfile(orig);
 		if (!new->flags)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux