linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: greg@kroah.com, kumar.gala@freescale.com,
	linux-kernel@vger.kernel.org, akpm@kernel.org,
	linux-console@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	Timur Tabi <timur@freescale.com>
Subject: Re: [PATCH 7/7] [v2] drivers/misc: introduce Freescale hypervisor management driver
Date: Wed, 1 Jun 2011 15:54:30 -0500	[thread overview]
Message-ID: <20110601155430.4d5aa6de@schlenkerla.am.freescale.net> (raw)
In-Reply-To: <20110601204618.32190be9@lxorguk.ukuu.org.uk>

On Wed, 1 Jun 2011 20:46:18 +0100
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> > +static char *strdup_from_user(const char __user *ustr, size_t max)
> > +{
> > +	size_t len;
> > +	char *str;
> > +
> > +	len = strnlen_user(ustr, max);
> > +	if (len > max)
> > +		return ERR_PTR(-ENAMETOOLONG);

if (len >= max)

> > +	str = kmalloc(len, GFP_KERNEL);
> > +	if (!str)
> > +		return ERR_PTR(-ENOMEM);
> > +
> > +	if (copy_from_user(str, ustr, len))
> > +		return ERR_PTR(-EFAULT);
> > +
> > +	return str;
> > +}

Memory leak on the EFAULT path

If strnlen_user gets an exception, it'll return zero, causing a
zero-length kmalloc.  Will kmalloc(0, ...) return NULL?  If so, a bad
user pointer would result in -ENOMEM rather than -EFAULT.

> > +	default:
> > +		pr_debug("fsl-hv: unknown ioctl %u\n", cmd);
> > +		ret = -ENOIOCTLCMD;
> 
> -ENOTTY
> 
> (-ENOIOCTLCMD is an internal indicator designed so driver layers can say
> 'dunno, try the next layer up')

There's a check for -ENOIOCTLCMD in vfs_ioctl() -- though it generates
-EINVAL rather than -ENOTTY (why?).

Using -ENOIOCTLCMD consistently would make it easier to refactor a
toplevel ioctl handler into a nested one, plus consistency is good in
general.

> > + * We use the same interrupt handler for all doorbells.  Whenever a doorbell
> > + * is rung, and we receive an interrupt, we just put the handle for that
> > + * doorbell (passed to us as *data) into all of the queues.
> 
> I wonder if these should be presented as IRQs or whether that makes no
> sense ?

They are presented as IRQs.  This driver registers the same handler for all
doorbell IRQs, and pipes the notifications up to userspace, but you could
also directly register a kernel handler for an individual doorbell IRQ.

> > +static irqreturn_t fsl_hv_shutdown_isr(int irq, void *data)
> > +{
> > +	schedule_work(&power_off);
> > +
> > +	/* We should never get here */
> 
> Probably worth printing something if you do (panic(...) ?)

I don't think the comment is accurate.  We've just scheduled the workqueue,
not waited for it to complete.

Timur, shouldn't this schedule orderly_poweroff rather than
kernel_power_off?

-Scott

  parent reply	other threads:[~2011-06-01 20:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-01 18:35 [PATCH 7/7] [v2] drivers/misc: introduce Freescale hypervisor management driver Timur Tabi
2011-06-01 19:46 ` Alan Cox
2011-06-01 20:24   ` Timur Tabi
2011-06-01 20:34     ` Alan Cox
2011-06-01 20:54   ` Scott Wood [this message]
2011-06-01 21:45     ` Alan Cox
2011-06-01 21:40 ` Arnd Bergmann
2011-06-01 22:24   ` Scott Wood
2011-06-03 15:28     ` Arnd Bergmann
2011-06-03 16:22       ` Scott Wood
2011-06-06 15:53         ` Arnd Bergmann
2011-06-06 18:15           ` Scott Wood
2011-06-06 19:48             ` Arnd Bergmann
2011-06-02 21:28   ` Timur Tabi
2011-06-03 15:24     ` Arnd Bergmann
2011-06-03 15:28       ` Timur Tabi
2011-06-06 15:42         ` Arnd Bergmann
2011-06-06 15:48           ` Timur Tabi
2011-06-06 16:03             ` Arnd Bergmann
2011-06-06 16:09               ` Timur Tabi
2011-06-06 16:24                 ` Arnd Bergmann
2011-06-06 16:27                   ` Timur Tabi
2011-06-06 21:01                   ` Chris Metcalf
2011-06-06 21:23                     ` Konrad Rzeszutek Wilk
2011-06-06 23:04                       ` Chris Metcalf
2011-06-07  7:08                         ` Arnd Bergmann
2011-06-07 16:49                           ` Chris Metcalf
2011-06-07 19:16                             ` Arnd Bergmann
2011-06-07 19:20                               ` Timur Tabi
2011-06-07 19:34                                 ` Arnd Bergmann
2011-06-03 14:44   ` Timur Tabi
2011-06-03 15:17     ` 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=20110601155430.4d5aa6de@schlenkerla.am.freescale.net \
    --to=scottwood@freescale.com \
    --cc=akpm@kernel.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=kumar.gala@freescale.com \
    --cc=linux-console@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=timur@freescale.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;
as well as URLs for NNTP newsgroup(s).