diff options
author | Xi Wang <xi.wang@gmail.com> | 2012-02-03 09:55:36 -0500 |
---|---|---|
committer | Alex Elder <elder@dreamhost.com> | 2012-03-22 11:47:45 -0400 |
commit | 810339ec2fae5cbd0164b8acde7fb65652755864 (patch) | |
tree | 4a7ea72b1af2201d2bc521afc5e34ed6f6a8ca41 /fs/ceph | |
parent | a661fc561190c0ee2d7cfabcfa92204e2b3aa349 (diff) |
ceph: avoid panic with mismatched symlink sizes in fill_inode()
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 <xi.wang@gmail.com>
Reviewed-by: Alex Elder <elder@dreamhost.com>
Diffstat (limited to 'fs/ceph')
-rw-r--r-- | fs/ceph/inode.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 2c489378b4cd..9fff9f3b17e4 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c | |||
@@ -677,18 +677,19 @@ static int fill_inode(struct inode *inode, | |||
677 | case S_IFLNK: | 677 | case S_IFLNK: |
678 | inode->i_op = &ceph_symlink_iops; | 678 | inode->i_op = &ceph_symlink_iops; |
679 | if (!ci->i_symlink) { | 679 | if (!ci->i_symlink) { |
680 | int symlen = iinfo->symlink_len; | 680 | u32 symlen = iinfo->symlink_len; |
681 | char *sym; | 681 | char *sym; |
682 | 682 | ||
683 | BUG_ON(symlen != inode->i_size); | ||
684 | spin_unlock(&ci->i_ceph_lock); | 683 | spin_unlock(&ci->i_ceph_lock); |
685 | 684 | ||
685 | err = -EINVAL; | ||
686 | if (WARN_ON(symlen != inode->i_size)) | ||
687 | goto out; | ||
688 | |||
686 | err = -ENOMEM; | 689 | err = -ENOMEM; |
687 | sym = kmalloc(symlen+1, GFP_NOFS); | 690 | sym = kstrndup(iinfo->symlink, symlen, GFP_NOFS); |
688 | if (!sym) | 691 | if (!sym) |
689 | goto out; | 692 | goto out; |
690 | memcpy(sym, iinfo->symlink, symlen); | ||
691 | sym[symlen] = 0; | ||
692 | 693 | ||
693 | spin_lock(&ci->i_ceph_lock); | 694 | spin_lock(&ci->i_ceph_lock); |
694 | if (!ci->i_symlink) | 695 | if (!ci->i_symlink) |