seinfo and binary policy endianness
Hello,
Our test team has run into a problem with seinfo on big endian platforms. Seinfo compares the unswapped SELINUX_MAGIC defined in borrowed.h with it's little endian counterpart at the top of the binary policy. So it doesn't recognize binary policies. It's easy enough to fix by #ifdef'ing swapped and unswapped definitions in borrrowed.h. But shouldn't SELINUX_MAGIC be defined in a single place and used throughout to write and read the policy?
So, as a side issue, should one expect policies to be portable across platforms with differing endianness? It may work--I haven't tried. Portability would be useful for cross-compile environments, for analysis when one has no access to the platform that generated the policy, and for cross-platform deployment of a single binary policy. It looks like binary policies are always little endian so portability may not be an issue. I must test that. Also, might it not be nice to have the policies in big endian (network byte order)? I know that would be busy work. But big endian just feels right for portable files.
Signature · 7 lines
George Wilson <[email protected]> IBM Linux Technology Center -- 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.
Quoted 9 lines · George Wilson
Hello,
Our test team has run into a problem with seinfo on big endian platforms. Seinfo compares the unswapped
SELINUX_MAGICdefined inborrowed.hwith it's little endian counterpart at the top of the binary policy. So it doesn't recognize binary policies. It's easy enough to fix by #ifdef'ing swapped and unswapped definitions inborrrowed.h. But shouldn'tSELINUX_MAGICbe defined in a single place and used throughout to write and read the policy?
Quoted 10 lines
So, as a side issue, should one expect policies to be portable across platforms with differing endianness? It may work--I haven't tried. Portability would be useful for cross-compile environments, for analysis when one has no access to the platform that generated the policy, and for cross-platform deployment of a single binary policy. It looks like binary policies are always little endian so portability may not be an issue. I must test that. Also, might it not be nice to have the policies in big endian (network byte order)? I know that would be busy work. But big endian just feels right for portable files.
Attached is Emily's patch, which is far more elegant than a borrowed.h hack. It seems like borrowed.h should really go away.
Signature · 3 lines
George Wilson IBM Linux Technology Center <[email protected]>
libapol/binpol/binpol.c +3 -0
@@ -1435,6 +1435,7 @@/* magic # and sz of policy string */ buf =ap_read_fbuf (fb,sizeof (__u32)*2 , fp);if (buf ==NULL ) { rt = fb->err; goto err_return; } + buf[0 ] =le32_to_cpu (buf[0 ]);if (buf[0 ] !=SELINUX_MAGIC ) { rt =-2 ; goto err_return; } len =le32_to_cpu (buf[1 ]);
@@ -1740,6 +1741,7 @@if (sz !=1 ) rt = FALSE;/* problem reading file */ + ubuf =le32_to_cpu (ubuf);if (ubuf ==SELINUX_MAGIC ) rt = TRUE;else
@@ -1773,6 +1775,7 @@/* magic # and sz of policy string */ buf =ap_read_fbuf (fb,sizeof (__u32)*2 , fp);if (buf ==NULL ) { rt = fb->err; goto err_return; } + buf[0 ] =le32_to_cpu (buf[0 ]);if (buf[0 ] !=SELINUX_MAGIC ) { rt =-2 ; goto err_return; } len =le32_to_cpu (buf[1 ]);
Quoted 33 lines
-----Original Message-----
From: George Wilson [mailto:[email protected]]
Sent: Thursday, September 29, 2005 6:56 PM
To: SELinux
Cc: Karl MacMillan; Emily Ratliff
Subject: Re: seinfo and binary policy endiannessQuoted 3 lines · George Wilson
Hello,
Our test team has run into a problem with seinfo on big endian
platforms.
Quoted 1 line
Seinfo compares the unswapped
SELINUX_MAGICdefined inborrowed.hwithit's
Quoted 1 line
little endian counterpart at the top of the binary policy. So it
doesn't
Quoted 1 line
recognize binary policies. It's easy enough to fix by #ifdef'ing
swapped and
Quoted 1 line
unswapped definitions in
borrrowed.h. But shouldn'tSELINUX_MAGICbedefined
Quoted 4 lines
in a single place and used throughout to write and read the policy?
So, as a side issue, should one expect policies to be portable across platforms with differing endianness? It may work--I haven't tried.
Portability
Quoted 1 line
would be useful for cross-compile environments, for analysis when one
has no
Quoted 2 lines
access to the platform that generated the policy, and for cross-platform deployment of a single binary policy. It looks like binary policies are
always
Quoted 1 line
little endian so portability may not be an issue. I must test that.
Also,
Quoted 1 line
might it not be nice to have the policies in big endian (network byte
Quoted 9 lines
order)?
Quoted 1 line
I know that would be busy work. But big endian just feels right for
portable
Quoted 2 lines
files.
Attached is Emily's patch, which is far more elegant than a
borrowed.hhack. It seems likeborrowed.hshould really go away.
Thanks - I'll get this integrated. Why should borrowed.h go away? We can't rely on libsepol to be stable, and one of the main defining characteristics of libapol is that it maintains backwards compatibility. We can read any policy format from pre-version 12 to current policies. That would be difficult to do relying on libsepol.
Karl
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 4 lines
--
George Wilson
IBM Linux Technology Center
<[email protected]>
--
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.
Quoted 5 lines · Karl MacMillan
Thanks - I'll get this integrated. Why should
borrowed.hgo away? We can't rely on libsepol to be stable, and one of the main defining characteristics of libapol is that it maintains backwards compatibility. We can read any policy format from pre-version 12 to current policies. That would be difficult to do relying on libsepol.
Not sure what you mean by "stable". You would use the static libsepol, just like recent versions of slat, so you don't need a stable ABI from the shared lib.
libsepol supports all policy versions 15 and later (i.e. everything ever supported by a 2.6 kernel), and I'm a little dubious that policy 12 has much life left to it (and in any event, you could always maintain that separately for that particular use).
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.
Quoted 11 lines
-----Original Message-----
From: Stephen Smalley [mailto:[email protected]]
Sent: Friday, September 30, 2005 10:23 AM
To: Karl MacMillan
Cc: [email protected]; 'SELinux'; 'Emily Ratliff'
Subject: RE: seinfo and binary policy endiannessQuoted 1 line · Karl MacMillan
Thanks - I'll get this integrated. Why should
borrowed.hgo away? Wecan't
Quoted 1 line
rely on libsepol to be stable, and one of the main defining
Quoted 9 lines
characteristics
Quoted 3 lines
of libapol is that it maintains backwards compatibility. We can read any policy format from pre-version 12 to current policies. That would be difficult to do relying on libsepol.
Not sure what you mean by "stable". You would use the static libsepol, just like recent versions of slat, so you don't need a stable ABI from the shared lib.
Stable API, not ABI - I don't want to have to track a constantly changing code base. This hasn't been a big issue lately though.
Karl
Quoted 5 lines
libsepol supports all policy versions 15 and later (i.e. everything ever supported by a 2.6 kernel), and I'm a little dubious that policy 12 has much life left to it (and in any event, you could always maintain that separately for that particular use).
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 3 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.
Quoted 2 lines · George Wilson
Attached is Emily's patch, which is far more elegant than a
borrowed.hhack. It seems likeborrowed.hshould really go away.
Even better would be for setools to just use libsepol, which is _the_ library for manipulation of binary policies...
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.
Quoted 7 lines
-----Original Message-----
From: Stephen Smalley [mailto:[email protected]]
Sent: Friday, September 30, 2005 10:12 AM
To: [email protected]
Cc: SELinux; Karl MacMillan; Emily Ratliff
Subject: Re: seinfo and binary policy endianness
Quoted 7 lines
Quoted 2 lines · George Wilson
Attached is Emily's patch, which is far more elegant than a
borrowed.hhack. It seems likeborrowed.hshould really go away.Even better would be for setools to just use libsepol, which is _the_ library for manipulation of binary policies...
Again, I agree that only having one library for representing policies would be desirable in many ways. Not just for reading, but for all policy representation and analysis. What prevents me from making that choice is:
a) backwards compatibility - we _must_ be able to load and represent very old policies. We still have work analyzing pre-LSM policies, for example.
I believe that libsepol's data structures can now represent everything from older policies with the exception of clone rules (which I am willing to drop). That leaves the parsers - which I guess we could have more than one source parser into the same data structures. So this is probably solvable, I would just need a commitment that backwards compatibility would be maintained.
b) conversion cost - the cost of converting all of our analysis code over to use libsepol would, in my opinion, outweigh the benefit. It appears to me to be less work to continue to maintain the separate code base than to do the conversion. Unless the changes, I cannot justify the cost.
Karl
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 3 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.
Quoted 3 lines · Karl MacMillan
Again, I agree that only having one library for representing policies would be desirable in many ways. Not just for reading, but for all policy representation and analysis. What prevents me from making that choice is:
I wasn't suggesting the latter (unified representation), just the former (reading the binary policy image). I'd still expect you to take the resulting libsepol data structures and convert them over to the native libapol representation that is presumably geared more toward analysis needs, unless it happens to be the case that the formats have converged to such a degree as to make that unnecessary (e.g. due to the avtab changes made recently).
Quoted 2 lines
a) backwards compatibility - we _must_ be able to load and represent very old policies. We still have work analyzing pre-LSM policies, for example.
In the short term, perhaps. But that is a rather specialized case, and doesn't require that the main setools branch retain that support. Seems suitable for a fork.
Quoted 11 lines
I believe that libsepol's data structures can now represent everything from older policies with the exception of clone rules (which I am willing to drop). That leaves the parsers - which I guess we could have more than one source parser into the same data structures. So this is probably solvable, I would just need a commitment that backwards compatibility would be maintained.
b) conversion cost - the cost of converting all of our analysis code over to use libsepol would, in my opinion, outweigh the benefit. It appears to me to be less work to continue to maintain the separate code base than to do the conversion. Unless the changes, I cannot justify the cost.
I don't think you need to do that - just convert the sepol data structures to your internal structures after the read. No need to touch the rest of your code.
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.
Quoted 2 lines · Stephen Smalley
Even better would be for setools to just use libsepol, which is _the_ library for manipulation of binary policies...
Three reasons why it currently does not:
1. We have backwards compatibility in libapol, since we support analysis of all sorts of versions of SELinux.
2. It's rather nice to have a separate code path to parse the policy for testing purposes. We use it a lot in testing compiler changes, etc.
3. (Most importantly) When I first wrote the binpol parser for libapol, libsepol did not exist in any form like today :-)
--
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.
Quoted 3 lines · Frank Mayer
Three reasons why it currently does not:
1. We have backwards compatibility in libapol, since we support analysis of all sorts of versions of SELinux.
Yes, known, but libsepol goes back to version 15, the first version supported in 2.6 kernels, and I'd be surprised if the policy.12 users aren't upgraded to 2.6 RSN.
Quoted 2 lines
2. It's rather nice to have a separate code path to parse the policy for testing purposes. We use it a lot in testing compiler changes, etc.
But it is also a major code duplication and potential source of subtle bugs in your analyses.
Quoted 2 lines
3. (Most importantly) When I first wrote the binpol parser for libapol, libsepol did not exist in any form like today :-)
Yes, understood. But going forward, I think it is the right path.
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.
Quoted 8 lines
-----Original Message-----
From: Stephen Smalley [mailto:[email protected]]
Sent: Friday, September 30, 2005 10:51 AM
To: Frank Mayer
Cc: [email protected]; 'SELinux'; 'Karl MacMillan'; 'Emily Ratliff'
Subject: RE: seinfo and binary policy endiannessOn Fri, 2005-09-30 at 10:43 -0400, Frank Mayer wrote:
Quoted 9 lines
Quoted 2 lines
Three reasons why it currently does not:
1. We have backwards compatibility in libapol, since we support analysisof
Quoted 1 line
all sorts of versions of SELinux.
Yes, known, but libsepol goes back to version 15, the first version supported in 2.6 kernels, and I'd be surprised if the policy.12 users aren't upgraded to 2.6 RSN.
Most, but not all. We can't load version 12 binaries anyway - just source. So the comment is only relevant if we moved to libsepol entirely.
Quoted 6 lines
Quoted 2 lines
2. It's rather nice to have a separate code path to parse the policy for testing purposes. We use it a lot in testing compiler changes, etc.
But it is also a major code duplication and potential source of subtle bugs in your analyses.
And supporting things like constraints will require significant work in libapol.
Quoted 5 lines
Quoted 2 lines
3. (Most importantly) When I first wrote the binpol parser for libapol, libsepol did not exist in any form like today :-)
Yes, understood. But going forward, I think it is the right path.
We'll think about it further.
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 3 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.
Quoted 10 lines
-----Original Message-----
From: George Wilson [mailto:[email protected]]
Sent: Thursday, September 29, 2005 6:26 PM
To: SELinux
Cc: Karl MacMillan; Emily Ratliff
Subject: seinfo and binary policy endiannessHello,
Quoted 10 lines
Our test team has run into a problem with seinfo on big endian platforms. Seinfo compares the unswapped
SELINUX_MAGICdefined inborrowed.hwith it's
little endian counterpart at the top of the binary policy. So it doesn't recognize binary policies. It's easy enough to fix by #ifdef'ing swapped and
unswapped definitions inborrrowed.h. But shouldn'tSELINUX_MAGICbe defined
in a single place and used throughout to write and read the policy?
Thanks for testing this - none of our powerbook owners seem to be loading binary policies I guess. Yes - there is only one SELINUX_MAGIC. Your other patch is correct.
Quoted 9 lines
So, as a side issue, should one expect policies to be portable across platforms with differing endianness? It may work--I haven't tried. Portability
would be useful for cross-compile environments, for analysis when one has no
access to the platform that generated the policy, and for cross-platform deployment of a single binary policy. It looks like binary policies are always
little endian so portability may not be an issue. I must test that.
Policies should be portable - as you mention they are always stored little endian. I've not tried this much in practice, but that is the intention.
Quoted 7 lines
Also,
might it not be nice to have the policies in big endian (network byte order)?
I know that would be busy work. But big endian just feels right for portable
files.
Portable formats transferred over the network maybe, but I don't see why it matters for file formats. It is an arbitrary choice and it makes more sense to have the default be a no-op on 90% of the hardware for reading these policies. Feel free to submit a patch to Steve and the kernel maintainers though :)
Karl
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 3 lines
--
George Wilson <[email protected]>
IBM Linux Technology Center
--
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.
Quoted 6 lines · George Wilson
Our test team has run into a problem with seinfo on big endian platforms. Seinfo compares the unswapped
SELINUX_MAGICdefined inborrowed.hwith it's little endian counterpart at the top of the binary policy. So it doesn't recognize binary policies. It's easy enough to fix by #ifdef'ing swapped and unswapped definitions inborrrowed.h. But shouldn'tSELINUX_MAGICbe defined in a single place and used throughout to write and read the policy?
IMHO, setools should just be using libsepol to read binary policies and then converting its data structures into its own internal ones.
Quoted 2 lines
So, as a side issue, should one expect policies to be portable across platforms with differing endianness?
Yes, that is the intent. They are always converted to/from little endian when written/read.
Quoted 8 lines
It may work--I haven't tried. Portability
would be useful for cross-compile environments, for analysis when one has no access to the platform that generated the policy, and for cross-platform deployment of a single binary policy. It looks like binary policies are always little endian so portability may not be an issue. I must test that. Also, might it not be nice to have the policies in big endian (network byte order)? I know that would be busy work. But big endian just feels right for portable files.
It adds overhead on our most common platform (x86). Also, ext2 uses little endian, so it must be right ;)
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.
Quoted 14 lines
-----Original Message-----
From: Stephen Smalley [mailto:[email protected]]
Sent: Friday, September 30, 2005 10:11 AM
To: George Wilson
Cc: SELinux; Karl MacMillan; Emily Ratliff
Subject: Re: seinfo and binary policy endiannessQuoted 1 line · George Wilson
Our test team has run into a problem with seinfo on big endian
platforms.
Quoted 1 line
Seinfo compares the unswapped
SELINUX_MAGICdefined inborrowed.hwithit's
Quoted 1 line
little endian counterpart at the top of the binary policy. So it
doesn't
Quoted 9 lines
Quoted 1 line
recognize binary policies. It's easy enough to fix by #ifdef'ing
swapped and
Quoted 1 line
unswapped definitions in
borrrowed.h. But shouldn'tSELINUX_MAGICbedefined
Quoted 1 line
in a single place and used throughout to write and read the policy?
IMHO, setools should just be using libsepol to read binary policies and then converting its data structures into its own internal ones.
This approach was discussed when we initially did this work. Again, the main drawback is the possibility that libsepol would drop backwards compatibility
- which I think is a good idea for libsepol. There is no reason to maintain the ability to read very old file formats in libsepol, but there is in libapol.
Other than that, using libsepol may have been easier. At this point, though, maintaining our binary parser is a fairly low amount of effort and switching would be a large effort.
Karl
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 3 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.
Quoted 5 lines · Karl MacMillan
This approach was discussed when we initially did this work. Again, the main drawback is the possibility that libsepol would drop backwards compatibility
- which I think is a good idea for libsepol. There is no reason to maintain the ability to read very old file formats in libsepol, but there is in libapol.
I'd be surprised if we dropped support for old formats from libsepol. We have talked about dropping the backward compatibility code from the kernel, but that requires a much tighter binding between policies and kernels than currently exists.
Quoted 3 lines
Other than that, using libsepol may have been easier. At this point, though, maintaining our binary parser is a fairly low amount of effort and switching would be a large effort.
You'll come around to our way of thinking eventually ;)
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.
Quoted 10 lines
-----Original Message-----
From: Stephen Smalley [mailto:[email protected]]
Sent: Friday, September 30, 2005 10:28 AM
To: Karl MacMillan
Cc: 'George Wilson'; 'SELinux'; 'Emily Ratliff'
Subject: RE: seinfo and binary policy endiannessQuoted 1 line · Karl MacMillan
This approach was discussed when we initially did this work. Again, the
main
Quoted 8 lines
Quoted 1 line
drawback is the possibility that libsepol would drop backwards
compatibility
Quoted 1 line
- which I think is a good idea for libsepol. There is no reason to
maintain
Quoted 2 lines
the ability to read very old file formats in libsepol, but there is in libapol.
I'd be surprised if we dropped support for old formats from libsepol.
My concern is that I would be surprised when you did drop that support :)
Quoted 4 lines
We have talked about dropping the backward compatibility code from the kernel, but that requires a much tighter binding between policies and kernels than currently exists.
Quoted 8 lines
Quoted 1 line
Other than that, using libsepol may have been easier. At this point,
though,
Quoted 1 line
maintaining our binary parser is a fairly low amount of effort and
switching
Quoted 1 line
would be a large effort.
You'll come around to our way of thinking eventually ;)
Especially when I get a patch from someone other than us making the change . . .
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 3 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.