Skip to content

Commit

Permalink
ceph: avoid panic with mismatched symlink sizes in fill_inode()
Browse files Browse the repository at this point in the history
Return -EINVAL rather than panic if iinfo->symlink_len and inode->i_size
do not match.

Also use kstrndup rather than kmalloc/memcpy.

Signed-off-by: Xi Wang <[email protected]>
Reviewed-by: Alex Elder <[email protected]>
  • Loading branch information
xiw authored and Alex Elder committed Mar 22, 2012
1 parent a661fc5 commit 810339e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions fs/ceph/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,18 +677,19 @@ static int fill_inode(struct inode *inode,
case S_IFLNK:
inode->i_op = &ceph_symlink_iops;
if (!ci->i_symlink) {
int symlen = iinfo->symlink_len;
u32 symlen = iinfo->symlink_len;
char *sym;

BUG_ON(symlen != inode->i_size);
spin_unlock(&ci->i_ceph_lock);

err = -EINVAL;
if (WARN_ON(symlen != inode->i_size))
goto out;

err = -ENOMEM;
sym = kmalloc(symlen+1, GFP_NOFS);
sym = kstrndup(iinfo->symlink, symlen, GFP_NOFS);
if (!sym)
goto out;
memcpy(sym, iinfo->symlink, symlen);
sym[symlen] = 0;

spin_lock(&ci->i_ceph_lock);
if (!ci->i_symlink)
Expand Down

0 comments on commit 810339e

Please sign in to comment.