diff options
author | kib <kib@FreeBSD.org> | 2017-01-12 01:09:15 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2017-01-12 01:09:15 +0000 |
commit | 76bb2f371469f2763fb84f3bb3dd828f90420d2c (patch) | |
tree | a11407698afefec2bbded7a1e8e1675210b634c2 /sys/compat/linux/linux_stats.c | |
parent | c1d4c0bf60b7b59ca091fe19df87571815ba5485 (diff) | |
download | FreeBSD-src-76bb2f371469f2763fb84f3bb3dd828f90420d2c.zip FreeBSD-src-76bb2f371469f2763fb84f3bb3dd828f90420d2c.tar.gz |
MFC r311452:
Do not allocate struct statfs on kernel stack.
Diffstat (limited to 'sys/compat/linux/linux_stats.c')
-rw-r--r-- | sys/compat/linux/linux_stats.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c index 3638c6b..f74fa803 100644 --- a/sys/compat/linux/linux_stats.c +++ b/sys/compat/linux/linux_stats.c @@ -415,7 +415,7 @@ int linux_statfs(struct thread *td, struct linux_statfs_args *args) { struct l_statfs linux_statfs; - struct statfs bsd_statfs; + struct statfs *bsd_statfs; char *path; int error; @@ -425,12 +425,13 @@ linux_statfs(struct thread *td, struct linux_statfs_args *args) if (ldebug(statfs)) printf(ARGS(statfs, "%s, *"), path); #endif - error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); + bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); + error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs); LFREEPATH(path); - if (error) - return (error); - error = bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); - if (error) + if (error == 0) + error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs); + free(bsd_statfs, M_STATFS); + if (error != 0) return (error); return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); } @@ -456,7 +457,7 @@ int linux_statfs64(struct thread *td, struct linux_statfs64_args *args) { struct l_statfs64 linux_statfs; - struct statfs bsd_statfs; + struct statfs *bsd_statfs; char *path; int error; @@ -469,11 +470,14 @@ linux_statfs64(struct thread *td, struct linux_statfs64_args *args) if (ldebug(statfs64)) printf(ARGS(statfs64, "%s, *"), path); #endif - error = kern_statfs(td, path, UIO_SYSSPACE, &bsd_statfs); + bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); + error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs); LFREEPATH(path); - if (error) + if (error == 0) + bsd_to_linux_statfs64(bsd_statfs, &linux_statfs); + free(bsd_statfs, M_STATFS); + if (error != 0) return (error); - bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs); return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); } @@ -481,7 +485,7 @@ int linux_fstatfs64(struct thread *td, struct linux_fstatfs64_args *args) { struct l_statfs64 linux_statfs; - struct statfs bsd_statfs; + struct statfs *bsd_statfs; int error; #ifdef DEBUG @@ -491,10 +495,13 @@ linux_fstatfs64(struct thread *td, struct linux_fstatfs64_args *args) if (args->bufsize != sizeof(struct l_statfs64)) return (EINVAL); - error = kern_fstatfs(td, args->fd, &bsd_statfs); - if (error) - return error; - bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs); + bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); + error = kern_fstatfs(td, args->fd, bsd_statfs); + if (error == 0) + bsd_to_linux_statfs64(bsd_statfs, &linux_statfs); + free(bsd_statfs, M_STATFS); + if (error != 0) + return (error); return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); } #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ @@ -503,18 +510,19 @@ int linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) { struct l_statfs linux_statfs; - struct statfs bsd_statfs; + struct statfs *bsd_statfs; int error; #ifdef DEBUG if (ldebug(fstatfs)) printf(ARGS(fstatfs, "%d, *"), args->fd); #endif - error = kern_fstatfs(td, args->fd, &bsd_statfs); - if (error) - return (error); - error = bsd_to_linux_statfs(&bsd_statfs, &linux_statfs); - if (error) + bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK); + error = kern_fstatfs(td, args->fd, bsd_statfs); + if (error == 0) + error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs); + free(bsd_statfs, M_STATFS); + if (error != 0) return (error); return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs))); } |