Skip to contentSkip to conversation

file(1)

DISCUSSION Russell Coker 3 participants 13 messages Mar 27, 2008 – Apr 2, 2008 SELinux security module

lore
Share & tools
lore
#0 lore raw

# SE Linux policy modules *.pp

0       lelong  0xf97cff8f      SE Linux modular policy
>4      lelong  x       version %d,
>8      lelong  x       %d sections,
Quoted 7 lines
Quoted 7 lines

(12.l) lelong 0xf97cff8d

Quoted 6 lines
(12.l+27) lelong x           mod version %d,
(12.l+31) lelong 0           Not MLS,
(12.l+31) lelong 1           MLS,

(12.l+23) lelong 2

Quoted 1 line

(12.l+47) string >\0 module name %s

(12.l+23) lelong 1 base

The above /etc/magic entry allows file(1) to display some information about policy modules. Below is a sample of the result:

# file qmail.pp  base.pp  /tmp/loadkeys.pp
qmail.pp:         SE Linux modular policy version 1, 2 sections, mod version 
7, Not MLS, module name qmail\005
base.pp:          SE Linux modular policy version 1, 4 sections, mod version 
7, Not MLS, base
/tmp/loadkeys.pp: SE Linux modular policy version 1, 2 sections, mod version 
6, MLS, module name loadkeys\005

Please let me know what you think of this, in terms of text formatting, information displayed, and use of file(1) features.

The \005 after the module name is due to the fact that file(1) seems to support only two types of string, a "C string" (terminated by \0) and a "Pascal string" where a single byte is used to indicate the length. Using a 32bit little-endian word to indicate the length doesn't seem to work with file(1) - but if anyone can figure out a way then please let me know.

It seems to me that it would be a good idea to write /etc/magic entries at the same time as devising file formats. Being able to quickly and easily determine the contents of a file is a really handy feature. Working with the limitations of file(1) to support this to the greatest degree possible would be a good thing. If the module name was limited to 255 characters I doubt that it would ever inconvenience anyone (in the past I've used compilers that support symbol lengths of ~30 characters), but having a better display in file(1) output would often help people. Another option would be to have a word indicating the string length while also having a 0 terminator (wasting the occasional byte isn't really a problem).

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 23 lines · Russell Coker

# SE Linux policy modules *.pp

0       lelong  0xf97cff8f      SE Linux modular policy
>4      lelong  x       version %d,
>8      lelong  x       %d sections,
Quoted 7 lines
Quoted 7 lines

(12.l) lelong 0xf97cff8d

Quoted 6 lines
(12.l+27) lelong x           mod version %d,
(12.l+31) lelong 0           Not MLS,
(12.l+31) lelong 1           MLS,

(12.l+23) lelong 2

Quoted 1 line

(12.l+47) string >\0 module name %s

(12.l+23) lelong 1 base

The above /etc/magic entry allows file(1) to display some information about policy modules. Below is a sample of the result:

# file qmail.pp  base.pp  /tmp/loadkeys.pp
qmail.pp:         SE Linux modular policy version 1, 2 sections, mod version 
7, Not MLS, module name qmail\005
base.pp:          SE Linux modular policy version 1, 4 sections, mod version 
7, Not MLS, base
/tmp/loadkeys.pp: SE Linux modular policy version 1, 2 sections, mod version 
6, MLS, module name loadkeys\005
Quoted 2 lines

Please let me know what you think of this, in terms of text formatting, information displayed, and use of file(1) features.

"policy version 1" ought to be "policy type 1", or more simply, "base module" (1) or "non-base module" (2).

Just for comparison with the existing support in file for kernel policies, "file policy.21" displays:
policy.21: SE Linux policy v21 8 symbols 7 ocons

Not sure though that the symbols and ocons info is helpful there to users, and it should always be implicit from the version.

Note btw that this format is expected to be obsoleted by the policyrep work.

Quoted 16 lines

The \005 after the module name is due to the fact that file(1) seems to support only two types of string, a "C string" (terminated by \0) and a "Pascal string" where a single byte is used to indicate the length. Using a 32bit little-endian word to indicate the length doesn't seem to work with file(1) - but if anyone can figure out a way then please let me know.

It seems to me that it would be a good idea to write /etc/magic entries at the same time as devising file formats. Being able to quickly and easily determine the contents of a file is a really handy feature. Working with the limitations of file(1) to support this to the greatest degree possible would be a good thing. If the module name was limited to 255 characters I doubt that it would ever inconvenience anyone (in the past I've used compilers that support symbol lengths of ~30 characters), but having a better display in file(1) output would often help people. Another option would be to have a word indicating the string length while also having a 0 terminator (wasting the occasional byte isn't really a problem).

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 10 lines · Russell Coker

# SE Linux policy modules *.pp
0 lelong 0xf97cff8f SE Linux modular policy

Quoted 8 lines
4      lelong  x       version %d,
8      lelong  x       %d sections,
Quoted 6 lines

(12.l) lelong 0xf97cff8d

Quoted 5 lines
(12.l+27) lelong x           mod version %d,
(12.l+31) lelong 0           Not MLS,
(12.l+31) lelong 1           MLS,

(12.l+23) lelong 2

Quoted 1 line

(12.l+47) string >\0 module name %s

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

(12.l+23) lelong 1 base

The above /etc/magic entry allows file(1) to display some information about policy modules. Below is a sample of the result:

# file qmail.pp  base.pp  /tmp/loadkeys.pp
qmail.pp:         SE Linux modular policy version 1, 2 sections, mod
version 7, Not MLS, module name qmail\005

Also I think SELinux policy package, this magic number is for packages, modules have their own magic number.

Quoted 14 lines
Quoted 6 lines

base.pp: SE Linux modular policy version 1, 4 sections, mod
version 7, Not MLS, base /tmp/loadkeys.pp: SE Linux modular policy version 1, 2 sections, mod version 6, MLS, module name loadkeys\005

Please let me know what you think of this, in terms of text formatting, information displayed, and use of file(1) features.

"policy version 1" ought to be "policy type 1", or more simply, "base module" (1) or "non-base module" (2).

Just for comparison with the existing support in file for kernel policies, "file policy.21" displays:
policy.21: SE Linux policy v21 8 symbols 7 ocons

Quoted 24 lines

Not sure though that the symbols and ocons info is helpful there to users, and it should always be implicit from the version.

Note btw that this format is expected to be obsoleted by the policyrep work.

Quoted 18 lines

The \005 after the module name is due to the fact that file(1) seems to support only two types of string, a "C string" (terminated by \0) and a "Pascal string" where a single byte is used to indicate the length. Using a 32bit little-endian word to indicate the length doesn't seem to work with file(1) - but if anyone can figure out a way then please let me know.

It seems to me that it would be a good idea to write /etc/magic entries at the same time as devising file formats. Being able to quickly and easily determine the contents of a file is a really handy feature. Working with the limitations of file(1) to support this to the greatest degree possible would be a good thing. If the module name was limited to 255 characters I doubt that it would ever inconvenience anyone (in the past I've used compilers that support symbol lengths of ~30 characters), but having a better display in file(1) output would often help people. Another option would be to have a word indicating the string length while also having a 0 terminator (wasting the occasional byte isn't really a problem).

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
Quoted 6 lines · Joshua Brindle
Quoted 3 lines
Quoted 3 lines
# file qmail.pp  base.pp  /tmp/loadkeys.pp
qmail.pp:         SE Linux modular policy version 1, 2 sections, mod
version 7, Not MLS, module name qmail\005

Also I think SELinux policy package, this magic number is for packages, modules have their own magic number.

# file /etc/selinux/refpolicy-mls/policy/policy.22
/etc/selinux/refpolicy-mls/policy/policy.22: SE Linux policy v22 MLS 8 symbols 
7 ocons

Yes, I've got that.

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

base.pp: SE Linux modular policy version 1, 4 sections, mod
version 7, Not MLS, base /tmp/loadkeys.pp: SE Linux modular policy version 1, 2 sections, mod version 6, MLS, module name loadkeys\005

Please let me know what you think of this, in terms of text formatting, information displayed, and use of file(1) features.

"policy version 1" ought to be "policy type 1", or more simply, "base module" (1) or "non-base module" (2).

But non-base modules have a 1 in that field too!

Quoted 6 lines
Quoted 6 lines

Just for comparison with the existing support in file for kernel policies, "file policy.21" displays:
policy.21: SE Linux policy v21 8 symbols 7 ocons

Not sure though that the symbols and ocons info is helpful there to users, and it should always be implicit from the version.

Probably not. But that was a mistake I made long ago. Hopefully this discussion will help avoid such things this time.

Quoted 2 lines
Quoted 2 lines

Note btw that this format is expected to be obsoleted by the policyrep work.

Which format? The module format or the policy binary format?

In either case we still need file(1) support. When someone gives me a disk containing a Debian/Etch or Fedora Core 5 filesystem in 2012 which has most files in /lost+found and asks me to recover data then the presence of magic entries will really help.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw

<snip>

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Note btw that this format is expected to be obsoleted by the policyrep work.

Which format? The module format or the policy binary format?

The kernel binary format isn't changing. The module format (and policy package format) are going away in favor of source based modules.

Quoted 6 lines

In either case we still need file(1) support. When someone gives me a disk containing a Debian/Etch or Fedora Core 5 filesystem in 2012 which has most files in /lost+found and asks me to recover data then the presence of magic entries will really help.

Which is fine, but it just won't be useful for future modules.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
Quoted 1 line · Joshua Brindle

Which is fine, but it just won't be useful for future modules.

Would it be possible to try and make things work well with file(1) when designing future module formats? Little things like zero terminating strings really help.

The magic database has entries for systems that were EOL'd 15+ years ago, so we will of course keep adding entries for these formats.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#6 lore raw
Quoted 7 lines

-----Original Message-----
From: Russell Coker [mailto:[email protected]]
Sent: Friday, March 28, 2008 9:49 PM
To: Joshua Brindle
Cc: Stephen Smalley; SE-Linux
Subject: Re: file(1)

Quoted 8 lines
Quoted 1 line · Joshua Brindle

Which is fine, but it just won't be useful for future modules.

Would it be possible to try and make things work well with file(1) when designing future module formats? Little things like zero terminating strings really help.

We want modules to be user editable using standard editors so no binary data will be used..
Unless file will be able to find the first non-comment line I'm not sure how it'll work.

Quoted 4 lines

The magic database has entries for systems that were EOL'd 15+ years ago, so we will of course keep adding entries for these formats.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#7 lore raw
Quoted 9 lines · Joshua Brindle
Quoted 6 lines
Quoted 1 line · <[email protected]> wrote:

Which is fine, but it just won't be useful for future modules.

Would it be possible to try and make things work well with file(1) when designing future module formats? Little things like zero terminating strings really help.

We want modules to be user editable using standard editors so no binary data will be used..

So we are back to editing source? That's fine by me.

Quoted 2 lines

Unless file will be able to find the first non-comment line I'm not sure how it'll work.

It seems to work fine for many other text files. Also there is nothing preventing the creator of a text file format from specifying that the first line must contain some specific text indicating the format. It probably would be good if the compiler (loader, linker, semanage, whatever you call it) could recognise something that might be suitable input. If it could give a specific error that it's operating on something it considers not to be a suitable source file it would help cover some common error cases.

$ file src/*
src/Makefile:      ASCII make commands text
src/dso.h:         ASCII C program text
src/mcstrans.c:    ASCII C program text
src/mcstrans.init: Bourne-Again shell script text executable
src/mcstransd.c:   ASCII C program text

The above is the file(1) output for some common file types. It seems to work quite well for them.

Below are some quick magic entries I hacked up for SE Linux policy source. I'm not sure at this stage whether I should submit them for inclusion. But they do demonstrate what can be done with recognising text files.

0       string  policy_module(  SE Linux policy module source
1       string  policy_module(  SE Linux policy module source
2       string  policy_module(  SE Linux policy module source

0 string ##\ <summary> SE Linux policy interface source

0 search gen_context( SE Linux policy file contexts

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#8 lore raw
Quoted 12 lines

-----Original Message-----
From: Russell Coker [mailto:[email protected]]
Sent: Friday, March 28, 2008 11:18 PM
To: Joshua Brindle
Cc: Stephen Smalley; SE-Linux
Subject: Re: file(1)

Quoted 3 lines · Joshua Brindle
Quoted 3 lines
Quoted 1 line · <[email protected]> wrote:

Which is fine, but it just won't be useful for future modules.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Would it be possible to try and make things work well with file(1) when designing future module formats? Little things like zero terminating strings really help.

We want modules to be user editable using standard editors so no binary data will be used..

So we are back to editing source? That's fine by me.

Yes, but with the infrastructure to link in modules, etc. Source just makes it much easier to manage the modules from the user perspective.

Quoted 29 lines
Quoted 2 lines

Unless file will be able to find the first non-comment line I'm not sure how it'll work.

It seems to work fine for many other text files. Also there is nothing preventing the creator of a text file format from specifying that the first line must contain some specific text indicating the format. It probably would be good if the compiler (loader, linker, semanage, whatever you call it) could recognise something that might be suitable input. If it could give a specific error that it's operating on something it considers not to be a suitable source file it would help cover some common error cases.

$ file src/*
src/Makefile:      ASCII make commands text
src/dso.h:         ASCII C program text
src/mcstrans.c:    ASCII C program text
src/mcstrans.init: Bourne-Again shell script text executable
src/mcstransd.c:   ASCII C program text

The above is the file(1) output for some common file types. It seems to work quite well for them.

Below are some quick magic entries I hacked up for SE Linux policy source.
I'm not sure at this stage whether I should submit them for inclusion. But they do demonstrate what can be done with recognising text files.

Quoted 8 lines
0       string  policy_module(  SE Linux policy module source
1       string  policy_module(  SE Linux policy module source
2       string  policy_module(  SE Linux policy module source

0 string ##\ <summary> SE Linux policy interface source

0 search gen_context( SE Linux policy file contexts

One thing, there won't be separate files for interfaces, modules, and file contexts anymore (at least from the toolchain perspective, refpolicy might keep them separate internally)

So modules will be self contained source files with everything necessary.

I wouldn't submit anything yet, a lot of the refpolicy things are slated to become parts of the proper language and the way modules are going to look haven't been completely hammered down.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#9 lore raw
In reply to Russell Coker
Quoted 5 lines · Russell Coker
Quoted 4 lines · Joshua Brindle
Quoted 3 lines
Quoted 3 lines
# file qmail.pp  base.pp  /tmp/loadkeys.pp
qmail.pp:         SE Linux modular policy version 1, 2 sections, mod
version 7, Not MLS, module name qmail\005
Quoted 8 lines
Quoted 2 lines

Also I think SELinux policy package, this magic number is for packages, modules have their own magic number.

# file /etc/selinux/refpolicy-mls/policy/policy.22
/etc/selinux/refpolicy-mls/policy/policy.22: SE Linux policy v22 MLS 8 symbols 
7 ocons

Yes, I've got that.

Wait - I think there might be some confusion here.

There are three or four formats depending on how you are counting:
- the kernel binary policy file (policy.N),
- the module policy package file (.pp files),
- the binary module file (.mod files, and these come in two flavors - base and non-base).

base.pp is a module policy package file containing a binary module (.mod) file, a file contexts (.fc) file, and potentially other components (e.g. seusers, users_extra).

So don't confuse the module policy package file with a module file - the module policy package file has its own header before the module file.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

base.pp: SE Linux modular policy version 1, 4 sections, mod
version 7, Not MLS, base /tmp/loadkeys.pp: SE Linux modular policy version 1, 2 sections, mod version 6, MLS, module name loadkeys\005

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Please let me know what you think of this, in terms of text formatting, information displayed, and use of file(1) features.

"policy version 1" ought to be "policy type 1", or more simply, "base module" (1) or "non-base module" (2).

But non-base modules have a 1 in that field too!

Right - I mistakenly thought you were dealing with .mod files there rather than .pp files. So that value reflects the version of the modular policy package format, which is independent of the module type or the module version.

Quoted 19 lines
Quoted 6 lines
Quoted 6 lines

Just for comparison with the existing support in file for kernel policies, "file policy.21" displays:
policy.21: SE Linux policy v21 8 symbols 7 ocons

Not sure though that the symbols and ocons info is helpful there to users, and it should always be implicit from the version.

Probably not. But that was a mistake I made long ago. Hopefully this discussion will help avoid such things this time.

Quoted 2 lines
Quoted 2 lines

Note btw that this format is expected to be obsoleted by the policyrep work.

Which format? The module format or the policy binary format?

In either case we still need file(1) support. When someone gives me a disk containing a Debian/Etch or Fedora Core 5 filesystem in 2012 which has most files in /lost+found and asks me to recover data then the presence of magic entries will really help.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#10 lore raw
Quoted 23 lines · Stephen Smalley
Quoted 5 lines · Russell Coker
Quoted 4 lines · Joshua Brindle
Quoted 3 lines
Quoted 3 lines
# file qmail.pp  base.pp  /tmp/loadkeys.pp
qmail.pp:         SE Linux modular policy version 1, 2 sections, mod
version 7, Not MLS, module name qmail\005
Quoted 8 lines
Quoted 2 lines

Also I think SELinux policy package, this magic number is for packages, modules have their own magic number.

# file /etc/selinux/refpolicy-mls/policy/policy.22
/etc/selinux/refpolicy-mls/policy/policy.22: SE Linux policy v22 MLS 8 symbols 
7 ocons

Yes, I've got that.

Wait - I think there might be some confusion here.

There are three or four formats depending on how you are counting:
- the kernel binary policy file (policy.N),
- the module policy package file (.pp files),
- the binary module file (.mod files, and these come in two flavors - base and non-base).

Quoted 6 lines

base.pp is a module policy package file containing a binary module (.mod) file, a file contexts (.fc) file, and potentially other components (e.g. seusers, users_extra).

So don't confuse the module policy package file with a module file - the module policy package file has its own header before the module file.

So, to be precise, we've got the following format for the module policy package file:
module package magic number (different from the module magic number) module package format version (different from the module format version) number of sections
offset array, indexed by section number
binary module (with its own header)
any other sections (file contexts, etc)

Note that the offset array is variable length - it will be the number of sections * sizeof uint32.

And note that the order of sections isn't necessarily fixed, although the current module package writing code always puts the binary module first. But the read code doesn't make any assumptions about ordering and just determines what each section is as it encounters it.

At present, we require each .pp file to at least contain a .mod file, but we've talked before about lifting that requirement so that a .pp file can just carry a .fc file or other data without requiring a module. Although today people favor using semanage fcontext instead since it provides safer ordering guarantees.

One other fun tidbit - in libsepol 2.0.23, I changed the policy reading code to accept either "Flask" or "SE Linux" as the string identifier as other projects, like Solaris FMAC, are using "Flask" as the string identifier as a more general specifier. So it would be nice if file(1) ultimately accepted either as well.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#11 lore raw
Quoted 22 lines · Stephen Smalley
Quoted 6 lines

There are three or four formats depending on how you are counting:
- the kernel binary policy file (policy.N),
- the module policy package file (.pp files),
- the binary module file (.mod files, and these come in two flavors - base and non-base).

Quoted 6 lines

base.pp is a module policy package file containing a binary module (.mod) file, a file contexts (.fc) file, and potentially other components (e.g. seusers, users_extra).

So don't confuse the module policy package file with a module file - the module policy package file has its own header before the module file.

So, to be precise, we've got the following format for the module policy package file:
module package magic number (different from the module magic number) module package format version (different from the module format version) number of sections
offset array, indexed by section number
binary module (with its own header)
any other sections (file contexts, etc)

Quoted 2 lines

Note that the offset array is variable length - it will be the number of sections * sizeof uint32.

This is where things start to become tricky, magic(5) doesn't support arrays. I could probably handle this with nested if statements for a reasonable number (it seems that we generally don't have that many).

Quoted 4 lines

And note that the order of sections isn't necessarily fixed, although the current module package writing code always puts the binary module first. But the read code doesn't make any assumptions about ordering and just determines what each section is as it encounters it.

My current effort just gives information on the first one, the binary seems to be the most interesting one (if for example qmail.pp
becomes /lost+found/#1234 then having the string "qmail\5" be displayed would be helpful).

Quoted 5 lines

One other fun tidbit - in libsepol 2.0.23, I changed the policy reading code to accept either "Flask" or "SE Linux" as the string identifier as other projects, like Solaris FMAC, are using "Flask" as the string identifier as a more general specifier. So it would be nice if file(1) ultimately accepted either as well.

Given that we already have hex magic numbers to recognise the various structures and that the most desirable way for humans to recognise file types is via file(1), what is the benefit of having either "SE Linux" or "Flask" in there?

Would it be possible to just accept that for the current version of the file format "SE Linux" will be contained in there and not bother about this? It's no secret that the Flask code was not originally developed for Solaris.

Eventually we just have to lose some data from file(1) output when these situations arise, I suspect that we have already reached the stage where we exceed the flexibility of the magic(5) configuration language. It may be that on the Linux platform we just get the wrong data from other platforms.

It seems that there are ongoing plans for new file formats. Could we agree that getting things to work with file(1) will be a pre-requisite for future file formats?

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#12 lore raw
Quoted 23 lines · Russell Coker
Quoted 22 lines · Stephen Smalley
Quoted 6 lines

There are three or four formats depending on how you are counting:
- the kernel binary policy file (policy.N),
- the module policy package file (.pp files),
- the binary module file (.mod files, and these come in two flavors - base and non-base).

Quoted 6 lines

base.pp is a module policy package file containing a binary module (.mod) file, a file contexts (.fc) file, and potentially other components (e.g. seusers, users_extra).

So don't confuse the module policy package file with a module file - the module policy package file has its own header before the module file.

So, to be precise, we've got the following format for the module policy package file:
module package magic number (different from the module magic number) module package format version (different from the module format version) number of sections
offset array, indexed by section number
binary module (with its own header)
any other sections (file contexts, etc)

Quoted 6 lines
Quoted 2 lines

Note that the offset array is variable length - it will be the number of sections * sizeof uint32.

This is where things start to become tricky, magic(5) doesn't support arrays. I could probably handle this with nested if statements for a reasonable number (it seems that we generally don't have that many).

Yes, in general you're likely to only encounter three situations:
- base.pp file with all of the sections present (or at least the ones that we actually use these days),
- foo.pp file with only a module section,
- bar.pp file with a module section and a file contexts section.

Quoted 9 lines
Quoted 4 lines

And note that the order of sections isn't necessarily fixed, although the current module package writing code always puts the binary module first. But the read code doesn't make any assumptions about ordering and just determines what each section is as it encounters it.

My current effort just gives information on the first one, the binary seems to be the most interesting one (if for example qmail.pp
becomes /lost+found/#1234 then having the string "qmail\5" be displayed would be helpful).

Yes - I was just saying that the format doesn't actually guarantee that the binary module will always be first. That's just an artifact of the current implementation.

Quoted 10 lines
Quoted 5 lines

One other fun tidbit - in libsepol 2.0.23, I changed the policy reading code to accept either "Flask" or "SE Linux" as the string identifier as other projects, like Solaris FMAC, are using "Flask" as the string identifier as a more general specifier. So it would be nice if file(1) ultimately accepted either as well.

Given that we already have hex magic numbers to recognise the various structures and that the most desirable way for humans to recognise file types is via file(1), what is the benefit of having either "SE Linux" or "Flask" in there?

Possibly none, but the string identifier is well entrenched there.

Quoted 3 lines

Would it be possible to just accept that for the current version of the file format "SE Linux" will be contained in there and not bother about this? It's no secret that the Flask code was not originally developed for Solaris.

The Flask code wasn't originally developed for Linux either ;) It would be confusing to use "SE Linux" there on other platforms. The change to accept either string identifier in libsepol is so that higher level policy tools like setools can read and analyze either kind of policy, as they don't really care whether the underlying platform is Linux or some other OS. Possibly not so important for file(1).

Quoted 8 lines

Eventually we just have to lose some data from file(1) output when these situations arise, I suspect that we have already reached the stage where we exceed the flexibility of the magic(5) configuration language. It may be that on the Linux platform we just get the wrong data from other platforms.

It seems that there are ongoing plans for new file formats. Could we agree that getting things to work with file(1) will be a pre-requisite for future file formats?

The only new format I'm aware of is for the policyrep work, and that is mostly a reversion to source text format for policy modules and policy packages.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.