public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] staging: ion: Prevent incorrect reference counting behavour
@ 2022-04-25 15:51 Lee Jones
  2022-04-25 15:59 ` Greg KH
  0 siblings, 1 reply; 20+ messages in thread
From: Lee Jones @ 2022-04-25 15:51 UTC (permalink / raw)
  To: lee.jones; +Cc: stable, Dan Carpenter

Supply additional check in order to prevent unexpected results.

Fixes: b892bf75b2034 ("ion: Switch ion to use dma-buf")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
This is a forward-port from linux-4.4.y and linux-4.9.y.

It has never been upstream.

Please apply to v4.14 through v5.10.

 drivers/staging/android/ion/ion.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index e1fe03ceb7f13..e6d4a3ee6cda5 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -114,6 +114,9 @@ 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;
 	}
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


^ permalink raw reply related	[flat|nested] 20+ messages in thread
* [PATCH 1/1] staging: ion: Prevent incorrect reference counting behavour
@ 2021-11-25 14:20 Lee Jones
  2021-11-25 14:50 ` Dan Carpenter
  0 siblings, 1 reply; 20+ messages in thread
From: Lee Jones @ 2021-11-25 14:20 UTC (permalink / raw)
  To: lee.jones; +Cc: stable, labbott, sumit.semwal, arve, riandrews, devel

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++;
 		return buffer->vaddr;
 	}
-- 
2.34.0.rc2.393.gf8c9666880-goog


^ permalink raw reply related	[flat|nested] 20+ messages in thread
* [PATCH 1/1] staging: ion: Prevent incorrect reference counting behavour
@ 2021-11-25 12:02 Lee Jones
  2021-11-25 12:15 ` Greg KH
  0 siblings, 1 reply; 20+ messages in thread
From: Lee Jones @ 2021-11-25 12:02 UTC (permalink / raw)
  To: lee.jones; +Cc: stable, labbott, sumit.semwal, arve, riandrews, devel

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>
---
 drivers/staging/android/ion/ion.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 806e9b30b9dc8..30f359faba575 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -509,6 +509,9 @@ static void *ion_handle_kmap_get(struct ion_handle *handle)
 	void *vaddr;
 
 	if (handle->kmap_cnt) {
+		if (handle->kmap_cnt + 1 < handle->kmap_cnt)
+			return ERR_PTR(-EOVERFLOW);
+
 		handle->kmap_cnt++;
 		return buffer->vaddr;
 	}
-- 
2.34.0.rc2.393.gf8c9666880-goog


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-04-25 15:59 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-25 15:51 [PATCH 1/1] staging: ion: Prevent incorrect reference counting behavour Lee Jones
2022-04-25 15:59 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2021-11-25 14:20 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
2021-11-26  9:02           ` Dan Carpenter
2021-11-26  9:03           ` Greg KH
2021-11-26  9:12             ` Lee Jones
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox