* [PATCH v2] vfs: fix put_compat_statfs64() does not handle errors
@ 2016-11-15 9:19 Li Wang
2016-11-29 5:55 ` Li Wang
2016-11-29 22:09 ` Andreas Dilger
0 siblings, 2 replies; 3+ messages in thread
From: Li Wang @ 2016-11-15 9:19 UTC (permalink / raw)
To: adilger, viro; +Cc: liwang, linux-fsdevel, linux-kernel
put_compat_statfs64() does NOT return -1 and setting errno to EOVERFLOW
when some variables(like: f_bsize) overflowed in the returned struct.
The reason is that the ubuf->f_blocks is __u64 type, it couldn't be
4bits as the judgement in put_comat_statfs64(). Here correct the
__u32 variables(in struct compat_statfs64) for comparison.
reproducer:
step1. mount hugetlbfs with two different pagesize on ppc64 arch.
$ hugeadm --pool-pages-max 16M:0
$ hugeadm --create-mount
$ mount | grep -i hugetlbfs
none on /var/lib/hugetlbfs/pagesize-16MB type hugetlbfs (rw,relatime,seclabel,pagesize=16777216)
none on /var/lib/hugetlbfs/pagesize-16GB type hugetlbfs (rw,relatime,seclabel,pagesize=17179869184)
step2. compile & run this C program.
$ cat statfs64_test.c
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <sys/syscall.h>
#include <sys/statfs.h>
int main()
{
struct statfs64 sb;
int err;
err = syscall(SYS_statfs64, "/var/lib/hugetlbfs/pagesize-16GB", sizeof(sb), &sb);
if (err)
return -1;
printf("sizeof f_bsize = %d, f_bsize=%ld\n", sizeof(sb.f_bsize), sb.f_bsize);
return 0;
}
$ gcc -m32 statfs64_test.c
$ ./a.out
sizeof f_bsize = 4, f_bsize=0
Signed-off-by: Li Wang <liwang@redhat.com>
---
fs/compat.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/compat.c b/fs/compat.c
index bd064a2..543b48c 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -253,9 +253,9 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
{
- if (sizeof ubuf->f_blocks == 4) {
- if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
- kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
+ if (sizeof(ubuf->f_bsize) == 4) {
+ if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
+ kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
return -EOVERFLOW;
/* f_files and f_ffree may be -1; it's okay
* to stuff that into 32 bits */
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] vfs: fix put_compat_statfs64() does not handle errors
2016-11-15 9:19 [PATCH v2] vfs: fix put_compat_statfs64() does not handle errors Li Wang
@ 2016-11-29 5:55 ` Li Wang
2016-11-29 22:09 ` Andreas Dilger
1 sibling, 0 replies; 3+ messages in thread
From: Li Wang @ 2016-11-29 5:55 UTC (permalink / raw)
To: Li Wang; +Cc: adilger, viro, linux-fsdevel, linux-kernel
sorry, ping for comments~
On 15 November 2016 at 17:19, Li Wang <liwang@redhat.com> wrote:
> put_compat_statfs64() does NOT return -1 and setting errno to EOVERFLOW
> when some variables(like: f_bsize) overflowed in the returned struct.
>
> The reason is that the ubuf->f_blocks is __u64 type, it couldn't be
> 4bits as the judgement in put_comat_statfs64(). Here correct the
> __u32 variables(in struct compat_statfs64) for comparison.
>
> reproducer:
> step1. mount hugetlbfs with two different pagesize on ppc64 arch.
>
> $ hugeadm --pool-pages-max 16M:0
> $ hugeadm --create-mount
> $ mount | grep -i hugetlbfs
> none on /var/lib/hugetlbfs/pagesize-16MB type hugetlbfs (rw,relatime,seclabel,pagesize=16777216)
> none on /var/lib/hugetlbfs/pagesize-16GB type hugetlbfs (rw,relatime,seclabel,pagesize=17179869184)
>
> step2. compile & run this C program.
>
> $ cat statfs64_test.c
>
> #define _LARGEFILE64_SOURCE
> #include <stdio.h>
> #include <sys/syscall.h>
> #include <sys/statfs.h>
>
> int main()
> {
> struct statfs64 sb;
> int err;
>
> err = syscall(SYS_statfs64, "/var/lib/hugetlbfs/pagesize-16GB", sizeof(sb), &sb);
> if (err)
> return -1;
>
> printf("sizeof f_bsize = %d, f_bsize=%ld\n", sizeof(sb.f_bsize), sb.f_bsize);
>
> return 0;
> }
>
> $ gcc -m32 statfs64_test.c
> $ ./a.out
> sizeof f_bsize = 4, f_bsize=0
>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
> fs/compat.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/compat.c b/fs/compat.c
> index bd064a2..543b48c 100644
> --- a/fs/compat.c
> +++ b/fs/compat.c
> @@ -253,9 +253,9 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
>
> static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
> {
> - if (sizeof ubuf->f_blocks == 4) {
> - if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
> - kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
> + if (sizeof(ubuf->f_bsize) == 4) {
> + if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
> + kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
> return -EOVERFLOW;
> /* f_files and f_ffree may be -1; it's okay
> * to stuff that into 32 bits */
> --
> 1.8.3.1
>
--
Regards,
Li Wang
Email: wangli.ahau@gmail.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] vfs: fix put_compat_statfs64() does not handle errors
2016-11-15 9:19 [PATCH v2] vfs: fix put_compat_statfs64() does not handle errors Li Wang
2016-11-29 5:55 ` Li Wang
@ 2016-11-29 22:09 ` Andreas Dilger
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Dilger @ 2016-11-29 22:09 UTC (permalink / raw)
To: Li Wang; +Cc: viro, linux-fsdevel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2382 bytes --]
> On Nov 15, 2016, at 2:19 AM, Li Wang <liwang@redhat.com> wrote:
>
> put_compat_statfs64() does NOT return -1 and setting errno to EOVERFLOW
> when some variables(like: f_bsize) overflowed in the returned struct.
>
> The reason is that the ubuf->f_blocks is __u64 type, it couldn't be
> 4bits as the judgement in put_comat_statfs64(). Here correct the
> __u32 variables(in struct compat_statfs64) for comparison.
>
> reproducer:
> step1. mount hugetlbfs with two different pagesize on ppc64 arch.
>
> $ hugeadm --pool-pages-max 16M:0
> $ hugeadm --create-mount
> $ mount | grep -i hugetlbfs
> none on /var/lib/hugetlbfs/pagesize-16MB type hugetlbfs (rw,relatime,seclabel,pagesize=16777216)
> none on /var/lib/hugetlbfs/pagesize-16GB type hugetlbfs (rw,relatime,seclabel,pagesize=17179869184)
>
> step2. compile & run this C program.
>
> $ cat statfs64_test.c
>
> #define _LARGEFILE64_SOURCE
> #include <stdio.h>
> #include <sys/syscall.h>
> #include <sys/statfs.h>
>
> int main()
> {
> struct statfs64 sb;
> int err;
>
> err = syscall(SYS_statfs64, "/var/lib/hugetlbfs/pagesize-16GB", sizeof(sb), &sb);
> if (err)
> return -1;
>
> printf("sizeof f_bsize = %d, f_bsize=%ld\n", sizeof(sb.f_bsize), sb.f_bsize);
>
> return 0;
> }
>
> $ gcc -m32 statfs64_test.c
> $ ./a.out
> sizeof f_bsize = 4, f_bsize=0
>
> Signed-off-by: Li Wang <liwang@redhat.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> ---
> fs/compat.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/compat.c b/fs/compat.c
> index bd064a2..543b48c 100644
> --- a/fs/compat.c
> +++ b/fs/compat.c
> @@ -253,9 +253,9 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
>
> static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
> {
> - if (sizeof ubuf->f_blocks == 4) {
> - if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
> - kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
> + if (sizeof(ubuf->f_bsize) == 4) {
> + if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
> + kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
> return -EOVERFLOW;
> /* f_files and f_ffree may be -1; it's okay
> * to stuff that into 32 bits */
> --
> 1.8.3.1
>
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-29 22:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-15 9:19 [PATCH v2] vfs: fix put_compat_statfs64() does not handle errors Li Wang
2016-11-29 5:55 ` Li Wang
2016-11-29 22:09 ` Andreas Dilger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).