public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Tiffany Y. Yang" <ynaffit@google.com>
To: Carlos Llamas <cmllamas@google.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Martijn Coenen" <maco@android.com>,
	"Joel Fernandes" <joel@joelfernandes.org>,
	"Christian Brauner" <brauner@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	linux-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v2] binder: use buffer offsets in debug logs
Date: Tue, 25 Mar 2025 00:41:39 +0000	[thread overview]
Message-ID: <dbx8v7ryym9o.fsf@ynaffit-start.c.googlers.com> (raw)
In-Reply-To: <Z-Go6qOLxT0ZfxyD@google.com> (Carlos Llamas's message of "Mon, 24 Mar 2025 18:48:10 +0000")

Carlos Llamas <cmllamas@google.com> writes:

> On Mon, Mar 24, 2025 at 06:07:18PM +0000, Tiffany Y. Yang wrote:
>> Identify buffer addresses using vma offsets instead of full user
>> addresses in debug logs.
>> 
>> Signed-off-by: Tiffany Y. Yang <ynaffit@google.com>
>> ---
>>  drivers/android/binder.c | 31 ++++++++++++++++---------------
>>  1 file changed, 16 insertions(+), 15 deletions(-)
>> 
>> diff --git a/drivers/android/binder.c b/drivers/android/binder.c
>> index d1aa6d24450a..994ae205aa07 100644
>> --- a/drivers/android/binder.c
>> +++ b/drivers/android/binder.c
>> @@ -3261,20 +3261,20 @@ static void binder_transaction(struct binder_proc *proc,
>>  
>>  	if (reply)
>>  		binder_debug(BINDER_DEBUG_TRANSACTION,
>> -			     "%d:%d BC_REPLY %d -> %d:%d, data %016llx-%016llx size %lld-%lld-%lld\n",
>> +			     "%d:%d BC_REPLY %d -> %d:%d, buffer offset %lx-%lx size %lld-%lld-%lld\n",
>>  			     proc->pid, thread->pid, t->debug_id,
>>  			     target_proc->pid, target_thread->pid,
>> -			     (u64)tr->data.ptr.buffer,
>> -			     (u64)tr->data.ptr.offsets,
>> +			     (unsigned long)tr->data.ptr.buffer - proc->alloc.buffer,
>> +			     (unsigned long)tr->data.ptr.offsets - proc->alloc.buffer,
>
> These could be pointers to anywhere in user memory, not necessarily the
> alloc->buffer. So there will be cases where this substraction doesn't
> make sense. However, you are correct that we shouldn't log these addrs
> so maybe just don't? wdyt?
>

Ah, in that case I think it makes sense to remove them here. What
do you think about printing the full buffer and offsets values in cases
where we would print a binder_user_error or binder_transaction_error
instead. Ideally, I would try to limit this to cases when the data or
offsets ptr is invalid / copy would fail. Ostensibly this wouldn't
reveal dangerous information about the user address space because the
print statements would only happen when the data wasn't where it was
supposed to be and it would help with debugging, but I'm not sure if
this line of thought makes sense...

>>  			     (u64)tr->data_size, (u64)tr->offsets_size,
>>  			     (u64)extra_buffers_size);
>>  	else
>>  		binder_debug(BINDER_DEBUG_TRANSACTION,
>> -			     "%d:%d BC_TRANSACTION %d -> %d - node %d, data %016llx-%016llx size %lld-%lld-%lld\n",
>> +			     "%d:%d BC_TRANSACTION %d -> %d - node %d, buffer offset %lx-%lx size %lld-%lld-%lld\n",
>>  			     proc->pid, thread->pid, t->debug_id,
>>  			     target_proc->pid, target_node->debug_id,
>> -			     (u64)tr->data.ptr.buffer,
>> -			     (u64)tr->data.ptr.offsets,
>> +			     (unsigned long)tr->data.ptr.buffer - proc->alloc.buffer,
>> +			     (unsigned long)tr->data.ptr.offsets - proc->alloc.buffer,
> same here.
>
> Regards,

  reply	other threads:[~2025-03-25  0:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24 18:07 [PATCH v2] binder: use buffer offsets in debug logs Tiffany Y. Yang
2025-03-24 18:23 ` Greg Kroah-Hartman
2025-03-24 18:48 ` Carlos Llamas
2025-03-25  0:41   ` Tiffany Y. Yang [this message]
2025-03-25 20:45     ` Carlos Llamas
2025-03-27 21:11       ` Tiffany Y. Yang

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=dbx8v7ryym9o.fsf@ynaffit-start.c.googlers.com \
    --to=ynaffit@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joel@joelfernandes.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maco@android.com \
    --cc=surenb@google.com \
    --cc=tkjos@android.com \
    /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