From: Andrew Morton <akpm@linux-foundation.org>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: arnd@arndb.de, gregkh@linuxfoundation.org, tglx@linutronix.de,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kmsg: limit message size
Date: Tue, 8 May 2012 15:57:26 -0700 [thread overview]
Message-ID: <20120508155726.d02d6600.akpm@linux-foundation.org> (raw)
In-Reply-To: <1336229772-3488-1-git-send-email-levinsasha928@gmail.com>
On Sat, 5 May 2012 16:56:12 +0200
Sasha Levin <levinsasha928@gmail.com> wrote:
> There are no size checks in kmsg_write(), and we try allocating enough
> memory to store everything userspace gave us, which may be too much for
> kmalloc to allocate.
>
> Furthermore, we can have an integer overflow if len==INT_MAX, in that case
> we'll corrupt kernel memory.
>
> This was tested with several userspace programs that write to kmsg, and haven't
> found a case where the program attempts to write more than PAGE_SIZE.
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
> drivers/char/mem.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
> index d6e9d08..c90964b 100644
> --- a/drivers/char/mem.c
> +++ b/drivers/char/mem.c
> @@ -815,6 +815,9 @@ static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv,
> ssize_t ret = -EFAULT;
> size_t len = iov_length(iv, count);
>
> + if (len > PAGE_SIZE)
> + return -E2BIG;
> +
> line = kmalloc(len + 1, GFP_KERNEL);
> if (line == NULL)
> return -ENOMEM;
Well, this is a write(), and write() is permitted to return
less-than-asked-for. So what we could do here is to write the first N
bytes and then return N to userspace. Well-behaved userspace will
notice this and then do some more writing from offset N.
Could I ask that you try this and test it a bit, see whether there is
any well-behaved userspace out there? Things like cat and echo
_should_ dtrt.
next prev parent reply other threads:[~2012-05-08 22:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-05 14:56 Sasha Levin
2012-05-08 22:57 ` Andrew Morton [this message]
2012-05-10 16:08 ` Sasha Levin
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=20120508155726.d02d6600.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®