From: Serban Constantinescu <serban.constantinescu@arm.com>
To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
kernel-team@android.com, arve@android.com,
john.stultz@linaro.org, Dave.Butcher@arm.com
Cc: Serban Constantinescu <serban.constantinescu@arm.com>
Subject: [PATCH v4 5/6] staging: android: binder: fix alignment issues
Date: Wed, 22 May 2013 11:13:00 +0100 [thread overview]
Message-ID: <1369217581-16285-6-git-send-email-serban.constantinescu@arm.com> (raw)
In-Reply-To: <1369217581-16285-1-git-send-email-serban.constantinescu@arm.com>
The Android userspace aligns the data written to the binder buffers to
4bytes. Thus for 32bit platforms or 64bit platforms running an 32bit
Android userspace we can have a buffer looking like this:
platform buffer(binder_cmd pointer) size
32/32 32b 32b 8B
64/32 32b 64b 12B
64/64 32b 64b 12B
Thus the kernel needs to check that the buffer size is aligned to 4bytes
not to (void *) that will be 8bytes on 64bit machines.
The patch also fixes the alignment issues for the offsets buffer, where
on 64bit systems, if the data_size is not aligned to 8bytes the offset's
start address will be incorrectly calculated.
The change does not affect existing 32bit ABI.
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
---
drivers/staging/android/binder.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index ca79084..72f5bb9 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -658,8 +658,8 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc,
return NULL;
}
- size = ALIGN(data_size, sizeof(void *)) +
- ALIGN(offsets_size, sizeof(void *));
+ size = ALIGN(data_size, sizeof(u32)) +
+ ALIGN(offsets_size, sizeof(u32));
if (size < data_size || size < offsets_size) {
binder_user_error("%d: got transaction with invalid size %zd-%zd\n",
@@ -807,8 +807,8 @@ static void binder_free_buf(struct binder_proc *proc,
buffer_size = binder_buffer_size(proc, buffer);
- size = ALIGN(buffer->data_size, sizeof(void *)) +
- ALIGN(buffer->offsets_size, sizeof(void *));
+ size = ALIGN(buffer->data_size, sizeof(u32)) +
+ ALIGN(buffer->offsets_size, sizeof(u32));
binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
"%d: binder_free_buf %p size %zd buffer_size %zd\n",
@@ -1238,7 +1238,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
if (buffer->target_node)
binder_dec_node(buffer->target_node, 1, 0);
- offp = (size_t *)(buffer->data + ALIGN(buffer->data_size, sizeof(void *)));
+ offp = (size_t *)(buffer->data + ALIGN(buffer->data_size, sizeof(u32)));
if (failed_at)
off_end = failed_at;
else
@@ -1247,7 +1247,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
struct flat_binder_object *fp;
if (*offp > buffer->data_size - sizeof(*fp) ||
buffer->data_size < sizeof(*fp) ||
- !IS_ALIGNED(*offp, sizeof(void *))) {
+ !IS_ALIGNED(*offp, sizeof(u32))) {
pr_err("transaction release %d bad offset %zd, size %zd\n",
debug_id, *offp, buffer->data_size);
continue;
@@ -1471,7 +1471,7 @@ static void binder_transaction(struct binder_proc *proc,
if (target_node)
binder_inc_node(target_node, 1, 0, NULL);
- offp = (size_t *)(t->buffer->data + ALIGN(tr->data_size, sizeof(void *)));
+ offp = (size_t *)(t->buffer->data + ALIGN(tr->data_size, sizeof(u32)));
if (copy_from_user(t->buffer->data, tr->data.ptr.buffer, tr->data_size)) {
binder_user_error("%d:%d got transaction with invalid data ptr\n",
@@ -1496,7 +1496,7 @@ static void binder_transaction(struct binder_proc *proc,
struct flat_binder_object *fp;
if (*offp > t->buffer->data_size - sizeof(*fp) ||
t->buffer->data_size < sizeof(*fp) ||
- !IS_ALIGNED(*offp, sizeof(void *))) {
+ !IS_ALIGNED(*offp, sizeof(u32))) {
binder_user_error("%d:%d got transaction with invalid offset, %zd\n",
proc->pid, thread->pid, *offp);
return_error = BR_FAILED_REPLY;
@@ -2332,7 +2332,7 @@ retry:
proc->user_buffer_offset;
tr.data.ptr.offsets = tr.data.ptr.buffer +
ALIGN(t->buffer->data_size,
- sizeof(void *));
+ sizeof(u32));
if (put_user(cmd, (uint32_t __user *)ptr))
return -EFAULT;
--
1.7.9.5
next prev parent reply other threads:[~2013-05-22 10:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-22 10:12 [PATCH v4 0/6] Android Binder IPC Fixes Serban Constantinescu
2013-05-22 10:12 ` [PATCH v4 1/6] staging: android: binder: modify struct binder_write_read to use size_t Serban Constantinescu
2013-06-03 21:42 ` Arve Hjønnevåg
2013-05-22 10:12 ` [PATCH v4 2/6] staging: android: binder: fix binder interface for 64bit compat layer Serban Constantinescu
2013-06-03 21:41 ` Arve Hjønnevåg
2013-06-04 8:54 ` Serban Constantinescu
2013-06-04 23:58 ` Arve Hjønnevåg
2013-06-05 8:28 ` Serban Constantinescu
2013-06-18 16:18 ` Serban Constantinescu
2013-05-22 10:12 ` [PATCH v4 3/6] staging: android: binder: fix BINDER_SET_MAX_THREADS declaration Serban Constantinescu
2013-05-31 23:17 ` Arve Hjønnevåg
2013-06-03 15:02 ` Greg KH
2013-06-03 21:44 ` Arve Hjønnevåg
2013-06-03 22:39 ` Greg KH
2013-05-22 10:12 ` [PATCH v4 4/6] staging: android: binder: fix BC_FREE_BUFFER ioctl declaration Serban Constantinescu
2013-05-22 10:13 ` Serban Constantinescu [this message]
2013-05-31 23:18 ` [PATCH v4 5/6] staging: android: binder: fix alignment issues Arve Hjønnevåg
2013-05-22 10:13 ` [PATCH v4 6/6] staging: android: binder: replace types with portable ones Serban Constantinescu
2013-05-31 23:18 ` Arve Hjønnevåg
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=1369217581-16285-6-git-send-email-serban.constantinescu@arm.com \
--to=serban.constantinescu@arm.com \
--cc=Dave.Butcher@arm.com \
--cc=arve@android.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.stultz@linaro.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®