All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ceph: avoid panic with mismatched symlink sizes in fill_inode()
@ 2012-02-29  3:59 Alex Elder
  0 siblings, 0 replies; only message in thread
From: Alex Elder @ 2012-02-29  3:59 UTC (permalink / raw)
  To: ceph-devel

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>
---
  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 87fb132..73e0f87 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -678,18 +678,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)
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2012-02-29  3:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-29  3:59 [PATCH] ceph: avoid panic with mismatched symlink sizes in fill_inode() Alex Elder

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.