All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH 04/20] dbus: Fix _dbus_kernel_calculate_bloom for multiple arguments.
Date: Tue, 15 Mar 2016 11:27:04 -0500	[thread overview]
Message-ID: <56E837D8.5040907@gmail.com> (raw)
In-Reply-To: <CAOq732JHOTHzDxX2_Trcae_h5gL=8TQe2C2BRGiCTiC0wpovjw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5817 bytes --]

Hi Andrew,

On 03/14/2016 05:11 PM, Andrzej Zaborowski wrote:
>   Hi Denis,
>
> On 14 March 2016 at 17:49, Denis Kenzior <denkenz@gmail.com> wrote:
>> Hi Andrew,
>>
>> On 03/13/2016 10:41 PM, Andrew Zaborowski wrote:
>>>
>>> It seems that l_dbus_message_iter_get_type can't be used to get the
>>> value of a single argument and be called repeatedly, it might crash if
>>
>>
>> Looking at l_dbus_message_iter_get_type, it just returns
>> iter->sig_start[iter->sig_pos].  Is there something deeper going on here
>> that is not readily apparent?
>
> Sorry, l_dbus_message_iter_get_type is a typo, I wanted to say
> message_iter_next_entry here.  This function calls it with a fixed
> number of parameters and sooner or later it will receive a message
> with more arguments and by my reading will segfault.
>

So l_dbus_message_iter_next_entry is assuming that the programmer knows 
the signature of the next parameter and passes in a variable meant to 
hold that parameter.  If there's a mismatch, then yes, it might crash. 
However, that is why we check the signature ahead of time.

I guess I'm still not quite sure what you're trying to say here :)

>>
>>> the number and types of call arguments don't match the message arguments.
>>> Also try to support the string arguments that come after non-string
>>> arguments in the bloom filter.
>>
>>
>>  From my reading of systemd code, I didn't think this was possible.  But I
>> could be wrong...
>
> I see no problem with the bloom filter containing, say, arg3="hello",
> even though arguments 1 and 2 are integers.  I don't know if systemd
> supports that but if for example a client adds a match with this kind
> of filter, the service must also support that or the signal won't pass
> through the filter.
>

That is the problem with systemd, it does not explicitly document what 
is and what is not supported.  Having glanced at their bloom filter code 
again, I'm pretty sure only string arguments are currently supported and 
non-string arguments in between are not skipped.  This is why our code 
looks the way it does.

Can you also take a look and confirm?  We are stuck supporting only what 
systemd supports.

>>
>>
>>> ---
>>>    ell/dbus-message.c | 38 ++++++++++++++++++++++++++++----------
>>>    1 file changed, 28 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/ell/dbus-message.c b/ell/dbus-message.c
>>> index f223c70..a123a8a 100644
>>> --- a/ell/dbus-message.c
>>> +++ b/ell/dbus-message.c
>>> @@ -1412,9 +1412,12 @@ bool _dbus_kernel_calculate_bloom(struct
>>> l_dbus_message *message,
>>>          const char *signature;
>>>          void *body;
>>>          size_t body_size;
>>> -       struct l_dbus_message_iter iter;
>>> +       struct l_dbus_message_iter iter, tmp;
>>>          uint8_t argn;
>>>          char buf[256];
>>> +       bool (*skip_entry)(struct l_dbus_message_iter *);
>>> +       bool (*get_basic)(struct l_dbus_message_iter *, char, void *);
>>> +       char type;
>>>
>>>          /* The string "interface:" suffixed by the interface name */
>>>          attr = l_dbus_message_get_interface(message);
>>> @@ -1458,17 +1461,32 @@ bool _dbus_kernel_calculate_bloom(struct
>>> l_dbus_message *message,
>>>
>>>          body = _dbus_message_get_body(message, &body_size);
>>>
>>> -       if (_dbus_message_is_gvariant(message))
>>> -               _gvariant_iter_init(&iter, message, signature, NULL,
>>> -                                       body, body_size);
>>> -       else
>>> +       if (_dbus_message_is_gvariant(message)) {
>>> +               if (!_gvariant_iter_init(&iter, message, signature, NULL,
>>> +                                               body, body_size))
>>> +                       return false;
>>> +
>>> +               skip_entry = _gvariant_iter_skip_entry;
>>> +               get_basic = _gvariant_iter_next_entry_basic;
>>> +       } else {
>>>                  _dbus1_iter_init(&iter, message, signature, NULL,
>>> -                               body, body_size);
>>> +                                       body, body_size);
>>> +
>>> +               skip_entry = _dbus1_iter_skip_entry;
>>> +               get_basic = _dbus1_iter_next_entry_basic;
>>> +       }
>>>
>>>          argn = 0;
>>>
>>> -       while (*signature == 's' || *signature == 'o' || *signature ==
>>> 'g') {
>>> -               if (!message_iter_next_entry(&iter, &attr))
>>> +       do {
>>> +               type = l_dbus_message_iter_get_type(&iter);
>>> +               if (!strchr("sog", type))
>>> +                       goto next;
>>> +
>>> +               /* Don't let get_basic move iter->pos without moving
>>> sig_pos */
>>> +               memcpy(&tmp, &iter, sizeof(tmp));
>>> +
>>> +               if (!get_basic(&tmp, type, &attr))
>>>                          return false;
>>
>>
>> Is this to avoid double skipping this entry?  Can we find a less hacky way
>> to do this?  Perhaps peek_basic, or restructure the loop in some way?
>
> The problem is that get_basic moves the data position (iter->pos) but
> doesn't move the iter->sig_pos, as fas as I can see.  Maybe instead we

I'm pretty sure it does.  See bottom of _dbus1_iter_next_entry_basic() 
for example.  However, the signature handling is full of nasty details. 
  See below.

> should just do iter->sig_pos += 1, similarly to what
> message_iter_next_entry_valist does?

It is really bad form to mess with iterator's internal data structures 
outside its core functions.  If you need it to do something specific, 
lets introduce an iterator method specific to your usecase.

Hence my suggestion to restructure the loop or introduce new operations.

Regards,
-Denis

>
> Best regards
>


  reply	other threads:[~2016-03-15 16:27 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14  3:41 [PATCH 01/20] dbus: Add _dbus1_message_iter_skip_entry and gvariant variant Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 02/20] dbus: Add _dbus_message_get_nth_string_argument Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 03/20] dbus: Support 2+ arguments in l_dbus_message_get_error Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 04/20] dbus: Fix _dbus_kernel_calculate_bloom for multiple arguments Andrew Zaborowski
2016-03-14 16:49   ` Denis Kenzior
2016-03-14 22:11     ` Andrzej Zaborowski
2016-03-15 16:27       ` Denis Kenzior [this message]
2016-03-15 22:08         ` Andrzej Zaborowski
2016-03-16  2:06           ` Denis Kenzior
2016-03-14  3:41 ` [PATCH 05/20] dbus: Add message filter logic in dbus-filter.c Andrew Zaborowski
2016-03-14 17:37   ` Denis Kenzior
2016-03-14 22:25     ` Andrzej Zaborowski
2016-03-14  3:41 ` [PATCH 06/20] unit: Add dbus message filter tests Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 07/20] dbus-filter: Name owner change tracking support Andrew Zaborowski
2016-03-14 18:03   ` Denis Kenzior
2016-03-14 22:32     ` Andrzej Zaborowski
2016-03-14  3:41 ` [PATCH 08/20] dbus: Classic dbus filter_ops implementation Andrew Zaborowski
2016-03-14 18:18   ` Denis Kenzior
2016-03-14 22:36     ` Andrzej Zaborowski
2016-03-15 16:32       ` Denis Kenzior
2016-03-14  3:41 ` [PATCH 09/20] dbus: kdbus " Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 10/20] linux: Update kdbus.h to current github version Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 11/20] dbus-kernel: Update with kdbus API changes Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 12/20] dbus: Add message filter public API Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 13/20] unit: Use the message filter API in dbus tests Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 14/20] dbus: Don't send replies to messages with no reply flag Andrew Zaborowski
2016-03-14 17:11   ` Denis Kenzior
2016-03-14 22:15     ` Andrzej Zaborowski
2016-03-15 16:35       ` Denis Kenzior
2016-03-14  3:41 ` [PATCH 15/20] dbus: Rewrite service/disconnect watch APIs on top of filter API Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 16/20] dbus: Remove now unused filter functions Andrew Zaborowski
2016-03-14 19:12   ` Denis Kenzior
2016-03-14  3:41 ` [PATCH 17/20] dbus: kdbus driver->name_acquire implementation Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 18/20] dbus: Classic dbus driver->name_acquire and public API Andrew Zaborowski
2016-03-14 19:18   ` Denis Kenzior
2016-03-14 22:39     ` Andrzej Zaborowski
2016-03-15 16:38       ` Denis Kenzior
2016-03-14  3:41 ` [PATCH 19/20] unit: Use l_dbus_name_acquire to acquire well-known name Andrew Zaborowski
2016-03-14  3:41 ` [PATCH 20/20] examples: " Andrew Zaborowski
2016-03-14 16:50 ` [PATCH 01/20] dbus: Add _dbus1_message_iter_skip_entry and gvariant variant Denis Kenzior

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=56E837D8.5040907@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ell@lists.01.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.