Skip to contentSkip to conversation

ceph: avoid panic with mismatched symlink sizes in fill_inode()

PATCH RESEND Superseded Xi Wang 2 participants 5 messages Feb 3, 2012 Ceph client

lore
Share & tools
lore

Xi Wang

author
#0 lore raw

PATCH RESEND 1/1 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.

---
 fs/ceph/inode.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
fs/ceph/inode.c +6 -5
index 2c48937..6c0205d 100644
@@ -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 (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)
Signature · 1 line
1.7.5.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Xi Wang

Return -EINVAL rather than panic if iinfo->symlink_len and inode->i_size do not match.

Also use kstrndup rather than kmalloc/memcpy.

Looks good, though it might good to at least call
WARN_ON(). What do you think?

I will commit this (either with or without the
WARN_ON()).

author
#2 lore raw
Quoted 2 lines · Alex Elder

Looks good, though it might good to at least call
WARN_ON(). What do you think?

Sounds good to me. I will send a v2. Thanks.

- xi

#3 lore raw
Quoted 5 lines · Xi Wang
Quoted 2 lines · Alex Elder

Looks good, though it might good to at least call
WARN_ON(). What do you think?

Sounds good to me. I will send a v2. Thanks.

No need. I can do it for you. -Alex

Quoted 5 lines

- xi
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw

PATCH v2 1/1 ceph: avoid panic with mismatched symlink sizes in fill_inode()

In reply to Xi Wang

Return -EINVAL rather than panic if iinfo->symlink_len and inode->i_size do not match.

Also use kstrndup rather than kmalloc/memcpy.

---
 fs/ceph/inode.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
fs/ceph/inode.c +6 -5
index 2c48937..9fff9f3 100644
@@ -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)
Signature · 1 line
1.7.5.4