From: Matthew Wilcox <willy@infradead.org>
To: Jordan Crouse <jcrouse@codeaurora.org>
Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] idr: Prevent unintended underflow for the idr index
Date: Wed, 18 Sep 2019 04:50:58 -0700 [thread overview]
Message-ID: <20190918115058.GB9880@bombadil.infradead.org> (raw)
In-Reply-To: <1568756922-2829-1-git-send-email-jcrouse@codeaurora.org>
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?
next prev parent reply other threads:[~2019-09-18 11:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-17 21:48 [PATCH] idr: Prevent unintended underflow for the idr index Jordan Crouse
2019-09-18 11:50 ` Matthew Wilcox [this message]
2019-09-18 15:32 ` Jordan Crouse
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=20190918115058.GB9880@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=freedreno@lists.freedesktop.org \
--cc=jcrouse@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 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).