lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20150304202828.GB6915@gmail.com>
Date:	Wed, 4 Mar 2015 21:28:28 +0100
From:	Ingo Molnar <mingo@...nel.org>
To:	"Liang, Kan" <kan.liang@...el.com>
Cc:	"hpa@...or.com" <hpa@...or.com>,
	"ak@...ux.intel.com" <ak@...ux.intel.com>,
	"acme@...hat.com" <acme@...hat.com>,
	"a.p.zijlstra@...llo.nl" <a.p.zijlstra@...llo.nl>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"xiakaixu@...wei.com" <xiakaixu@...wei.com>,
	"tglx@...utronix.de" <tglx@...utronix.de>,
	"linux-tip-commits@...r.kernel.org" 
	<linux-tip-commits@...r.kernel.org>
Subject: Re: [tip:perf/core] Revert "perf: Remove the extra validity check on
 nr_pages"


* Liang, Kan <kan.liang@...el.com> wrote:

> > * Liang, Kan <kan.liang@...el.com> wrote:
> > 
> > > > * tip-bot for Kan Liang <tipbot@...or.com> wrote:
> > > >
> > > > > --- a/kernel/events/core.c
> > > > > +++ b/kernel/events/core.c
> > > > > @@ -4446,7 +4446,7 @@ static int perf_mmap(struct file *file, struct
> > > > vm_area_struct *vma)
> > > > >  	 * If we have rb pages ensure they're a power-of-two number, so
> > > > we
> > > > >  	 * can do bitmasks instead of modulo.
> > > > >  	 */
> > > > > -	if (!is_power_of_2(nr_pages))
> > > > > +	if (nr_pages != 0 && !is_power_of_2(nr_pages))
> > > > >  		return -EINVAL;
> > > >
> > > > Hm, what does is_power_of_2(0) return? It should return 0, 
> > > > because 0 is not a power of 2!
> > > >
> > > > and if it's fixed to return 0, then the check should properly 
> > > > be something like:
> > > >
> > > > 	if (!nr_pages || !is_power_of_2(nr_pages))
> > > >  		return -EINVAL;
> > > >
> > > > or so?
> > >
> > > nr_pages == 0 is valid, we cannot return -EINVAL. Because
> > > 	vma_size = vma->vm_end - vma->vm_start;
> > > 	nr_pages = (vma_size / PAGE_SIZE) - 1;
> > >
> > > So here we only want to check is_power_of_2
> > > when the pages > 1 (or nr_pages > 0).
> > 
> > I don't think you answered my first question, on which my later
> > comments rely:
> > 
> > > > Hm, what does is_power_of_2(0) return? It should return 0, because 0
> > is
> > > > not a power of 2!
> 
> Yes,  is_power_of_2(0) returns 0.

Oh, indeed, and I clearly cannot read code: your original argument and 
the revert is correct, sorry about the confusion!

Thanks,

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ