All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH 3/5] dbus: Add and validate the UNIX_FDS msg header field
Date: Fri, 29 Apr 2016 20:15:48 -0500	[thread overview]
Message-ID: <57240744.1010904@gmail.com> (raw)
In-Reply-To: <CAOq732+e0Ugrfw5oeYAcXmAPa0FBd5AxFSs93aG1BL5vs2HQyQ@mail.gmail.com>

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

Hi Andrew,

On 04/29/2016 06:52 PM, Andrzej Zaborowski wrote:
> On 30 April 2016 at 01:17, Denis Kenzior <denkenz@gmail.com> wrote:
>> On 04/29/2016 05:44 PM, Andrew Zaborowski wrote:
>>> @@ -764,11 +764,22 @@ struct l_dbus_message *dbus_message_from_blob(const
>>> void *data, size_t size,
>>>                  get_header_field(message, DBUS_MESSAGE_FIELD_SIGNATURE,
>>>                                          'g', &message->signature);
>>>
>>> -       if (num_fds > L_ARRAY_SIZE(message->fds)) {
>>> -               for (i = L_ARRAY_SIZE(message->fds); i < num_fds; i++)
>>> -                       close(fds[i]);
>>> +       if (num_fds) {
>>> +               uint32_t unix_fds;
>>>
>>> -               num_fds = L_ARRAY_SIZE(message->fds);
>>> +               if (!get_header_field(message,
>>> DBUS_MESSAGE_FIELD_UNIX_FDS,
>>> +                                       'u', &unix_fds))
>>> +                       goto free;
>>> +
>>> +               if (num_fds > unix_fds)
>>> +                       num_fds = unix_fds;
>>
>>
>> If num_fds > unix_fds, should all unused fds (e.g. fds[unix_fds ..
>> num_fds-1] be closed just in case as well?
>
> Ok, let's do that.
>
>>
>> Also, what if unix_fds > num_fds?
>
> Well, not sure if there's anything we can do.  As far as I've tried to
> understand the sendmsg/recvmsg semantics the message boundaries are
> not preserved and I understand FDs may also be delivered in a recvmsg
> call different than that in which the message is received when there
> are multiple messages in the queue.  The solution would be to keep
> buffers of header/body data another buffer with FDs received and pair
> them based on the UNIX_FDS headers but perhaps we don't want to
> overcomplicate it.  For simplicity I take the minimum of num_fds,
> unix_fds and L_ARRAY_SIZE(message->fds).
>

Isn't this a transport detail?  This function in particular is taking 
the full dbus-message blob.  Same with dbus_message_build().

We probably do have a separate problem inside classic_recv_message(). 
Since the UNIX socket is a stream, the message boundaries are not 
preserved, as you point out.

One way might be to use MSG_WAITALL flag.  Alternatively, allocate a 
buffer and keep reading into it until enough data is read.

This reminds me, since we utilize MSG_CMSG_CLOEXEC flag in recvmsg.  Do 
we still need a separate loop to set the O_CLOEXEC flag?  I suppose its 
safe to keep it just in case we're running on Linux kernel less than 2.6.23.

Is a similar flag implied over kdbus?

> Best regards
>

Regards,
-Denis

  reply	other threads:[~2016-04-30  1:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29 22:43 [PATCH 1/5] dbus: Handle the 'h' type in append_arguments Andrew Zaborowski
2016-04-29 22:43 ` [PATCH 2/5] dbus: Remove memcpy and fix setting of FD_CLOEXEC on FDs Andrew Zaborowski
2016-04-29 23:20   ` Denis Kenzior
2016-04-29 22:44 ` [PATCH 3/5] dbus: Add and validate the UNIX_FDS msg header field Andrew Zaborowski
2016-04-29 23:17   ` Denis Kenzior
2016-04-29 23:52     ` Andrzej Zaborowski
2016-04-30  1:15       ` Denis Kenzior [this message]
2016-04-30 14:58         ` Andrzej Zaborowski
2016-05-02 15:10           ` Denis Kenzior
2016-05-02 22:25             ` Andrzej Zaborowski
2016-05-03  3:17               ` Denis Kenzior
2016-04-29 22:44 ` [PATCH 4/5] unit: Add UNIX_FDS header fields in FD test messages Andrew Zaborowski
2016-04-29 23:20   ` Denis Kenzior
2016-04-29 22:44 ` [PATCH 5/5] unit: End to end FD passing test Andrew Zaborowski
2016-04-29 23:21   ` Denis Kenzior
2016-04-29 23:20 ` [PATCH 1/5] dbus: Handle the 'h' type in append_arguments 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=57240744.1010904@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.