* potential integer overflow in xenbus_file_write()
@ 2012-09-13 16:00 Dan Carpenter
2012-10-15 10:25 ` Ian Campbell
[not found] ` <1350296757.18058.21.camel@zakaz.uk.xensource.com>
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2012-09-13 16:00 UTC (permalink / raw)
To: virtualization
Hi,
I was reading some code and had a question in xenbus_file_write()
drivers/xen/xenbus/xenbus_dev_frontend.c
461 if ((len + u->len) > sizeof(u->u.buffer)) {
^^^^^^^^^^^^
Can this addition overflow? Should the test be something like:
if (len > sizeof(u->u.buffer) || len + u->len > sizeof(u->u.buffer)) {
462 /* On error, dump existing buffer */
463 u->len = 0;
464 rc = -EINVAL;
465 goto out;
466 }
467
468 ret = copy_from_user(u->u.buffer + u->len, ubuf, len);
469
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: potential integer overflow in xenbus_file_write()
2012-09-13 16:00 potential integer overflow in xenbus_file_write() Dan Carpenter
@ 2012-10-15 10:25 ` Ian Campbell
[not found] ` <1350296757.18058.21.camel@zakaz.uk.xensource.com>
1 sibling, 0 replies; 3+ messages in thread
From: Ian Campbell @ 2012-10-15 10:25 UTC (permalink / raw)
To: Dan Carpenter; +Cc: xen-devel, Konrad Rzeszutek Wilk, virtualization
On Thu, 2012-09-13 at 19:00 +0300, Dan Carpenter wrote:
> Hi,
Thanks Dan. I'm not sure anyone from Xen-land really monitors
virtualization@. Adding xen-devel and Konrad.
>
> I was reading some code and had a question in xenbus_file_write()
>
> drivers/xen/xenbus/xenbus_dev_frontend.c
> 461 if ((len + u->len) > sizeof(u->u.buffer)) {
> ^^^^^^^^^^^^
> Can this addition overflow?
len is a size_t and u->len is an unsigned int, so I expect so.
> Should the test be something like:
>
> if (len > sizeof(u->u.buffer) || len + u->len > sizeof(u->u.buffer)) {
I think that would do it.
Ian.
> 462 /* On error, dump existing buffer */
> 463 u->len = 0;
> 464 rc = -EINVAL;
> 465 goto out;
> 466 }
> 467
> 468 ret = copy_from_user(u->u.buffer + u->len, ubuf, len);
> 469
>
> regards,
> dan carpenter
> _______________________________________________
> Virtualization mailing list
> Virtualization@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/virtualization
>
^ permalink raw reply [flat|nested] 3+ messages in thread[parent not found: <1350296757.18058.21.camel@zakaz.uk.xensource.com>]
* Re: [Xen-devel] potential integer overflow in xenbus_file_write()
[not found] ` <1350296757.18058.21.camel@zakaz.uk.xensource.com>
@ 2012-10-16 8:54 ` Jan Beulich
0 siblings, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2012-10-16 8:54 UTC (permalink / raw)
To: Ian Campbell, Dan Carpenter
Cc: xen-devel, Konrad Rzeszutek Wilk, virtualization
>>> On 15.10.12 at 12:25, Ian Campbell <Ian.Campbell@citrix.com> wrote:
> On Thu, 2012-09-13 at 19:00 +0300, Dan Carpenter wrote:
>> Hi,
>
> Thanks Dan. I'm not sure anyone from Xen-land really monitors
> virtualization@. Adding xen-devel and Konrad.
>
>>
>> I was reading some code and had a question in xenbus_file_write()
>>
>> drivers/xen/xenbus/xenbus_dev_frontend.c
>> 461 if ((len + u->len) > sizeof(u->u.buffer)) {
>> ^^^^^^^^^^^^
>> Can this addition overflow?
>
> len is a size_t and u->len is an unsigned int, so I expect so.
>
>> Should the test be something like:
>>
>> if (len > sizeof(u->u.buffer) || len + u->len > sizeof(u->u.buffer)) {
>
> I think that would do it.
Actually, it can remain a single range check:
if (len > sizeof(u->u.buffer) - u->len) {
because the rest of the code guarantees u->len to be less or
equal to sizeof(u->u.buffer) at all times.
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-10-16 8:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-13 16:00 potential integer overflow in xenbus_file_write() Dan Carpenter
2012-10-15 10:25 ` Ian Campbell
[not found] ` <1350296757.18058.21.camel@zakaz.uk.xensource.com>
2012-10-16 8:54 ` [Xen-devel] " Jan Beulich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox