From: Lee Jones <lee.jones@linaro.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
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 15:07:37 +0000 [thread overview]
Message-ID: <YZ+muS7vC5iNs/kq@google.com> (raw)
In-Reply-To: <20211125145004.GN6514@kadam>
On Thu, 25 Nov 2021, Dan Carpenter wrote:
> 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.
I read the helper to take copies of the original variables.
#define __unsigned_add_overflow(a, b, d) ({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
typeof(d) __d = (d); \
(void) (&__a == &__b); \
(void) (&__a == __d); \
*__d = __a + __b; \
*__d < __a; \
})
Maybe I misread it.
So the original patch [0] was better?
[0] https://lore.kernel.org/stable/20211125120234.67987-1-lee.jones@linaro.org/
--
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-25 15:09 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 [this message]
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=YZ+muS7vC5iNs/kq@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox