Skip to content

Commit b41eeef

Browse files
neilbrownLinus Torvalds
authored andcommitted
knfsd: avoid Oops if buggy userspace performs confusing filehandle->dentry mapping
When a lookup request arrives, nfsd uses information provided by userspace (mountd) to find the right filesystem. It then assumes that the same filehandle type as the incoming filehandle can be used to create an outgoing filehandle. However if mountd is buggy, or maybe just being creative, the filesystem may not support that filesystem type, and the kernel could oops, particularly if 'ex_uuid' is NULL but a FSID_UUID* filehandle type is used. So add some proper checking that the fsid version/type from the incoming filehandle is actually supportable, and ignore that information if it isn't supportable. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 072f62e commit b41eeef

1 file changed

Lines changed: 50 additions & 6 deletions

File tree

‎fs/nfsd/nfsfh.c‎

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
323323
*
324324
*/
325325

326-
u8 version = 1;
326+
u8 version;
327327
u8 fsid_type = 0;
328328
struct inode * inode = dentry->d_inode;
329329
struct dentry *parent = dentry->d_parent;
@@ -341,15 +341,59 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
341341
* the reference filehandle (if it is in the same export)
342342
* or the export options.
343343
*/
344+
retry:
345+
version = 1;
344346
if (ref_fh && ref_fh->fh_export == exp) {
345347
version = ref_fh->fh_handle.fh_version;
346-
if (version == 0xca)
348+
fsid_type = ref_fh->fh_handle.fh_fsid_type;
349+
350+
if (ref_fh == fhp)
351+
fh_put(ref_fh);
352+
ref_fh = NULL;
353+
354+
switch (version) {
355+
case 0xca:
347356
fsid_type = FSID_DEV;
348-
else
349-
fsid_type = ref_fh->fh_handle.fh_fsid_type;
350-
/* We know this version/type works for this export
351-
* so there is no need for further checks.
357+
break;
358+
case 1:
359+
break;
360+
default:
361+
goto retry;
362+
}
363+
364+
/* Need to check that this type works for this
365+
* export point. As the fsid -> filesystem mapping
366+
* was guided by user-space, there is no guarantee
367+
* that the filesystem actually supports that fsid
368+
* type. If it doesn't we loop around again without
369+
* ref_fh set.
352370
*/
371+
switch(fsid_type) {
372+
case FSID_DEV:
373+
if (!old_valid_dev(ex_dev))
374+
goto retry;
375+
/* FALL THROUGH */
376+
case FSID_MAJOR_MINOR:
377+
case FSID_ENCODE_DEV:
378+
if (!(exp->ex_dentry->d_inode->i_sb->s_type->fs_flags
379+
& FS_REQUIRES_DEV))
380+
goto retry;
381+
break;
382+
case FSID_NUM:
383+
if (! (exp->ex_flags & NFSEXP_FSID))
384+
goto retry;
385+
break;
386+
case FSID_UUID8:
387+
case FSID_UUID16:
388+
if (!root_export)
389+
goto retry;
390+
/* fall through */
391+
case FSID_UUID4_INUM:
392+
case FSID_UUID16_INUM:
393+
if (exp->ex_uuid == NULL)
394+
goto retry;
395+
break;
396+
}
353397
} else if (exp->ex_uuid) {
354398
if (fhp->fh_maxsize >= 64) {
355399
if (root_export)

0 commit comments

Comments
 (0)