From: Lee Jones <lee.jones@linaro.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: devel@driverdev.osuosl.org, riandrews@android.com,
stable@vger.kernel.org, arve@android.com, labbott@redhat.com,
sumit.semwal@linaro.org
Subject: Re: [PATCH 1/1] staging: ion: Prevent incorrect reference counting behavour
Date: Fri, 26 Nov 2021 08:56:27 +0000 [thread overview]
Message-ID: <YaChOzfm2/3gY4o3@google.com> (raw)
In-Reply-To: <20211126071641.GO6514@kadam>
On Fri, 26 Nov 2021, Dan Carpenter wrote:
> On Thu, Nov 25, 2021 at 06:18:22PM +0300, Dan Carpenter wrote:
> > I had thought that ->kmap_cnt was a regular int and not an unsigned
> > int, but I would have to pull a stable tree to see where I misread the
> > code.
>
> I was looking at (struct ion_buffer)->kmap_cnt but this is
> (struct ion_handle)->kmap_cnt. I'm not sure how those are related but
> it makes me nervous that one can go higher than the other. Also both
> probably need overflow protection.
>
> So I guess I would just do something like:
>
> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
> index 806e9b30b9dc8..e8846279b33b5 100644
> --- a/drivers/staging/android/ion/ion.c
> +++ b/drivers/staging/android/ion/ion.c
> @@ -489,6 +489,8 @@ static void *ion_buffer_kmap_get(struct ion_buffer *buffer)
> void *vaddr;
>
> if (buffer->kmap_cnt) {
> + if (buffer->kmap_cnt == INT_MAX)
> + return ERR_PTR(-EOVERFLOW);
> buffer->kmap_cnt++;
> return buffer->vaddr;
> }
> @@ -509,6 +511,8 @@ static void *ion_handle_kmap_get(struct ion_handle *handle)
> void *vaddr;
>
> if (handle->kmap_cnt) {
> + if (handle->kmap_cnt == INT_MAX)
> + return ERR_PTR(-EOVERFLOW);
> handle->kmap_cnt++;
> return buffer->vaddr;
> }
Which is all well and good until somebody changes the type.
--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
next prev parent reply other threads:[~2021-11-26 8:59 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-25 14:20 [PATCH 1/1] staging: ion: Prevent incorrect reference counting behavour Lee Jones
2021-11-25 14:50 ` Dan Carpenter
2021-11-25 15:07 ` Lee Jones
2021-11-25 15:15 ` Lee Jones
2021-11-25 15:18 ` Dan Carpenter
2021-11-25 15:28 ` Lee Jones
2021-11-26 7:16 ` Dan Carpenter
2021-11-26 8:56 ` Lee Jones [this message]
2021-11-26 9:02 ` Dan Carpenter
2021-11-26 9:03 ` Greg KH
2021-11-26 9:12 ` Lee Jones
-- strict thread matches above, loose matches on Subject: below --
2022-04-25 15:51 Lee Jones
2022-04-25 15:59 ` Greg KH
2021-11-25 12:02 Lee Jones
2021-11-25 12:15 ` Greg KH
2021-11-25 12:46 ` Lee Jones
2021-11-25 12:54 ` Greg KH
2021-11-25 13:03 ` Lee Jones
2021-11-25 13:06 ` Greg KH
2021-11-25 13:11 ` Lee Jones
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=YaChOzfm2/3gY4o3@google.com \
--to=lee.jones@linaro.org \
--cc=arve@android.com \
--cc=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=labbott@redhat.com \
--cc=riandrews@android.com \
--cc=stable@vger.kernel.org \
--cc=sumit.semwal@linaro.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.