mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][RESEND] mac: validate mac_partition is within sector
Date: Fri, 20 Nov 2015 16:31:39 -0500	[thread overview]
Message-ID: <x49610wcq84.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <20151120011854.GA12836@www.outflux.net> (Kees Cook's message of "Thu, 19 Nov 2015 17:18:54 -0800")

Kees Cook <keescook@chromium.org> writes:

> If md->signature == MAC_DRIVER_MAGIC and md->block_size == 1023, a single
> 512 byte sector would be read (secsize / 512). However the partition
> structure would be located past the end of the buffer (secsize % 512).

Do we even want to support non-power-of-two block sizes?

-Jeff

>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Cc: stable@vger.kernel.org
> ---
> There doesn't seem to be a mac partition maintainer...
> ---
>  block/partitions/mac.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/block/partitions/mac.c b/block/partitions/mac.c
> index c2c48ec64b27..621317ac4d59 100644
> --- a/block/partitions/mac.c
> +++ b/block/partitions/mac.c
> @@ -32,7 +32,7 @@ int mac_partition(struct parsed_partitions *state)
>  	Sector sect;
>  	unsigned char *data;
>  	int slot, blocks_in_map;
> -	unsigned secsize;
> +	unsigned secsize, datasize, partoffset;
>  #ifdef CONFIG_PPC_PMAC
>  	int found_root = 0;
>  	int found_root_goodness = 0;
> @@ -50,10 +50,14 @@ int mac_partition(struct parsed_partitions *state)
>  	}
>  	secsize = be16_to_cpu(md->block_size);
>  	put_dev_sector(sect);
> -	data = read_part_sector(state, secsize/512, &sect);
> +	datasize = round_down(secsize, 512);
> +	data = read_part_sector(state, datasize / 512, &sect);
>  	if (!data)
>  		return -1;
> -	part = (struct mac_partition *) (data + secsize%512);
> +	partoffset = secsize % 512;
> +	if (partoffset + sizeof(*part) > datasize)
> +		return -1;
> +	part = (struct mac_partition *) (data + partoffset);
>  	if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
>  		put_dev_sector(sect);
>  		return 0;		/* not a MacOS disk */
> -- 
> 1.9.1

      reply	other threads:[~2015-11-20 21:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-20  1:18 Kees Cook
2015-11-20 21:31 ` Jeff Moyer [this message]

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=x49610wcq84.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=dan.carpenter@oracle.com \
    --cc=keescook@chromium.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®