aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2016-12-05 16:28:28 -0800
committerMister Oyster <oysterized@gmail.com>2017-04-16 15:03:42 +0200
commitcff1a3c2d9b02ed8a1f1630191218b4905a05e65 (patch)
tree36f347e03d577934e6ed9963001824a5429c5357
parentf81ee65aedf25f7279cb1023081823e815a6e708 (diff)
ANDROID: ion: check for kref overflow
Userspace can cause the kref to handles to increment arbitrarily high. Ensure it does not overflow. Signed-off-by: Daniel Rosenberg <drosen@google.com> Bug: 31992382 Test: See bug for poc Change-Id: I6bff1df385742b1d836d43180dc87fadcea80782 Git-repo: https://android.googlesource.com/kernel/msm Git-commit: 0c702db4d90de88df11057bcf0d8fb2dfe741605 Signed-off-by: Dennis Cagle <d-cagle@codeaurora.org> Signed-off-by: c_vkeert <vkeert@codeaurora.org>
-rwxr-xr-xdrivers/staging/android/ion/ion.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index a6a9b6ede..8b6da4807 100755
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -15,6 +15,8 @@
*/
#include <linux/device.h>
+#include <linux/atomic.h>
+#include <linux/err.h>
#include <linux/file.h>
#include <linux/freezer.h>
#include <linux/fs.h>
@@ -448,6 +450,15 @@ static void ion_handle_get(struct ion_handle *handle)
kref_get(&handle->ref);
}
+/* Must hold the client lock */
+static struct ion_handle* ion_handle_get_check_overflow(struct ion_handle *handle)
+{
+ if (atomic_read(&handle->ref.refcount) + 1 == 0)
+ return ERR_PTR(-EOVERFLOW);
+ ion_handle_get(handle);
+ return handle;
+}
+
static int ion_handle_put_nolock(struct ion_handle *handle)
{
return kref_put(&handle->ref, ion_handle_destroy);
@@ -490,9 +501,9 @@ static struct ion_handle *ion_handle_get_by_id_nolock(struct ion_client *client,
handle = idr_find(&client->idr, id);
if (handle)
- ion_handle_get(handle);
+ return ion_handle_get_check_overflow(handle);
- return handle ? handle : ERR_PTR(-EINVAL);
+ return ERR_PTR(-EINVAL);
}
struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
@@ -1394,7 +1405,7 @@ struct ion_handle *__ion_import_dma_buf(struct ion_client *client, int fd, int f
/* if a handle exists for this buffer just take a reference to it */
handle = ion_handle_lookup(client, buffer);
if (!IS_ERR(handle)) {
- ion_handle_get(handle);
+ handle = ion_handle_get_check_overflow(handle);
mutex_unlock(&client->lock);
goto end;
}