All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Brindle <method@manicmethod.com>
To: Eric Paris <eparis@redhat.com>
Cc: selinux@tycho.nsa.gov
Subject: Re: Where to specific the handling of unknown kernel classes and perms
Date: Wed, 02 May 2007 20:46:43 -0400	[thread overview]
Message-ID: <463930F3.7020803@manicmethod.com> (raw)
In-Reply-To: <1178141128.3897.33.camel@dhcp59-235.rdu.redhat.com>

Eric Paris wrote:
> I just sent out a kernel patch with the tristate flag to change kernel
> handling of unknown classes and permissions.  The idea is that when the
> policy is created someone can set the flag to any of the three options
> (deny/reject/allow) and the kernel will act accordingly.  My problem is
> I don't understand the userspace tools which create policy.  I patched
> libsepol to support this new flag when it reads or writes a policydb,
> which allows me to edit my policy.21 by hand in hex and then call
> load_policy to test my kernel.  My problem now is that I don't know
> where a user should be specifying how they want the flags to be set.  To
> be perfectly honest after a bit of searching I'm not even sure where
> policy.21 gets created when I build a policy.
>
>   
It should be setable in semanage.conf or by checkpolicy if building a 
monolithic policy.

> So really I'm just looking for a pointer on what now-a-days creates that
> policy.21 which gets loaded on boot up and where in the whole policy
> build process would be the best place to specify how the policy should
> handle unknowns.  I figure somewhere on some command line I need to add
> some --handle-unknown=accept (or other such option) to the build
> process, but I don't even know what program would be the right one to
> process that input.....
>
>   
So... when you add a module to your policy (eg., semodule -i foo.pp) 
libsemanage eventually calls sepol_link_packages and 
sepol_expand_module. sepol_expand_module is where the policy that is 
written to disk and loaded at bootup is created.

If you look semanage_store.c in the semanage_expand_sandbox function 
you'll see:

        int policyvers = sh->conf->policyvers;
        if (sepol_policydb_set_vers(out, policyvers)) {

where out is the new policy being created. It should be pretty simple to 
add a new option to the semanage conf struct and conf parser and add a 
call in this function to set the option.

In checkpolicy.c policy options are set directly (since its statically 
linked against libsepol):

                policydb.policy_type = POLICY_KERN;
                policydb.policyvers = policyvers;

look for those lines and your option should go there.
> -Eric
>
> (patch for libsepol below)
>
> diff -Naupr libsepol-2.0.3/include/sepol/policydb/policydb.h libsepol-2.0.3.handle_unknown/include/sepol/policydb/policydb.h
> --- libsepol-2.0.3/include/sepol/policydb/policydb.h	2007-04-17 08:34:08.000000000 -0400
> +++ libsepol-2.0.3.handle_unknown/include/sepol/policydb/policydb.h	2007-04-27 15:29:30.000000000 -0400
> @@ -469,6 +469,8 @@ typedef struct policydb {
>  	ebitmap_t *attr_type_map;	/* not saved in the binary policy */
>  
>  	unsigned policyvers;
> +
> +	unsigned handle_unknown;
>  } policydb_t;
>  
>  struct sepol_policydb {
> @@ -599,6 +601,15 @@ extern int policydb_write(struct policyd
>  
>  #define POLICYDB_CONFIG_MLS    1
>  
> +/* the config flags related to unknown classes/perms are bits 2 and 3 */
> +#define POLICYDB_CONFIG_UNKNOWN_MASK   6
> +#define POLICYDB_CONFIG_UNKNOWN_SHIFT  1
> +
> +enum policy_with_unknown_perms {
> +	 DENY_UNKNOWN = 0,
> +	 REJECT_UNKNOWN = 1,
> +	 ALLOW_UNKNOWN = 2
> +};
>  #define OBJECT_R "object_r"
>  #define OBJECT_R_VAL 1
>  
> --- libsepol-2.0.3/src/policydb.c	2007-04-17 08:34:08.000000000 -0400
> +++ libsepol-2.0.3.handle_unknown/src/policydb.c	2007-05-02 14:35:13.000000000 -0400
> @@ -3057,6 +3057,9 @@ int policydb_read(policydb_t * p, struct
>  		p->mls = 0;
>  	}
>  
> +	p->handle_unknown = buf[bufindex] & POLICYDB_CONFIG_UNKNOWN_MASK;
> +	p->handle_unknown = p->handle_unknown >>= POLICYDB_CONFIG_UNKNOWN_SHIFT;
> +
>  	bufindex++;
>  
>  	info = policydb_lookup_compat(r_policyvers, policy_type);
> diff -Naupr libsepol-2.0.3/src/write.c libsepol-2.0.3.handle_unknown/src/write.c
> --- libsepol-2.0.3/src/write.c	2007-04-17 08:34:08.000000000 -0400
> +++ libsepol-2.0.3.handle_unknown/src/write.c	2007-04-27 15:41:17.000000000 -0400
> @@ -1533,6 +1533,9 @@ int policydb_write(policydb_t * p, struc
>  	config = 0;
>  	if (p->mls)
>  		config |= POLICYDB_CONFIG_MLS;
> +	i = POLICYDB_CONFIG_UNKNOWN_MASK & (p->handle_unknown << POLICYDB_CONFIG_UNKNOWN_SHIFT);
> +	if (i)
> +		config |= i;
>  
>  	/* Write the magic number and string identifiers. */
>  	items = 0;
>
>
>
>   


--
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.

  reply	other threads:[~2007-05-03  0:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-02 21:25 Where to specific the handling of unknown kernel classes and perms Eric Paris
2007-05-03  0:46 ` Joshua Brindle [this message]
2007-05-03 12:42   ` Karl MacMillan
2007-05-03 12:46   ` Stephen Smalley
2007-05-03 13:20     ` Joshua Brindle
2007-05-03 13:54       ` Stephen Smalley
2007-05-03 15:31         ` Joshua Brindle
2007-05-04 15:37           ` Daniel J Walsh
2007-05-04 16:15             ` Karl MacMillan
2007-05-04 17:19               ` Daniel J Walsh
2007-05-03  2:12 ` Joshua Brindle

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=463930F3.7020803@manicmethod.com \
    --to=method@manicmethod.com \
    --cc=eparis@redhat.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.