From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
ian.campbell@citrix.com, ian.jackson@eu.citrix.com,
jbeulich@suse.com, keir@xen.org, tim@xen.org
Cc: xen-devel@lists.xen.org
Subject: Re: [PATCH] sysctl: Don't overwrite array size variable when it is set on error earlier
Date: Wed, 25 Mar 2015 17:12:06 +0000 [thread overview]
Message-ID: <5512EC66.1080009@citrix.com> (raw)
In-Reply-To: <1427303386-3513-1-git-send-email-boris.ostrovsky@oracle.com>
On 25/03/15 17:09, Boris Ostrovsky wrote:
> When querying CPU topology, if caller-provided array size is smaller than
> number of online CPUs then, in addition to returning -ENOBUFS, sysctl is
> expected to provide back this number. However, this value, stored in 'i',
> is overwritten in the subsequent loop's control statement.
>
> Make sure we don't do this by converting the loop to 'while'.
>
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> xen/common/sysctl.c | 6 +++++-
> 1 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c
> index a8c629f..b83d230 100644
> --- a/xen/common/sysctl.c
> +++ b/xen/common/sysctl.c
> @@ -338,8 +338,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
> ret = -ENOBUFS;
> i = num_cpus;
> }
> + else
> + i = 0;
>
> - for ( i = 0; i < num_cpus; i++ )
> + while ( i < num_cpus )
This would be fine to keep as "for ( ; i < num_cpus; i++)", and helps
avoid an issue if someone introduces a continue; in the future.
As for the fix itself, Reviewed-by: Andrew Cooper
<andrew.cooper3@citrix.com>
> {
> xen_sysctl_cputopo_t cputopo;
>
> @@ -363,6 +365,8 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
> ret = -EFAULT;
> break;
> }
> +
> + i++;
> }
> }
> else
next prev parent reply other threads:[~2015-03-25 17:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-25 17:09 [PATCH] sysctl: Don't overwrite array size variable when it is set on error earlier Boris Ostrovsky
2015-03-25 17:12 ` Andrew Cooper [this message]
2015-03-26 8:32 ` Jan Beulich
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=5512EC66.1080009@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--cc=tim@xen.org \
--cc=xen-devel@lists.xen.org \
/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.