From: Wei Liu <wei.liu2@citrix.com>
To: Zoltan Kiss <zoltan.kiss@citrix.com>
Cc: SeeChen Ng <seechen81@gmail.com>, Wei Liu <wei.liu2@citrix.com>,
xen-devel@lists.xen.org
Subject: Re: [PATCH net-next v4] xen-netback: Adding debugfs "io_ring_qX" files
Date: Mon, 11 Aug 2014 13:31:29 +0100 [thread overview]
Message-ID: <20140811123129.GD3249@zion.uk.xensource.com> (raw)
In-Reply-To: <53E8B46C.4090809@citrix.com>
On Mon, Aug 11, 2014 at 01:17:48PM +0100, Zoltan Kiss wrote:
> On 11/08/14 11:38, Wei Liu wrote:
> >On Sun, Aug 10, 2014 at 10:57:51PM +0800, SeeChen Ng wrote:
> >>Hi, I'm a noob to linux kernel, I tried to figure out the usage of the function
> >>"simple_write_to_buffer", and I got confused about the code here.
> >>
> >>>+static ssize_t
> >>>+xenvif_write_io_ring(struct file *filp, const char __user *buf, size_t count,
> >>>+ loff_t *ppos)
> >>>+{
> >>>+ struct xenvif_queue *queue =
> >>>+ ((struct seq_file *)filp->private_data)->private;
> >>>+ int len;
> >>>+ char write[sizeof(XENVIF_KICK_STR)];
> >>>+
> >>>+ /* don't allow partial writes and check the length */
> >>>+ if (*ppos != 0)
> >>>+ return 0;
> >>>+ if (count < sizeof(XENVIF_KICK_STR) - 1)
> >>>+ return -ENOSPC;
> >>The statement here is trying to verify the value of "count" is smaller
> >>than the size of array "write", make sure that the array got
> >>enough space for the write operation, right?
> >>
> >
> >Yes I think so.
> >
> >>So, I think the statement should be:
> >>
> >> if (count >= sizeof(XENVIF_KICK_STR))
> >> return -ENOSPC;
> >>
> >
> > * sizeof(XENVIF_KICK_STR) = 5
> > * count is the number of bytes needs to be written, in the case of "kick"
> "count" is the number of bytes in the incoming buffer. We don't necessarily
> need all of them.
>
> > it's 5 because the tailing '\0' is also counted.
> >
> >so the correct fix should be
> >
> > if (count > sizeof(XENVIF_KICK_STR))
> > return -ENOSPC;
> That would fail if e.g. there is a newline character after the 4 letters of
> "kick". I've crafted this check in this way so we don't have to worry what
> is after that 4 character. This check makes sure there is at least 4
> character, and strncmp check exactly those ones. If there is anything after
> that, we don't care about it.
>
I think current code is wrong in two ways.
a) echo "k" > io_ring_q0 -> returns -ENOSPC
when there's still space in the array, -EINVAL is more appropriate
b) echo "kick1234" > io_ring_q0 -> succeeds but "kick1234" is not a
defined command
My preferred option here is to check the lenght of the input for
excactly what you want. If you only support "kick", that means you
*only* allow the input to be "kick", nothing less, nothing more.
In any case -ENOSPC when there is still space is wrong. -EINVAL is more
appropriate.
So another fix will be
if (count is less than expected)
return -EINVAL;
if (count is more than expected)
return -ENOSPC;
Wei.
next prev parent reply other threads:[~2014-08-11 12:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-10 14:57 [PATCH net-next v4] xen-netback: Adding debugfs "io_ring_qX" files SeeChen Ng
2014-08-11 10:38 ` Wei Liu
2014-08-11 10:50 ` David Vrabel
2014-08-11 10:56 ` Wei Liu
2014-08-11 12:17 ` Zoltan Kiss
2014-08-11 12:31 ` Wei Liu [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-07-08 18:49 Zoltan Kiss
2014-07-08 18:59 ` Konrad Rzeszutek Wilk
2014-07-09 3:49 ` David Miller
2014-07-09 3:49 ` David Miller
2014-07-08 18:49 Zoltan Kiss
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=20140811123129.GD3249@zion.uk.xensource.com \
--to=wei.liu2@citrix.com \
--cc=seechen81@gmail.com \
--cc=xen-devel@lists.xen.org \
--cc=zoltan.kiss@citrix.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.