mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Petr Vandrovec" <VANDROVE@vc.cvut.cz>
To: Matt <madmatt@bits.bris.ac.uk>
Cc: linux-kernel@vger.kernel.org
Subject: Re: ioctl arg passing
Date: Mon, 23 Apr 2001 18:29:24 MET-1	[thread overview]
Message-ID: <EE31127966@vcnet.vc.cvut.cz> (raw)

On 23 Apr 01 at 17:06, Matt wrote:
> struct instruction_t {
>     __s16 code;
>     __s16 rxlen;
>     __s16 *rxbuf;
>     __s16 txlen;
>     __s16 *txbuf;
> };

You should reorder fields, starting with largest fields and going down
to smaller ones. That ways you'll not have troubles with alignment when
someone decides to play with alignment rules...

> struct instruction_t local;
> __s16 *temp;
> 
> copy_from_user( &local, ( struct instruction_t * ) arg, sizeof( struct instruction_t ) );
> temp = kmalloc( sizeof( __s16 ) * local.rxlen, GFP_KERNEL );
> copy_from_user( temp, arg, sizeof( __s16 ) * local.rxlen );
> local.rxbuf = temp;
> temp = kmalloc( sizeof( __s16 ) * local.txlen, GFP_KERNEL );
> ...

As you are using signed value for rxlen/txlen, you should check
for value < 0 ... And there is very low chance that kmalloc() for 
anything bigger than 4KB will succeed. You should either use
vmalloc unconditionally, or at least as fallback. And some error
checking (copy_from_user returns 0 if everything went OK) also
makes driver safer.
                                        Best regards,
                                            Petr Vandrovec
                                            vandrove@vc.cvut.cz


             reply	other threads:[~2001-04-23 16:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-23 18:29 Petr Vandrovec [this message]
2001-04-23 16:40 ` Alex Bligh - linux-kernel
  -- strict thread matches above, loose matches on Subject: below --
2001-04-23 16:06 Matt
2001-04-23 17:50 ` Ingo Oeser
2001-04-23 20:14   ` Matt
2001-04-23 20:17   ` rui.sousa
2001-04-23 20:34     ` Matt
2001-04-23 20:37     ` Mathieu Chouquet-Stringer
2001-04-23 19:58 ` Matt
2001-04-23 21:33   ` Ingo Oeser
2001-04-23 22:09 ` Matt
2001-04-23 23:41   ` Jonathan Lundell

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=EE31127966@vcnet.vc.cvut.cz \
    --to=vandrove@vc.cvut.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madmatt@bits.bris.ac.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 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®