public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Lee Jones <lee.jones@linaro.org>
Cc: devel@driverdev.osuosl.org, arve@android.com,
	stable@vger.kernel.org, riandrews@android.com,
	labbott@redhat.com, sumit.semwal@linaro.org
Subject: Re: [PATCH 1/1] staging: ion: Prevent incorrect reference counting behavour
Date: Thu, 25 Nov 2021 17:50:04 +0300	[thread overview]
Message-ID: <20211125145004.GN6514@kadam> (raw)
In-Reply-To: <20211125142004.686650-1-lee.jones@linaro.org>

On Thu, Nov 25, 2021 at 02:20:04PM +0000, Lee Jones wrote:
> Supply additional checks in order to prevent unexpected results.
> 
> Fixes: b892bf75b2034 ("ion: Switch ion to use dma-buf")
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
> Should be back-ported from v4.9 and earlier.
> 
>  drivers/staging/android/ion/ion.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
> index 806e9b30b9dc8..402b74f5d7e69 100644
> --- a/drivers/staging/android/ion/ion.c
> +++ b/drivers/staging/android/ion/ion.c
> @@ -29,6 +29,7 @@
>  #include <linux/export.h>
>  #include <linux/mm.h>
>  #include <linux/mm_types.h>
> +#include <linux/overflow.h>
>  #include <linux/rbtree.h>
>  #include <linux/slab.h>
>  #include <linux/seq_file.h>
> @@ -509,6 +510,10 @@ static void *ion_handle_kmap_get(struct ion_handle *handle)
>  	void *vaddr;
>  
>  	if (handle->kmap_cnt) {
> +		if (check_add_overflow(handle->kmap_cnt,
> +				       (unsigned int) 1, &handle->kmap_cnt))
                                                         ^^^^^^^^^^^^^^^^^

> +			return ERR_PTR(-EOVERFLOW);
> +
>  		handle->kmap_cnt++;
                ^^^^^^^^^^^^^^^^^^^
This will not do what you want at all.  It's a double increment on the
success path and it leave handle->kmap_cnt overflowed on failure path.

regards,
dan carpenter


  reply	other threads:[~2021-11-25 14:52 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 [this message]
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
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=20211125145004.GN6514@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=arve@android.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=labbott@redhat.com \
    --cc=lee.jones@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox