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: <20190918153248.GC25762@jcrouse1-lnx.qualcomm.com>
Date:   Wed, 18 Sep 2019 09:32:48 -0600
From:   Jordan Crouse <jcrouse@...eaurora.org>
To:     Matthew Wilcox <willy@...radead.org>
Cc:     freedreno@...ts.freedesktop.org, linux-arm-msm@...r.kernel.org,
        linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] idr: Prevent unintended underflow for the idr index

On Wed, Sep 18, 2019 at 04:50:58AM -0700, Matthew Wilcox wrote:
> On Tue, Sep 17, 2019 at 03:48:42PM -0600, Jordan Crouse wrote:
> > It is possible for unaware callers of several idr functions to accidentally
> > underflow the index by specifying a id that is less than the idr base.
> 
> Hi Jordan.  Thanks for the patch, but this seems like a distinction
> without a difference.
> 
> >  void *idr_remove(struct idr *idr, unsigned long id)
> >  {
> > +	if (id < idr->idr_base)
> > +		return NULL;
> > +
> >  	return radix_tree_delete_item(&idr->idr_rt, id - idr->idr_base, NULL);
> 
> If this underflows, we'll try to delete an index which doesn't exist,
> which will return NULL.
> 
> >  void *idr_find(const struct idr *idr, unsigned long id)
> >  {
> > +	if (id < idr->idr_base)
> > +		return NULL;
> > +
> >  	return radix_tree_lookup(&idr->idr_rt, id - idr->idr_base);
> 
> If this underflows, we'll look up an entry which doesn't exist, which
> will return NULL.
> 
> > @@ -302,6 +308,9 @@ void *idr_replace(struct idr *idr, void *ptr, unsigned long id)
> >  	void __rcu **slot = NULL;
> >  	void *entry;
> >  
> > +	if (id < idr->idr_base)
> > +		return ERR_PTR(-ENOENT);
> > +
> >  	id -= idr->idr_base;
> >  
> >  	entry = __radix_tree_lookup(&idr->idr_rt, id, &node, &slot);
> 
> ... just outside the context is this line:
>         if (!slot || radix_tree_tag_get(&idr->idr_rt, id, IDR_FREE))
>                 return ERR_PTR(-ENOENT);
> 
> Looking up an index which doesn't exist gets you a NULL slot, so you get
> -ENOENT anyway.
> 
> I did think about these possibilities when I was writing the code and
> convinced myself I didn't need them.  If you have an example of a case
> where I got thast wrong, I'd love to see it.
> 
> More generally, the IDR is deprecated; I'm trying to convert users to
> the XArray.  If you're adding a new user, can you use the XArray API
> instead?

Thanks for the explanation. I happened to walk by while code inspecting an
existing out-of-tree user and thought there might be a small hole to fill
but I agree it is unlikely that the underflow is likely to be a valid id.

Jordan
-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ