All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Antill <jantill@redhat.com>
To: jbrindle@tresys.com
Cc: selinux@tycho.nsa.gov
Subject: Re: [PATCH 00/33] libsemanage/libsepol object serialization and ps-api
Date: Tue, 24 Apr 2007 19:12:40 -0400	[thread overview]
Message-ID: <1177456360.20127.83.camel@code.and.org> (raw)
In-Reply-To: <20070423213455.741326000@tresys.com>

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

On Mon, 2007-04-23 at 17:34 -0400, jbrindle@tresys.com wrote:
> This is the majority of the patches from the policy server release a few months ago. This implements object serialization to send objects (eg., booleans, file contexts, etc) across the line to the policy server. It also implements the line protocol to connect to the policy server and the backend for libsemanage so that semodule, semanage, etc will talk to a policy server instead of doing local operations.
> 
> The object serialization will also be necessary for the policy representation branch as we will use this infrastructure to serialize the policy tree for module reading and writing.
> 
> The only part left for the policy server is the hooks that were implemented in the expander. As the policy representation work is going on and should remove the expander entirely these patches will have to wait until we have enough of the new representation work to implement them there.
> 
> This is obviously meant only for trunk and the policyrep branch.

 Karl asked me to have a look at this, and I haven't looked at all of
it ... but what I have seen worries me a bit. 

[patch 22/33] 


	status = semanage_unserialize(handle, data, size, (void **)&temp_size,
NULL, SEMANAGE_SERIAL_UINT32_T);

 This has the same problem I told Karl about, (foo **) doesn't convert
to (void **) in std. C.

[patch 24/33]
int read_n(semanage_handle_t *sh, int socket_fd, int timeout, char *buf,
size_t n)
int flush_n(semanage_handle_t *sh, int socket_fd, int timeout, uint64_t
n)

 Test the result of time() directly against (time_t)-1.
 select only easily handles fds upto FD_SETSIZE.
 timeout parameter is "interesting" in that it can take upto (timeout *
2) easily, and even (n*timeout) seconds for the worst case.
 timeout == 0, means you spin on read() with an O_NONBLOCK fd.
 If you get read() == 0, Ie. EOF, you spin until the timeout expires.

int read_msg(semanage_handle_t *sh, int socket_fd, int timeout, uint32_t
* message_type,
	     uint64_t * data_length, char **data)

 Having the parameters be: (len, buf) when read is (buf, len) is a bad
idea, IMO.

int write_msg(semanage_handle_t *sh, int socket_fd, uint32_t
message_type,
	      uint64_t data_length, char *data)

 This doesn't handle EINTR, assumes that writting the msg_header will
happen atomically (and won't get EAGAIN etc.).
 Also the use of O_NONBLOCK and a while loop on write are not a good
combination.
 
int read_server(semanage_handle_t *sh, int socket_fd, uint32_t *
message_type,
		uint64_t * data_length, char **data)

 WTF is the server sending that you can arbitrarily ignore it????


       if (write_msg(handle, fd, PS_PUT_DATABASE, data_length, data))
       if (read_server(handle, fd, &message_type, &data_length, &data))

[patch 25/33]
+static int dbase_ps_flush(semanage_handle_t * handle, dbase_config_t *
dconfig)
{


[...]
       /* Clean up. */
       free(data);

       return STATUS_SUCCESS;

      err:
       ERR(handle, "could not flush database to policy server");
       free(data);
       free(type);
       free(records);
       return STATUS_ERR;
}

 records/type is leaked on the normal path.

static int dbase_ps_cache(semanage_handle_t * handle, dbase_config_t *
dconfig)
{
[...]
	if (semanage_dbase_ps_database_type_serialize(handle,
dbase->database_type, &data, &data_length) != STATUS_SUCCESS)
		goto err;

	if (write_msg(handle, fd, PS_GET_DATABASE, data_length, data))
		goto err;

	data = NULL;
	data_length = 0;

 This leaks data.


int semanage_ps_begintrans(semanage_handle_t * sh)
{
       uint32_t response_type = 0;
       uint64_t response_length = 0;
       char *response = NULL;

       err = write_msg(sh, fd, PS_BEGIN_TRANSACTION, 0, NULL);
       err = read_server(sh, fd, &response_type, &response_length,
&response);
}

/*
[...]
 * The file descriptor will be set to non-blocking mode.
 * Return the file descriptor used, -1 if the server could not be
 * found, -2 if the server rejected this connection, or -3 for all
 * other errors.
 */
int semanage_ps_connect(semanage_handle_t * sh)

 Overloading the fd value in this way is pretty hacky.
 Also is_connected is set to 1 early in this function, and isn't reset
to 0 on failures.





int semanage_ps_disconnect(semanage_handle_t * sh)
{
[...]
       err = close(sh->u.ps_handle.socket_fd);
       sh->u.ps_handle.socket_fd = err;
       return err;
}

 Setting socket_fd to 0, on success, is probably a really bad idea.
 This also doesn't reset is_connected to 0.
 
 
int semanage_ps_list_modules(semanage_handle_t * sh,
                             semanage_module_info_t ** modules, int
*num_mods)

 This uses C99 variable declarations, is that intentional?

 
semanage_ps_begintrans
semanage_ps_install_base_module
semanage_ps_install_module
semanage_ps_remove_module
semanage_ps_upgrade_module
 
 Are all basically the same function. And there are a few more which
also C&P this function with a bit added on the end.


static int connect_remote(semanage_handle_t * sh)
 
 Probably at least need a comment that this is IPv4 only, and uses
gethostbyname().
 The return value from inet_ntop() isn't checked.
 


-- 
James Antill - <james.antill@redhat.com>
setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, ...);
setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, ...);
setsockopt(fd, SOL_SOCKET,  SO_ATTACH_FILTER, ...);


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  parent reply	other threads:[~2007-04-24 23:12 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-23 21:34 [PATCH 00/33] libsemanage/libsepol object serialization and ps-api jbrindle
2007-04-23 21:34 ` [PATCH 01/33] libsepol: basic serilization support jbrindle
2007-04-24 20:00   ` Karl MacMillan
2007-04-24 22:29     ` Joshua Brindle
2007-04-25  4:49       ` Karl MacMillan
2007-04-25 14:14         ` Joshua Brindle
2007-04-25 15:16           ` Karl MacMillan
2007-04-25 15:21             ` Joshua Brindle
2007-04-25 15:40               ` Karl MacMillan
2007-04-25 15:52                 ` Joshua Brindle
2007-04-25 16:00                   ` Karl MacMillan
2007-04-25 16:25                     ` Joshua Brindle
2007-04-25 17:11                       ` James Antill
2007-04-25 18:08                         ` Karl MacMillan
2007-04-23 21:34 ` [PATCH 02/33] libsepol: boolean serialization jbrindle
2007-04-25  4:56   ` Karl MacMillan
2007-04-23 21:34 ` [PATCH 03/33] libsepol: context serialization jbrindle
2007-04-23 21:34 ` [PATCH 04/33] libsepol: interface serialization jbrindle
2007-04-23 21:35 ` [PATCH 05/33] libsepol: node serialization jbrindle
2007-04-23 21:35 ` [PATCH 06/33] libsepol: port serialization jbrindle
2007-04-23 21:35 ` [PATCH 07/33] libsepol: user serialization jbrindle
2007-04-23 21:35 ` [PATCH 08/33] libsemanage: DESTDIR support in INCLUDE and safe test target jbrindle
2007-04-23 21:35 ` [PATCH 09/33] libsemanage: dbase/dconfig cleanup jbrindle
2007-04-23 21:35 ` [PATCH 10/33] libsemanage: database serialization jbrindle
2007-04-23 21:35 ` [PATCH 11/33] libsemanage: endianness macros jbrindle
2007-04-23 21:35 ` [PATCH 12/33] libsemanage: basic serialization jbrindle
2007-04-24 21:16   ` Karl MacMillan
2007-04-24 22:31     ` Joshua Brindle
2007-04-24 22:39       ` Karl MacMillan
2007-04-23 21:35 ` [PATCH 13/33] libsemanage: testing infrastructure jbrindle
2007-04-23 21:35 ` [PATCH 14/33] libsemanage: boolean serialization jbrindle
2007-04-23 21:35 ` [PATCH 15/33] libsemanage: context serialization jbrindle
2007-04-23 21:35 ` [PATCH 16/33] libsemanage: fcontext serialization jbrindle
2007-04-23 21:35 ` [PATCH 17/33] libsemanage: interface serialization jbrindle
2007-04-23 21:35 ` [PATCH 18/33] libsemanage: node serialization jbrindle
2007-04-23 21:35 ` [PATCH 19/33] libsemanage: port serialization jbrindle
2007-04-23 21:35 ` [PATCH 20/33] libsemanage: seuser serialization jbrindle
2007-04-23 21:35 ` [PATCH 21/33] libsemanage: user serialization jbrindle
2007-04-23 21:35 ` [PATCH 22/33] libsemanage: module serialization jbrindle
2007-04-23 21:35 ` [PATCH 23/33] libsemanage: commit number serialization jbrindle
2007-04-23 21:35 ` [PATCH 24/33] libsemanage: networking support jbrindle
2007-04-23 21:35 ` [PATCH 25/33] libsemanage: policy server database hooks jbrindle
2007-04-24 21:39   ` Karl MacMillan
2007-04-24 22:39     ` Joshua Brindle
2007-04-24 23:20       ` Karl MacMillan
2007-04-24 23:57         ` Joshua Brindle
2007-04-25  4:42           ` Karl MacMillan
2007-04-23 21:35 ` [PATCH 26/33] libsemanage: module serialization tests jbrindle
2007-04-23 21:35 ` [PATCH 27/33] libsemanage: booleans " jbrindle
2007-04-23 21:35 ` [PATCH 28/33] libsemanage: fcontexts " jbrindle
2007-04-23 21:35 ` [PATCH 29/33] libsemanage: interface " jbrindle
2007-04-23 21:35 ` [PATCH 30/33] libsemanage: node " jbrindle
2007-04-23 21:35 ` [PATCH 31/33] libsemanage: port " jbrindle
2007-04-23 21:35 ` [PATCH 32/33] libsemanage: seuser " jbrindle
2007-04-23 21:35 ` [PATCH 33/33] libsemanage: user " jbrindle
2007-04-24 19:48 ` [PATCH 00/33] libsemanage/libsepol object serialization and ps-api Joshua Brindle
2007-04-24 23:12 ` James Antill [this message]
2007-04-25  4:46   ` James Antill

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=1177456360.20127.83.camel@code.and.org \
    --to=jantill@redhat.com \
    --cc=jbrindle@tresys.com \
    --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.