diff options
author | Christoph Hellwig <hch@tuxera.com> | 2010-10-14 09:54:28 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2010-10-14 09:54:28 -0400 |
commit | f6089ff87d309a8ddb7b0d4dd92a570f1b0f689b (patch) | |
tree | 9b2c6b43885899e055e7b64b88e12bf3759e3794 /fs/hfsplus/dir.c | |
parent | 13571a6977f821fab7d9c3cc5f75da52b7732e40 (diff) | |
download | linux-f6089ff87d309a8ddb7b0d4dd92a570f1b0f689b.tar.bz2 |
hfsplus: fix link corruption
HFS implements hardlink by using indirect catalog entries that refer to a hidden
directly. The link target is cached in the dev field in the HFS+ specific
inode, which is also used for the device number for device files, and inside
for passing the nlink value of the indirect node from hfsplus_cat_write_inode
to a helper function. Now if we happen to write out the indirect node while
hfsplus_link is creating the catalog entry we'll get a link pointing to the
linkid of the current nlink value. This can easily be reproduced by a large
enough loop of local git-clone operations.
Stop abusing the dev field in the HFS+ inode for short term storage by
refactoring the way the permission structure in the catalog entry is
set up, and rename the dev field to linkid to avoid any confusion.
While we're at it also prevent creating hard links to special files, as
the HFS+ dev and linkid share the same space in the on-disk structure.
Signed-off-by: Christoph Hellwig <hch@tuxera.com>
Diffstat (limited to 'fs/hfsplus/dir.c')
-rw-r--r-- | fs/hfsplus/dir.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c index 33aab211695a..c05c8776e836 100644 --- a/fs/hfsplus/dir.c +++ b/fs/hfsplus/dir.c @@ -102,7 +102,7 @@ again: if (IS_ERR(inode)) return ERR_CAST(inode); if (S_ISREG(inode->i_mode)) - HFSPLUS_I(inode)->dev = linkid; + HFSPLUS_I(inode)->linkid = linkid; out: d_add(dentry, inode); return NULL; @@ -252,6 +252,8 @@ static int hfsplus_link(struct dentry *src_dentry, struct inode *dst_dir, if (HFSPLUS_IS_RSRC(inode)) return -EPERM; + if (!S_ISREG(inode->i_mode)) + return -EPERM; mutex_lock(&sbi->vh_mutex); if (inode->i_ino == (u32)(unsigned long)src_dentry->d_fsdata) { @@ -268,7 +270,7 @@ static int hfsplus_link(struct dentry *src_dentry, struct inode *dst_dir, if (res != -EEXIST) goto out; } - HFSPLUS_I(inode)->dev = id; + HFSPLUS_I(inode)->linkid = id; cnid = sbi->next_cnid++; src_dentry->d_fsdata = (void *)(unsigned long)cnid; res = hfsplus_create_cat(cnid, src_dir, &src_dentry->d_name, inode); |