diff options
author | Hugh Dickins <hughd@google.com> | 2012-10-07 23:32:51 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-10-09 23:33:55 -0400 |
commit | 35c2a7f4908d404c9124c2efc6ada4640ca4d5d5 (patch) | |
tree | 4ef3fa1953b939fb4bfff935b3d351f76d97252b /fs/ceph | |
parent | 8e22cc88d68ca1a46d7d582938f979eb640ed30f (diff) |
tmpfs,ceph,gfs2,isofs,reiserfs,xfs: fix fh_len checking
Fuzzing with trinity oopsed on the 1st instruction of shmem_fh_to_dentry(),
u64 inum = fid->raw[2];
which is unhelpfully reported as at the end of shmem_alloc_inode():
BUG: unable to handle kernel paging request at ffff880061cd3000
IP: [<ffffffff812190d0>] shmem_alloc_inode+0x40/0x40
Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
Call Trace:
[<ffffffff81488649>] ? exportfs_decode_fh+0x79/0x2d0
[<ffffffff812d77c3>] do_handle_open+0x163/0x2c0
[<ffffffff812d792c>] sys_open_by_handle_at+0xc/0x10
[<ffffffff83a5f3f8>] tracesys+0xe1/0xe6
Right, tmpfs is being stupid to access fid->raw[2] before validating that
fh_len includes it: the buffer kmalloc'ed by do_sys_name_to_handle() may
fall at the end of a page, and the next page not be present.
But some other filesystems (ceph, gfs2, isofs, reiserfs, xfs) are being
careless about fh_len too, in fh_to_dentry() and/or fh_to_parent(), and
could oops in the same way: add the missing fh_len checks to those.
Reported-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Sage Weil <sage@inktank.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: stable@vger.kernel.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/ceph')
-rw-r--r-- | fs/ceph/export.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/fs/ceph/export.c b/fs/ceph/export.c index 8e1b60e557b6..02ce90972d81 100644 --- a/fs/ceph/export.c +++ b/fs/ceph/export.c | |||
@@ -99,7 +99,7 @@ static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len, | |||
99 | * FIXME: we should try harder by querying the mds for the ino. | 99 | * FIXME: we should try harder by querying the mds for the ino. |
100 | */ | 100 | */ |
101 | static struct dentry *__fh_to_dentry(struct super_block *sb, | 101 | static struct dentry *__fh_to_dentry(struct super_block *sb, |
102 | struct ceph_nfs_fh *fh) | 102 | struct ceph_nfs_fh *fh, int fh_len) |
103 | { | 103 | { |
104 | struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; | 104 | struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; |
105 | struct inode *inode; | 105 | struct inode *inode; |
@@ -107,6 +107,9 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, | |||
107 | struct ceph_vino vino; | 107 | struct ceph_vino vino; |
108 | int err; | 108 | int err; |
109 | 109 | ||
110 | if (fh_len < sizeof(*fh) / 4) | ||
111 | return ERR_PTR(-ESTALE); | ||
112 | |||
110 | dout("__fh_to_dentry %llx\n", fh->ino); | 113 | dout("__fh_to_dentry %llx\n", fh->ino); |
111 | vino.ino = fh->ino; | 114 | vino.ino = fh->ino; |
112 | vino.snap = CEPH_NOSNAP; | 115 | vino.snap = CEPH_NOSNAP; |
@@ -150,7 +153,7 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, | |||
150 | * convert connectable fh to dentry | 153 | * convert connectable fh to dentry |
151 | */ | 154 | */ |
152 | static struct dentry *__cfh_to_dentry(struct super_block *sb, | 155 | static struct dentry *__cfh_to_dentry(struct super_block *sb, |
153 | struct ceph_nfs_confh *cfh) | 156 | struct ceph_nfs_confh *cfh, int fh_len) |
154 | { | 157 | { |
155 | struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; | 158 | struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; |
156 | struct inode *inode; | 159 | struct inode *inode; |
@@ -158,6 +161,9 @@ static struct dentry *__cfh_to_dentry(struct super_block *sb, | |||
158 | struct ceph_vino vino; | 161 | struct ceph_vino vino; |
159 | int err; | 162 | int err; |
160 | 163 | ||
164 | if (fh_len < sizeof(*cfh) / 4) | ||
165 | return ERR_PTR(-ESTALE); | ||
166 | |||
161 | dout("__cfh_to_dentry %llx (%llx/%x)\n", | 167 | dout("__cfh_to_dentry %llx (%llx/%x)\n", |
162 | cfh->ino, cfh->parent_ino, cfh->parent_name_hash); | 168 | cfh->ino, cfh->parent_ino, cfh->parent_name_hash); |
163 | 169 | ||
@@ -207,9 +213,11 @@ static struct dentry *ceph_fh_to_dentry(struct super_block *sb, struct fid *fid, | |||
207 | int fh_len, int fh_type) | 213 | int fh_len, int fh_type) |
208 | { | 214 | { |
209 | if (fh_type == 1) | 215 | if (fh_type == 1) |
210 | return __fh_to_dentry(sb, (struct ceph_nfs_fh *)fid->raw); | 216 | return __fh_to_dentry(sb, (struct ceph_nfs_fh *)fid->raw, |
217 | fh_len); | ||
211 | else | 218 | else |
212 | return __cfh_to_dentry(sb, (struct ceph_nfs_confh *)fid->raw); | 219 | return __cfh_to_dentry(sb, (struct ceph_nfs_confh *)fid->raw, |
220 | fh_len); | ||
213 | } | 221 | } |
214 | 222 | ||
215 | /* | 223 | /* |
@@ -230,6 +238,8 @@ static struct dentry *ceph_fh_to_parent(struct super_block *sb, | |||
230 | 238 | ||
231 | if (fh_type == 1) | 239 | if (fh_type == 1) |
232 | return ERR_PTR(-ESTALE); | 240 | return ERR_PTR(-ESTALE); |
241 | if (fh_len < sizeof(*cfh) / 4) | ||
242 | return ERR_PTR(-ESTALE); | ||
233 | 243 | ||
234 | pr_debug("fh_to_parent %llx/%d\n", cfh->parent_ino, | 244 | pr_debug("fh_to_parent %llx/%d\n", cfh->parent_ino, |
235 | cfh->parent_name_hash); | 245 | cfh->parent_name_hash); |