From: Chandan Rajendra <chandan@linux.vnet.ibm.com>
To: linux-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, joe@perches.com, abdhalee@linux.vnet.ibm.com
Subject: Re: [PATCH RESEND] get_fs_type: Validate fs type string argument
Date: Tue, 20 Nov 2018 11:14:04 +0530 [thread overview]
Message-ID: <2024224.sHGP59Fbbc@localhost.localdomain> (raw)
In-Reply-To: <20181120053642.24513-1-chandan@linux.vnet.ibm.com>
On Tuesday, November 20, 2018 11:06:42 AM IST Chandan Rajendra wrote:
> On ppc64le, When a string with PAGE_SIZE - 1 (i.e. 64k-1) length is
> passed as a "filesystem type" argument to the mount(2) syscall,
> copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64le)
> worth of space for holding the string in kernel's address space.
>
> Later, in set_precision() (invoked by get_fs_type() ->
> __request_module() -> vsnprintf()), we end up assigning
> strlen(fs-type-string) i.e. 65535 as the
> value to 'struct printf_spec'->precision member. This field has a width
> of 16 bits and it is a signed data type. Hence an invalid value ends
> up getting assigned. This causes the "WARN_ONCE(spec->precision != prec,
> "precision %d too large", prec)" statement inside set_precision() to be
> executed.
>
> This commit fixes the bug by validating the length of the "filesystem
> type" argument passed to get_fs_type() function.
>
The following is a trivial userspace program to recreate the issue,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#define BUFSIZE 65536
char buf[BUFSIZE];
int main(int argc, char *argv[])
{
int ret;
if (argc != 3) {
fprintf(stderr, "Usage: %s <device> <mount point>.\n", argv[0]);
exit(1);
}
memset(buf, 1, BUFSIZE);
buf[BUFSIZE-1] = '\0';
printf("strlen(buf) = %lu.\n", strlen(buf));
ret = mount(argv[1], argv[2], buf, 0, NULL);
if (ret) {
perror("mount");
exit(0);
}
exit(1);
}
--
chandan
next prev parent reply other threads:[~2018-11-20 16:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-20 5:36 [PATCH RESEND] get_fs_type: Validate fs type string argument Chandan Rajendra
2018-11-20 5:44 ` Chandan Rajendra [this message]
2019-01-21 12:20 ` Miklos Szeredi
2019-01-21 21:25 ` Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2024224.sHGP59Fbbc@localhost.localdomain \
--to=chandan@linux.vnet.ibm.com \
--cc=abdhalee@linux.vnet.ibm.com \
--cc=joe@perches.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.