public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Jens Axboe <jens.axboe@oracle.com>
Cc: linux-kernel@vger.kernel.org, abhishekrai@google.com,
	Linus Torvalds <torvalds@linux-foundation.org>,
	davem@davemloft.net
Subject: Re: [PATCH] Fix blktrace setup 32-bit ioctl on 64-bit kernels
Date: Wed, 3 Oct 2007 11:34:56 +0200	[thread overview]
Message-ID: <200710031134.56940.arnd@arndb.de> (raw)
In-Reply-To: <20071002092856.GG5236@kernel.dk>

On Tuesday 02 October 2007, Jens Axboe wrote:
> Hi Arnd,
> 
> Updated patch below. I kept the code in compat_ioctl.c, to me it seems
> like the cleanest approach. I need the BLKTRACESETUP32 define both in
> compat_ioctl.c and blktrace.c if I move it, and I need to hard-core the
> struct size or define it in both places. And guard the code in
> blktrace.c with an ifdef for CONFIG_COMPAT. Not pretty, imho.
> 
> I haven't tested this one yet, but at least it compiles and the sizing
> seems right. The u16 padding was an artifact of the
> __attribute__((packed)) so that could be removed.

The sizes are ok now, but I still don't like the idea of adding more
stuff to fs/compat_ioctl.c. I also noticed another problem now, see below.

The preferred way to define compat_ioctl handlers is to use a ->compat_ioctl
file operation so you don't need any code in compat_ioctl.c at all.
You still need the #ifdef in blktrace.c though if you want to building extra
code on the architectures that don't need it.

> +static int blktrace32_setup(int fd, unsigned cmd, unsigned long arg)
> +{
> +	struct blk_user_trace_setup __user *buts = compat_alloc_user_space(sizeof(*buts));
> +	struct blk_user_trace_setup32 __user *buts32 = compat_ptr(arg);
> +	int err;
> +
> +	if (copy_in_user(&buts->name, &buts32->name, 32) ||
> +	    get_user(buts->act_mask, &buts32->act_mask) ||
> +	    get_user(buts->buf_size, &buts32->buf_size) ||
> +	    get_user(buts->buf_nr, &buts32->buf_nr) ||
> +	    get_user(buts->start_lba, &buts32->start_lba) ||
> +	    get_user(buts->end_lba, &buts32->end_lba) ||
> +	    get_user(buts->pid, &buts32->pid))
> +		return -EFAULT;

You are dereferencing 'buts' here, which is a user space pointer. This is
broken and cannot work on architectures that have split kernel/user address
spaces, and a potential security hole on those that don't.
sparse would warn about this kind of bug, but of course one of the problems
with fs/compat_ioctl.c is that it isn't sparse clean in the first place.

> +	err = sys_ioctl(fd, cmd, (unsigned long) buts);
> +	if (err)
> +		return err;
> +
> +	if (copy_to_user(&buts32->name, &buts->name, 32))
> +		return -EFAULT;

Same here, this needs to be copy_in_user.

	Arnd <><

  reply	other threads:[~2007-10-03  9:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-02  7:39 [PATCH] Fix blktrace setup 32-bit ioctl on 64-bit kernels Jens Axboe
2007-10-02  7:52 ` David Miller
2007-10-02  8:15 ` Arnd Bergmann
2007-10-02  8:37   ` Jens Axboe
2007-10-02  9:28     ` Jens Axboe
2007-10-03  9:34       ` Arnd Bergmann [this message]
2007-10-03 15:55       ` Arnd Bergmann
2007-10-03 22:48         ` Arnd Bergmann
2007-10-04 18:16           ` Jens Axboe
2007-10-04 18:44             ` Arnd Bergmann
2007-10-05 10:41               ` Jens Axboe
2007-10-05 12:30                 ` [PATCH] block: move ioctl conversion to compat_blkdev_ioctl Arnd Bergmann
2007-10-05 12:41                   ` Jens Axboe
2007-10-05 12:41                     ` Arnd Bergmann

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=200710031134.56940.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=abhishekrai@google.com \
    --cc=davem@davemloft.net \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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