mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: Jiri Kosina <jikos@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Andy Whitcroft <robobotbotbot@gmail.com>,
	Brian Belleville <bbellevi@uci.edu>
Subject: Re: [PATCH] floppy: Do not copy a kernel pointer to user memory in FDGETPRM ioctl
Date: Tue, 10 Jul 2018 00:14:46 +0100	[thread overview]
Message-ID: <ef59bbc78d3a71dba51bfea5f452718d3fa0499c.camel@decadent.org.uk> (raw)
In-Reply-To: <20180529132722.GH7445@brain>

[-- Attachment #1: Type: text/plain, Size: 2044 bytes --]

On Tue, 2018-05-29 at 14:27 +0100, Andy Whitcroft wrote:
[...]
> >From ddb8c77229a9507fa5575c910d2847e123a9c94c Mon Sep 17 00:00:00 2001
> From: Andy Whitcroft <apw@canonical.com>
> Date: Tue, 29 May 2018 13:04:15 +0100
> Subject: [PATCH 1/1] floppy: Do not copy a kernel pointer to user memory in
>  FDGETPRM ioctl
> 
> The final field of a floppy_struct is the field "name", which is a pointer
> to a string in kernel memory.  The kernel pointer should not be copied to
> user memory.  The FDGETPRM ioctl copies a floppy_struct to user memory,
> including this "name" field.  This pointer cannot be used by the user
> and it will leak a kernel address to user-space, which will reveal the
> location of kernel code and data and undermine KASLR protection.
> 
> Model this code after the compat ioctl which copies the returned data
> to a previously cleared temporary structure on the stack (excluding the
> name pointer) and copy out to userspace from there.  As we already have
> an inparam union with an appropriate member and that memory is already
> cleared even for read only calls make use of that as a temporary store.
> 
> Based on an initial patch by Brian Belleville.
> 
> CVE-2018-7755
> Signed-off-by: Andy Whitcroft <apw@canonical.com>

Reviewed-and-tested-by: Ben Hutchings <ben@decadent.org.uk>

Ben.

> ---
>  drivers/block/floppy.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> index 8ec7235fc93b..7512f6ff7c43 100644
> --- a/drivers/block/floppy.c
> +++ b/drivers/block/floppy.c
> @@ -3470,6 +3470,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
>  					  (struct floppy_struct **)&outparam);
>  		if (ret)
>  			return ret;
> +		memcpy(&inparam.g, outparam, offsetof(struct floppy_struct, name));
> +		outparam = &inparam.g;
>  		break;
>  	case FDMSGON:
>  		UDP->flags |= FTD_MSG;
-- 
Ben Hutchings
If you seem to know what you are doing, you'll be given more to do.


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2018-07-09 23:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-08  0:02 Brian Belleville
2018-03-22 19:59 ` Brian Belleville
2018-05-29 13:27 ` Andy Whitcroft
2018-07-09 23:14   ` Ben Hutchings [this message]
2018-08-27  7:45   ` Kees Cook
2018-09-20 14:01     ` Joe Lawrence
2018-09-20 15:10       ` Jens Axboe

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=ef59bbc78d3a71dba51bfea5f452718d3fa0499c.camel@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=bbellevi@uci.edu \
    --cc=jikos@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robobotbotbot@gmail.com \
    /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®