From: Sudeep Dutt <sudeep.dutt@intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Ashutosh Dixit <ashutosh.dixit@intel.com>,
Caz Yokoyama <Caz.Yokoyama@intel.com>,
Dasaratharaman Chandramouli
<dasaratharaman.chandramouli@intel.com>,
Nikhil Rao <nikhil.rao@intel.com>,
Harshavardhan R Kharche <harshavardhan.r.kharche@intel.com>,
Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Sudeep Dutt <sudeep.dutt@intel.com>
Subject: Re: Intel MIC host driver: possible signed underflow (undefined behavior) in userspace API
Date: Fri, 10 Jan 2014 10:22:55 -0800 [thread overview]
Message-ID: <1389378175.83628.14.camel@localhost> (raw)
In-Reply-To: <20140110142116.GB7212@kroah.com>
On Fri, 2014-01-10 at 06:21 -0800, Greg Kroah-Hartman wrote:
> On Fri, Jan 10, 2014 at 05:56:25AM +0000, Mathieu Desnoyers wrote:
> > Hi,
> >
> > Looking at this commit:
> >
> > commit f69bcbf3b4c4b333dcd7a48eaf868bf0c88edab5
> > Author: Ashutosh Dixit <ashutosh.dixit@intel.com>
> > Date: Thu Sep 5 16:42:18 2013 -0700
> >
> > Intel MIC Host Driver Changes for Virtio Devices.
> >
> > Especially at:
> >
> > +struct mic_copy_desc {
> > +#ifdef __KERNEL__
> > + struct iovec __user *iov;
> > +#else
> > + struct iovec *iov;
> > +#endif
> > + int iovcnt;
> > + __u8 vr_idx;
> > + __u8 update_used;
> > + __u32 out_len;
> > +};
> >
> > Seeing iovcnt being declared as a signed integer seems strange. The
> > first question would be: why is it signed rather than unsigned ?
> >
> > Then, looking further into
> >
> > drivers/misc/mic/host/mic_virtio.c:_mic_virtio_copy()
> >
> > We can see that the while() loop iterates until the local variable
> > iovcnt reaches the value 0 (and iovcnt is also a signed integer). If
> > user-space passes e.g. INT_MIN as iovcnt field, this loop then appears
> > to depend on an undefined behavior (signed underflow) to complete.
> > Wouldn't it be better to use an unsigned integers both in the
> > userspace API and for the local variable ?
>
> Better yet, it should be a "__" type variable, as "int" doesn't mean
> much when crossing the user/kernel boundry...
>
We had designed the interface to be similar to readv(..)/writev(..)
which takes an integer iovcnt. However, the suggestion to use __u32
works nicely since it avoids adding the missing integer parameter
validation in the driver. We will post a patch incorporating this
feedback for the next kernel release.
Thanks to Mathieu for reporting this issue.
Sudeep Dutt
next prev parent reply other threads:[~2014-01-10 18:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1151498255.5788.1389332631491.JavaMail.zimbra@efficios.com>
2014-01-10 5:56 ` Intel MIC host driver: possible signed underflow (undefined behavior) in userspace API Mathieu Desnoyers
2014-01-10 14:21 ` Greg Kroah-Hartman
2014-01-10 18:22 ` Sudeep Dutt [this message]
2014-01-10 20:43 ` Greg Kroah-Hartman
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=1389378175.83628.14.camel@localhost \
--to=sudeep.dutt@intel.com \
--cc=Caz.Yokoyama@intel.com \
--cc=ashutosh.dixit@intel.com \
--cc=dasaratharaman.chandramouli@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=harshavardhan.r.kharche@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=nikhil.rao@intel.com \
--cc=peter.p.waskiewicz.jr@intel.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