All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH 08/11] dbus: Remove memcpy and fix setting of FD_CLOEXEC on FDs
Date: Fri, 29 Apr 2016 11:11:34 -0500	[thread overview]
Message-ID: <572387B6.7090706@gmail.com> (raw)
In-Reply-To: <1461900728-20662-13-git-send-email-andrew.zaborowski@intel.com>

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

Hi Andrew,

On 04/28/2016 10:32 PM, Andrew Zaborowski wrote:
> Make sure the size of the FD buffer passed to recvmsg is properly
> aligned, etc. and remove the memcpy which seems unneeded.  Also it looks
> like the fcntl() calls operated on one dbus socket FD instead of the
> message FDs.
> ---
>   ell/dbus.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/ell/dbus.c b/ell/dbus.c
> index 70da849..fc0f243 100644
> --- a/ell/dbus.c
> +++ b/ell/dbus.c
> @@ -638,7 +638,8 @@ static struct l_dbus_message *classic_recv_message(struct l_dbus *dbus)
>   	ssize_t len;
>   	void *header, *body;
>   	size_t header_size, body_size;
> -	int fds[16];
> +	uint8_t fd_buf[CMSG_SPACE(16 * sizeof(int))];

'man cmsg' recommends doing:
            union {
                /* ancillary data buffer, wrapped in a union in order to 
ensure
                   it is suitably aligned */
                char buf[CMSG_SPACE(sizeof myfds)];
                struct cmsghdr align;
            } u;

And it looks like systemd does the same.  This is probably what we 
should do as well.

> +	int *fds = NULL;
>   	uint32_t num_fds = 0;
>
>   	len = recv(fd, &hdr, DBUS_HEADER_SIZE, MSG_PEEK);
> @@ -659,8 +660,8 @@ static struct l_dbus_message *classic_recv_message(struct l_dbus *dbus)
>   	memset(&msg, 0, sizeof(msg));
>   	msg.msg_iov = iov;
>   	msg.msg_iovlen = 2;
> -	msg.msg_control = &fds;
> -	msg.msg_controllen = CMSG_SPACE(16 * sizeof(int));
> +	msg.msg_control = &fd_buf;
> +	msg.msg_controllen = sizeof(fd_buf);
>
>   	len = recvmsg(fd, &msg, MSG_CMSG_CLOEXEC);
>   	if (len < 0)
> @@ -675,19 +676,18 @@ static struct l_dbus_message *classic_recv_message(struct l_dbus *dbus)
>   			continue;
>
>   		num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
> -
> -		memcpy(fds, CMSG_DATA(cmsg), num_fds * sizeof(int));
> +		fds = (void *) CMSG_DATA(cmsg);
>
>   		/* Set FD_CLOEXEC on all file descriptors */
>   		for (i = 0; i < num_fds; i++) {
>   			long flags;
>
> -			flags = fcntl(fd, F_GETFD, NULL);
> +			flags = fcntl(fds[i], F_GETFD, NULL);
>   			if (flags < 0)
>   				continue;
>
>   			if (!(flags & FD_CLOEXEC))
> -				fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
> +				fcntl(fds[i], F_SETFD, flags | FD_CLOEXEC);
>                   }
>   	}
>
>

Regards,
-Denis

  reply	other threads:[~2016-04-29 16:11 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29  3:31 [PATCH 1/2] dbus: Better search for matching rules in the filter tree Andrew Zaborowski
2016-04-29  3:31 ` [PATCH 2/2] unit: test a filter tree scenario with unordered paths Andrew Zaborowski
2016-05-03 19:09   ` Denis Kenzior
2016-04-29  3:31 ` [PATCH 1/2] dbus: Fix Dbus1 parsing of doubles Andrew Zaborowski
2016-04-29 15:21   ` Denis Kenzior
2016-04-29  3:31 ` [PATCH 2/2] unit: Fix typos that make the assertions always true Andrew Zaborowski
2016-04-29 15:22   ` Denis Kenzior
2016-04-29  3:31 ` [PATCH] dbus: Don't use KDBUS_ATTACH_NAMES for kdbus connection Andrew Zaborowski
2016-04-29 15:23   ` Denis Kenzior
2016-04-29  3:31 ` [PATCH 01/11] dbus: Accept a list of FDs in dbus_message_from_blob Andrew Zaborowski
2016-04-29 15:30   ` Denis Kenzior
2016-04-29  3:31 ` [PATCH 02/11] unit: Update dbus tests to use new dbus_message_from_blob prototype Andrew Zaborowski
2016-04-29 15:30   ` Denis Kenzior
2016-04-29  3:32 ` [PATCH 03/11] dbus: Validate the size of fd list in dbus_message_build Andrew Zaborowski
2016-04-29 15:30   ` Denis Kenzior
2016-04-29  3:32 ` [PATCH 04/11] dbus: Handle the 'y' type in append_arguments Andrew Zaborowski
2016-04-29 15:50   ` Denis Kenzior
2016-04-29 21:43     ` Andrzej Zaborowski
2016-04-29  3:32 ` [PATCH 05/11] dbus: Check the FD array size in l_dbus_message_builder_append_from_iter Andrew Zaborowski
2016-04-29 15:51   ` Denis Kenzior
2016-04-29  3:32 ` [PATCH 06/11] dbus: Add utility to get FD array for a message Andrew Zaborowski
2016-04-29 15:51   ` Denis Kenzior
2016-04-29  3:32 ` [PATCH 07/11] dbus: Attach FDs to Dbus1 messages being sent Andrew Zaborowski
2016-04-29 15:51   ` Denis Kenzior
2016-04-29  3:32 ` [PATCH 08/11] dbus: Remove memcpy and fix setting of FD_CLOEXEC on FDs Andrew Zaborowski
2016-04-29 16:11   ` Denis Kenzior [this message]
2016-04-29 21:46     ` Andrzej Zaborowski
2016-04-29  3:32 ` [PATCH 09/11] dbus: Attach FDs to kdbus messages being sent Andrew Zaborowski
2016-04-29 16:13   ` Denis Kenzior
2016-04-29  3:32 ` [PATCH 10/11] dbus: Handle received KDBUS_ITEM_FDS Andrew Zaborowski
2016-04-29 16:14   ` Denis Kenzior
2016-04-29  3:32 ` [PATCH 11/11] unit: 'h' type parsing and building tests Andrew Zaborowski
2016-04-29 16:16   ` Denis Kenzior
2016-05-03 19:09 ` [PATCH 1/2] dbus: Better search for matching rules in the filter tree 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=572387B6.7090706@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.