From b48d22427791719f0585210adb05f8a33eb55708 Mon Sep 17 00:00:00 2001 From: anholt Date: Wed, 5 Nov 2003 23:52:54 +0000 Subject: [PATCH] Prevent leaking of fsid to non-root users in linux_statfs and linux_fstatfs. Matches native syscalls now. PR: kern/58793 Submitted by: David P. Reese Jr. MFC after: 1 week --- sys/compat/linux/linux_stats.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c index 8d90b1ffb139..ec6e0677047e 100644 --- a/sys/compat/linux/linux_stats.c +++ b/sys/compat/linux/linux_stats.c @@ -268,8 +268,13 @@ linux_statfs(struct thread *td, struct linux_statfs_args *args) linux_statfs.f_bavail = bsd_statfs->f_bavail; linux_statfs.f_ffree = bsd_statfs->f_ffree; linux_statfs.f_files = bsd_statfs->f_files; - linux_statfs.f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; - linux_statfs.f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; + if (suser(td)) { + linux_statfs.f_fsid.val[0] = 0; + linux_statfs.f_fsid.val[1] = 0; + } else { + linux_statfs.f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; + linux_statfs.f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; + } linux_statfs.f_namelen = MAXNAMLEN; return copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); } @@ -312,8 +317,13 @@ linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) linux_statfs.f_bavail = bsd_statfs->f_bavail; linux_statfs.f_ffree = bsd_statfs->f_ffree; linux_statfs.f_files = bsd_statfs->f_files; - linux_statfs.f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; - linux_statfs.f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; + if (suser(td)) { + linux_statfs.f_fsid.val[0] = 0; + linux_statfs.f_fsid.val[1] = 0; + } else { + linux_statfs.f_fsid.val[0] = bsd_statfs->f_fsid.val[0]; + linux_statfs.f_fsid.val[1] = bsd_statfs->f_fsid.val[1]; + } linux_statfs.f_namelen = MAXNAMLEN; error = copyout(&linux_statfs, args->buf, sizeof(linux_statfs)); fdrop(fp, td);