selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: William Roberts <bill.c.roberts@gmail.com>
To: Gary Tierney <gary.tierney@fastmail.com>
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH 1/2] checkmodule: add support for specifying module policy version
Date: Thu, 18 Apr 2019 08:11:29 -0700	[thread overview]
Message-ID: <CAFftDdrYssqXxp7MA9jn7UeYAAEqEbxSEPFT-Ej6yK7neQDG9Q@mail.gmail.com> (raw)
In-Reply-To: <20190417163731.3434-2-gary.tierney@fastmail.com>

On Wed, Apr 17, 2019 at 9:37 AM Gary Tierney <gary.tierney@fastmail.com> wrote:
>
> Currently checkpolicy can produce binary policies for earlier policy versions
> to provide support for building policies on one machine and loading/analyzing
> them on another machine with an earlier version of the kernel or libsepol,
> respectively. However, checkmodule was lacking this capability.
>
> This commit adds an identical `-c` flag that can be passed to checkmodule that
> will build a modular policy file of the specified version.
>
> Signed-off-by: Gary Tierney <gary.tierney@fastmail.com>
> ---
>  checkpolicy/checkmodule.8 |  5 ++++-
>  checkpolicy/checkmodule.c | 29 +++++++++++++++++++++++++++--
>  2 files changed, 31 insertions(+), 3 deletions(-)
>
> diff --git a/checkpolicy/checkmodule.8 b/checkpolicy/checkmodule.8
> index cf76591c24d0..e55582f30ec0 100644
> --- a/checkpolicy/checkmodule.8
> +++ b/checkpolicy/checkmodule.8
> @@ -38,7 +38,7 @@ Generate a non-base policy module.
>  Enable the MLS/MCS support when checking and compiling the policy module.
>  .TP
>  .B \-V,\-\-version
> - Show policy versions created by this program.  Note that you cannot currently build older versions.
> +Show policy versions created by this program.
>  .TP
>  .B \-o,\-\-output filename
>  Write a binary policy module file to the specified filename.
> @@ -47,6 +47,9 @@ and will not generate a binary module at all.
>  .TP
>  .B \-U,\-\-handle-unknown <action>
>  Specify how the kernel should handle unknown classes or permissions (deny, allow or reject).
> +.TP
> +.B \-c policyvers
> +Specify the policy version, defaults to the latest.
>
>  .SH EXAMPLE
>  .nf
> diff --git a/checkpolicy/checkmodule.c b/checkpolicy/checkmodule.c
> index 8edc1f8c7bbd..3bb9e5a4a6b3 100644
> --- a/checkpolicy/checkmodule.c
> +++ b/checkpolicy/checkmodule.c
> @@ -142,6 +142,8 @@ static __attribute__((__noreturn__)) void usage(const char *progname)
>         printf("  -m         build a policy module instead of a base module\n");
>         printf("  -M         enable MLS policy\n");
>         printf("  -o FILE    write module to FILE (else just check syntax)\n");
> +       printf("  -c VERSION build a policy module targeting a modular policy version (%d-%d)\n",
> +              MOD_POLICYDB_VERSION_MIN, MOD_POLICYDB_VERSION_MAX);
>         exit(1);
>  }
>
> @@ -163,7 +165,7 @@ int main(int argc, char **argv)
>                 {NULL, 0, NULL, 0}
>         };
>
> -       while ((ch = getopt_long(argc, argv, "ho:bVU:mMC", long_options, NULL)) != -1) {
> +       while ((ch = getopt_long(argc, argv, "ho:bVU:mMCc:", long_options, NULL)) != -1) {
>                 switch (ch) {
>                 case 'h':
>                         usage(argv[0]);
> @@ -194,7 +196,6 @@ int main(int argc, char **argv)
>                         usage(argv[0]);
>                 case 'm':
>                         policy_type = POLICY_MOD;
> -                       policyvers = MOD_POLICYDB_VERSION_MAX;
>                         break;
>                 case 'M':
>                         mlspol = 1;
> @@ -202,6 +203,30 @@ int main(int argc, char **argv)
>                 case 'C':
>                         cil = 1;
>                         break;
> +               case 'c': {
> +                       long int n;
> +                       errno = 0;
> +                       n = strtol(optarg, NULL, 10);
> +
> +                       if (errno) {

Get rid of this newline between the strtol() and errno.

> +                               fprintf(stderr,
> +                                       "Invalid policyvers specified: %s\n",
> +                                       optarg);
> +                               usage(argv[0]);
> +                       }
> +
> +                       if (n < MOD_POLICYDB_VERSION_MIN
> +                           || n > MOD_POLICYDB_VERSION_MAX) {
> +                               fprintf(stderr,
> +                                       "policyvers value %ld not in range %d-%d\n",
> +                                       n, MOD_POLICYDB_VERSION_MIN,
> +                                       MOD_POLICYDB_VERSION_MAX);
> +                               usage(argv[0]);
> +                       }
> +
> +                       policyvers = n;
> +                       break;
> +               }
>                 default:
>                         usage(argv[0]);
>                 }
> --
> 2.17.2
>

  reply	other threads:[~2019-04-18 15:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-17 16:37 [PATCH 0/2] checkmodule: allow building modules of a specific version Gary Tierney
2019-04-17 16:37 ` [PATCH 1/2] checkmodule: add support for specifying module policy version Gary Tierney
2019-04-18 15:11   ` William Roberts [this message]
2019-04-17 16:37 ` [PATCH 2/2] dismod: print policy version of loaded modules Gary Tierney
2019-04-18 15:13   ` William Roberts
2019-04-18 13:17 ` [Non-DoD Source] [PATCH 0/2] checkmodule: allow building modules of a specific version jwcart2
2019-04-18 15:18   ` William Roberts
2019-04-18 17:49     ` jwcart2
2019-04-19 17:21       ` jwcart2

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=CAFftDdrYssqXxp7MA9jn7UeYAAEqEbxSEPFT-Ej6yK7neQDG9Q@mail.gmail.com \
    --to=bill.c.roberts@gmail.com \
    --cc=gary.tierney@fastmail.com \
    --cc=selinux@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).