From: Greg KH <greg@kroah.com>
To: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Cc: linux-usb@vger.kernel.org, Felipe Balbi <balbi@kernel.org>,
Michal Nazarewicz <mina86@mina86.com>,
kernel@collabora.com, Marek Szyprowski <mszyprow@samsung.com>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: usb: gadget: Don't allocate zero-length buffers
Date: Wed, 20 Mar 2019 15:25:03 +0100 [thread overview]
Message-ID: <20190320142503.GB26251@kroah.com> (raw)
On Wed, Mar 20, 2019 at 01:56:41PM +0100, Andrzej Pietrasiewicz wrote:
> Don't actually allocate anything if userspace enqueues a zero-length
> buffer. Otherwise vmalloc of zero-sized area will be attempted in
> ffs_build_sg_list().
>
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
> drivers/usb/gadget/function/f_fs.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 08357c5dd026..5cecfe3e9395 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -797,6 +797,9 @@ static void *ffs_build_sg_list(struct sg_table *sgt, size_t sz)
> static inline void *ffs_alloc_buffer(struct ffs_io_data *io_data,
> size_t data_len)
> {
> + if (!data_len)
> + return ZERO_SIZE_PTR;
> +
> if (io_data->use_sg)
> return ffs_build_sg_list(&io_data->sgt, data_len);
>
> @@ -805,7 +808,7 @@ static inline void *ffs_alloc_buffer(struct ffs_io_data *io_data,
>
> static inline void ffs_free_buffer(struct ffs_io_data *io_data)
> {
> - if (!io_data->buf)
> + if (ZERO_OR_NULL_PTR(io_data->buf))
> return;
>
> if (io_data->use_sg) {
Are you sure this is ok? zero length packets mean something in the USB
protocol :)
What is the problem of trying to allocate a buffer of 0 bytes?
thanks,
greg k-h
next reply other threads:[~2019-03-20 14:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-20 14:25 Greg KH [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-03-29 19:54 usb: gadget: Don't allocate zero-length buffers Michał Nazarewicz
2019-03-21 7:42 Andrzej Pietrasiewicz
2019-03-20 12:56 Andrzej Pietrasiewicz
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=20190320142503.GB26251@kroah.com \
--to=greg@kroah.com \
--cc=andrzej.p@collabora.com \
--cc=b.zolnierkie@samsung.com \
--cc=balbi@kernel.org \
--cc=kernel@collabora.com \
--cc=linux-usb@vger.kernel.org \
--cc=mina86@mina86.com \
--cc=mszyprow@samsung.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).