From: Joshua Brindle <jbrindle@tresys.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Daniel J Walsh <dwalsh@redhat.com>,
Darrel Goeddel <dgoeddel@TrustedCS.com>,
Karl MacMillan <kmacmillan@mentalrootkit.com>,
SE Linux <selinux@tycho.nsa.gov>
Subject: Re: Latest policycoreutils patch
Date: Wed, 13 Sep 2006 11:14:32 -0400 [thread overview]
Message-ID: <45082058.5040106@tresys.com> (raw)
In-Reply-To: <1157747116.31695.223.camel@moss-spartans.epoch.ncsc.mil>
Stephen Smalley wrote:
> On Fri, 2006-09-08 at 12:37 -0400, Daniel J Walsh wrote:
>> Stephen Smalley wrote:
>>> On Thu, 2006-09-07 at 09:31 -0400, Daniel J Walsh wrote:
>>>
>>>> Have newrole ignore sigpipe so it gives correct error message when
>>>> flooded with 4000 character security context.
>>>>
>>> I'm a little unclear on this one, although I did find a bug report about
>>> it (which would be helpful to identify in the patch posting in the
>>> future when it applies for easy reference), at
>>> https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=203801
>>>
>>> If I read that one correctly, the SIGPIPE is actually happening when
>>> libselinux tries to write the context to the setrans socket, because the
>>> daemon is dropping the connection immediately upon getting the header
>>> with such a large length (more generally, any failure in the daemon
>>> before reading the entire request could lead to this). So that could
>>> affect any user of libselinux, not just newrole, right?
>>>
>>> Looking around a bit, I see that if we changed the use of writev() in
>>> libselinux to instead use sendmsg() with an explicit MSG_NOSIGNAL flag,
>>> we could avoid having such failures generate SIGPIPE altogether. Then
>>> we would just get an error return and have the usual fallback handling.
>>>
>> That sounds like a better solution.
>
> Possible patch below. Changes:
> 1) Collect up the entire request into a single msg and send it once.
> 2) Use sendmsg with MSG_NOSIGNAL rather than writev.
>
> Can anyone explain what data2 is for? It is always NULL at present
> AFAICS.
>
> Index: libselinux/src/setrans_client.c
> ===================================================================
> RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/src/setrans_client.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 setrans_client.c
> --- libselinux/src/setrans_client.c 29 Jun 2006 18:21:05 -0000 1.8
> +++ libselinux/src/setrans_client.c 8 Sep 2006 20:18:07 -0000
> @@ -58,11 +58,12 @@ static int setransd_open(void)
> static int
> send_request(int fd, uint32_t function, const char *data1, const char *data2)
> {
> - struct iovec req_hdr[3];
> + struct msghdr msgh;
> + struct iovec iov[5];
> uint32_t data1_size;
> uint32_t data2_size;
> - struct iovec req_data[2];
> - ssize_t count;
> + ssize_t count, expected;
> + unsigned int i;
>
> if (fd < 0)
> return -1;
> @@ -75,28 +76,27 @@ send_request(int fd, uint32_t function,
> data1_size = strlen(data1) + 1;
> data2_size = strlen(data2) + 1;
>
> - req_hdr[0].iov_base = &function;
> - req_hdr[0].iov_len = sizeof(function);
> - req_hdr[1].iov_base = &data1_size;
> - req_hdr[1].iov_len = sizeof(data1_size);
> - req_hdr[2].iov_base = &data2_size;
> - req_hdr[2].iov_len = sizeof(data2_size);
> -
> - while (((count = writev(fd, req_hdr, 3)) < 0) && (errno == EINTR)) ;
> - if (count != (sizeof(function) + sizeof(data1_size) +
> - sizeof(data2_size))) {
> - return -1;
> - }
> + iov[0].iov_base = &function;
> + iov[0].iov_len = sizeof(function);
> + iov[1].iov_base = &data1_size;
> + iov[1].iov_len = sizeof(data1_size);
> + iov[2].iov_base = &data2_size;
> + iov[2].iov_len = sizeof(data2_size);
> + iov[3].iov_base = (char *)data1;
> + iov[3].iov_len = data1_size;
> + iov[4].iov_base = (char *)data2;
> + iov[4].iov_len = data2_size;
> + memset(&msgh, 0, sizeof(msgh));
> + msgh.msg_iov = iov;
> + msgh.msg_iovlen = sizeof(iov)/sizeof(iov[0]);
> +
> + expected = 0;
> + for (i = 0; i < sizeof(iov)/sizeof(iov[0]); i++)
> + expected += iov[i].iov_len;
>
> - req_data[0].iov_base = (char *)data1;
> - req_data[0].iov_len = data1_size;
> - req_data[1].iov_base = (char *)data2;
> - req_data[1].iov_len = data2_size;
> -
> - while (((count = writev(fd, req_data, 2)) < 0) && (errno == EINTR)) ;
> - if (count < 0 || (uint32_t) count != (data1_size + data2_size)) {
> + while (((count = sendmsg(fd, &msgh, MSG_NOSIGNAL)) < 0) && (errno == EINTR)) ;
> + if (count < 0 || count != expected)
> return -1;
> - }
>
> return 0;
> }
>
>
Thanks, merged.
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
next prev parent reply other threads:[~2006-09-13 15:14 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-07 13:31 Latest policycoreutils patch Daniel J Walsh
2006-09-08 14:00 ` Karl MacMillan
2006-09-08 14:33 ` Joshua Brindle
2006-09-08 14:55 ` Karl MacMillan
2006-09-08 14:35 ` Stephen Smalley
2006-09-08 16:37 ` Daniel J Walsh
2006-09-08 20:25 ` Stephen Smalley
2006-09-11 12:25 ` Joshua Brindle
2006-09-12 12:45 ` Karl MacMillan
2006-09-13 15:14 ` Joshua Brindle [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-11-06 15:25 Daniel J Walsh
2006-01-17 20:34 Daniel J Walsh
2006-01-18 1:36 ` Joshua Brindle
2006-01-18 1:37 ` Joshua Brindle
2006-01-18 3:40 ` Daniel J Walsh
2006-01-18 3:41 ` Joshua Brindle
2006-01-18 3:48 ` Daniel J Walsh
2006-01-18 3:51 ` Joshua Brindle
2006-01-18 7:02 ` Ivan Gyurdiev
2006-01-18 15:44 ` Daniel J Walsh
2006-01-18 18:00 ` Ivan Gyurdiev
2006-01-18 18:12 ` Ivan Gyurdiev
2006-01-18 18:30 ` Stephen Smalley
2006-01-18 18:36 ` Ivan Gyurdiev
2006-01-18 18:52 ` Stephen Smalley
2006-01-18 19:04 ` Ivan Gyurdiev
2006-01-18 19:32 ` Stephen Smalley
2006-01-18 19:07 ` Daniel J Walsh
2006-01-18 19:15 ` Ivan Gyurdiev
2006-01-18 19:19 ` Daniel J Walsh
2006-01-18 19:59 ` Stephen Smalley
2006-01-18 20:01 ` Ivan Gyurdiev
2006-01-19 14:27 ` Daniel J Walsh
2006-01-18 16:13 ` Stephen Smalley
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=45082058.5040106@tresys.com \
--to=jbrindle@tresys.com \
--cc=dgoeddel@TrustedCS.com \
--cc=dwalsh@redhat.com \
--cc=kmacmillan@mentalrootkit.com \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
/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.