From: Lee Jones <lee.jones@linaro.org>
To: lee.jones@linaro.org
Cc: stable@vger.kernel.org
Subject: [PATCH v2 4.9 3/3] ion: Do not 'put' ION handle until after its final use
Date: Tue, 25 Jan 2022 14:18:08 +0000 [thread overview]
Message-ID: <20220125141808.1172511-3-lee.jones@linaro.org> (raw)
In-Reply-To: <20220125141808.1172511-1-lee.jones@linaro.org>
pass_to_user() eventually calls kref_put() on an ION handle which is
still live, potentially allowing for it to be legitimately freed by
the client.
Prevent this from happening before its final use in both ION_IOC_ALLOC
and ION_IOC_IMPORT.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
NB: Only v4.9 is affected by these issues due to refactoring.
drivers/staging/android/ion/ion-ioctl.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c
index d47e9b4171e28..a27865b94416b 100644
--- a/drivers/staging/android/ion/ion-ioctl.c
+++ b/drivers/staging/android/ion/ion-ioctl.c
@@ -165,10 +165,9 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
data.allocation.flags, true);
if (IS_ERR(handle))
return PTR_ERR(handle);
- pass_to_user(handle);
data.allocation.handle = handle->id;
-
cleanup_handle = handle;
+ pass_to_user(handle);
break;
}
case ION_IOC_FREE:
@@ -212,11 +211,12 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
} else {
+ data.handle.handle = handle->id;
handle = pass_to_user(handle);
- if (IS_ERR(handle))
+ if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
- else
- data.handle.handle = handle->id;
+ data.handle.handle = 0;
+ }
}
break;
}
--
2.35.0.rc0.227.g00780c9af4-goog
next prev parent reply other threads:[~2022-01-25 14:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-25 14:18 [PATCH v2 4.9 1/3] ion: Fix use after free during ION_IOC_ALLOC Lee Jones
2022-01-25 14:18 ` [PATCH v2 4.9 2/3] ion: Protect kref from userspace manipulation Lee Jones
2022-01-25 14:18 ` Lee Jones [this message]
2022-01-27 15:38 ` [PATCH v2 4.9 1/3] ion: Fix use after free during ION_IOC_ALLOC Greg KH
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=20220125141808.1172511-3-lee.jones@linaro.org \
--to=lee.jones@linaro.org \
--cc=stable@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).