-------
Any review would be much appreciated.
Comments:
--------
Add a netlink attribute INET_DIAG_SECCTX
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
The element sk_security of struct sock represents the socket
security context ID, which is inherited from the parent process
when the socket is created.
but when SELinux type_transition rule is applied to socket, or
application sets /proc/xxx/attr/createsock, the socket security
context would be different from the creating process. For these
conditions, the "netstat -Z" would return wrong value, since
"netstat -Z" only returns the process security context as socket
process security.
The application to verify the netlink new attribute.
------
See attached file
test:
--------
1. Enable SELinux when compile and startup .
root@qemu-host:/root> ./printsocketsec
inode:7141 system_u:system_r:rpcbind_t:s0
inode:7136 system_u:system_r:rpcbind_t:s0
inode:7604 system_u:system_r:initrc_t:s0
inode:7227 system_u:system_r:rpcd_t:s0
inode:7471 system_u:system_r:sshd_t:s0-s0:c0.c1023
inode:7469 system_u:system_r:sshd_t:s0-s0:c0.c1023
inode:7552 system_u:system_r:sendmail_t:s0
inode:7348 system_u:system_r:initrc_t:s0
inode:7553 system_u:system_r:sendmail_t:s0
root@qemu-host:/root>
2. Disable SELinux when startup.
root@qemu-host:/root> ./printsocketsec
inode:3221
inode:2942
inode:2861
inode:3256
inode:3156
inode:3220
inode:3060
root@qemu-host:/root>
3. Disable SELinux when compile and startup
root@qemu-host:/root> ./printsocketsec
inode:3221
inode:2942
inode:2861
inode:3256
inode:3156
inode:3220
inode:3060
root@qemu-host:/root>
From: Roy.Li <redacted>
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
The element sk_security of struct sock represents the socket
security context ID, which is inherited from the parent process
when the socket is created.
but when SELinux type_transition rule is applied to socket, or
application sets /proc/xxx/attr/createsock, the socket security
context would be different from the creating process. For these
conditions, the "netstat -Z" will return wrong value, since
"netstat -Z" only returns the process security context as socket
process security.
Signed-off-by: Roy.Li <redacted>
---
include/linux/inet_diag.h | 3 ++-
net/ipv4/inet_diag.c | 38 +++++++++++++++++++++++++++++++++-----
2 files changed, 35 insertions(+), 6 deletions(-)
From: Rongqing Li <hidden> Date: 2011-08-31 08:38:23
On 08/31/2011 04:36 PM, rongqing.li@windriver.com wrote:
-------
Any review would be much appreciated.
Comments:
--------
Add a netlink attribute INET_DIAG_SECCTX
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
The element sk_security of struct sock represents the socket
security context ID, which is inherited from the parent process
when the socket is created.
but when SELinux type_transition rule is applied to socket, or
application sets /proc/xxx/attr/createsock, the socket security
context would be different from the creating process. For these
conditions, the "netstat -Z" would return wrong value, since
"netstat -Z" only returns the process security context as socket
process security.
The application to verify the netlink new attribute.
------
See attached file
test:
--------
1. Enable SELinux when compile and startup .
root@qemu-host:/root> ./printsocketsec
inode:7141 system_u:system_r:rpcbind_t:s0
inode:7136 system_u:system_r:rpcbind_t:s0
inode:7604 system_u:system_r:initrc_t:s0
inode:7227 system_u:system_r:rpcd_t:s0
inode:7471 system_u:system_r:sshd_t:s0-s0:c0.c1023
inode:7469 system_u:system_r:sshd_t:s0-s0:c0.c1023
inode:7552 system_u:system_r:sendmail_t:s0
inode:7348 system_u:system_r:initrc_t:s0
inode:7553 system_u:system_r:sendmail_t:s0
root@qemu-host:/root>
2. Disable SELinux when startup.
root@qemu-host:/root> ./printsocketsec
inode:3221
inode:2942
inode:2861
inode:3256
inode:3156
inode:3220
inode:3060
root@qemu-host:/root>
3. Disable SELinux when compile and startup
root@qemu-host:/root> ./printsocketsec
inode:3221
inode:2942
inode:2861
inode:3256
inode:3156
inode:3220
inode:3060
root@qemu-host:/root>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Stephen Smalley <hidden> Date: 2011-08-31 12:08:30
On Wed, 2011-08-31 at 16:36 +0800, rongqing.li@windriver.com wrote:
From: Roy.Li <redacted>
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
The element sk_security of struct sock represents the socket
security context ID, which is inherited from the parent process
when the socket is created.
but when SELinux type_transition rule is applied to socket, or
application sets /proc/xxx/attr/createsock, the socket security
context would be different from the creating process. For these
conditions, the "netstat -Z" will return wrong value, since
"netstat -Z" only returns the process security context as socket
process security.
Signed-off-by: Roy.Li <redacted>
---
include/linux/inet_diag.h | 3 ++-
net/ipv4/inet_diag.c | 38 +++++++++++++++++++++++++++++++++-----
2 files changed, 35 insertions(+), 6 deletions(-)
We don't impose such a (low) limit on other interfaces for reporting
security contexts. Can you just size the buffer appropriately for the
actual secctx length?
--
Stephen Smalley
National Security Agency
On 8/31/2011 1:36 AM, rongqing.li@windriver.com wrote:
From: Roy.Li <redacted>
Define security_sk_getsecctx to return the security
context of a sock.
So, what is the intended use of the information
coming from this hook? If I wanted to write the
Smack hook, which of the "contexts" would I want
to return? There are potentially three. If I know
what the caller is looking for, I can (hopefully)
select the correct information.
From: Stephen Smalley <hidden> Date: 2011-08-31 18:46:01
On Wed, 2011-08-31 at 08:43 -0700, Casey Schaufler wrote:
On 8/31/2011 1:36 AM, rongqing.li@windriver.com wrote:
quoted
From: Roy.Li <redacted>
Define security_sk_getsecctx to return the security
context of a sock.
So, what is the intended use of the information
coming from this hook? If I wanted to write the
Smack hook, which of the "contexts" would I want
to return? There are potentially three. If I know
what the caller is looking for, I can (hopefully)
select the correct information.
The initial use case is for netstat -Z so that it can reliably show the
security context of the socket rather than inferring it from the owning
process, which can be inaccurate for security-aware applications.
In your situation, when in != out, which would you rather see in netstat
-Z output? Alternatively, if you want them both, perhaps you could
combine in and out into a single string that is returned, similar to
what you proposed for handling multiple xattrs with inode_getsecctx()?
--
Stephen Smalley
National Security Agency
On Wed, 2011-08-31 at 08:43 -0700, Casey Schaufler wrote:
quoted
On 8/31/2011 1:36 AM, rongqing.li@windriver.com wrote:
quoted
From: Roy.Li <redacted>
Define security_sk_getsecctx to return the security
context of a sock.
So, what is the intended use of the information
coming from this hook? If I wanted to write the
Smack hook, which of the "contexts" would I want
to return? There are potentially three. If I know
what the caller is looking for, I can (hopefully)
select the correct information.
The initial use case is for netstat -Z so that it can reliably show the
security context of the socket rather than inferring it from the owning
process, which can be inaccurate for security-aware applications.
In your situation, when in != out, which would you rather see in netstat
-Z output? Alternatively, if you want them both, perhaps you could
combine in and out into a single string that is returned, similar to
what you proposed for handling multiple xattrs with inode_getsecctx()?
If we want to use secctx consistently within the kernel, and
I personally think that is a good idea, I would have to chose
the SMACK64IPIN (label checked on packet delivery) value. Putting
both the SMACK64IPOUT and SMACK64IPIN "contexts" into the secctx
would violate the architectural notion that a secctx is the
textual representation of a value used to make access control
decisions. It would mean that calling security_secctx_to_secid()
with the value returned by security_sk_getsecctx would be invalid.
Note that this is different from the mechanism I had suggested
for handling secctx in the multiple LSM case, as the composed
string would map to a single secid which would in turn map back
to that same composed string. If, on the other hand, what netstat -Z
is out to show is all of the LSM base information about the socket
a compound string might make sense, it just would not be a
secctx, it would be an informational string of some other flavor.
From: Paul Moore <paul@paul-moore.com> Date: 2011-08-31 21:18:53
On Wednesday, August 31, 2011 04:36:17 PM rongqing.li@windriver.com wrote:
From: Roy.Li <redacted>
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
You'll have to forgive me, I'm not familiar with the netlink code used by
netstat and friends, but is there anyway to report back the security context
of UDP sockets? Or does the code below handle that already?
In general, AF_INET and AF_INET6 sockets, regardless of any upper level
protocols, have security contexts associated with them and it would be nice to
see them in netstat.
I'll echo Stephen's concerns that this is too small. A MCS/MLS system with a
moderate number of categories could bump into this limit without too much
difficulty.
Is the "-" string a special value already interpreted by the userspace tools?
If not, you might consider using a string that would indicate an out-of-space
condition occurred; at first glance I thought the "-" string indicated no
context.
How much of a problem would it be if you just allocated an entire page (or 4k
in the case of huge pages) and used that? Is memory usage a concern here?
--
paul moore
www.paul-moore.com
From: Rongqing Li <hidden> Date: 2011-09-01 09:33:21
On 09/01/2011 05:18 AM, Paul Moore wrote:
On Wednesday, August 31, 2011 04:36:17 PM rongqing.li@windriver.com wrote:
quoted
From: Roy.Li<redacted>
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
You'll have to forgive me, I'm not familiar with the netlink code used by
netstat and friends, but is there anyway to report back the security context
of UDP sockets? Or does the code below handle that already?
In general, AF_INET and AF_INET6 sockets, regardless of any upper level
protocols, have security contexts associated with them and it would be nice to
see them in netstat.
Yes, this is real concern, If the dumping tcp security context can be
accepted
by netdev, I am planning to implement it for ipv4 udp socket, unix socket.
then ipv6..
I'll echo Stephen's concerns that this is too small. A MCS/MLS system with a
moderate number of categories could bump into this limit without too much
difficulty.
I will reconsider this as Stephen's suggestion, just size the buffer
appropriately
for the actual secctx length, so that, your next question will be fixed
since we
have enough memory to place the security context.
quoted
struct inet_diag_entry {
@@ -108,6 +110,25 @@ static int inet_csk_diag_fill(struct sock *sk, icsk->icsk_ca_ops->name); }+ if (ext& (1<< (INET_DIAG_SECCTX - 1))) {+ u32 ctxlen = 0;+ void *secctx;+ int error;++ error = security_sk_getsecctx(sk,&secctx,&ctxlen);++ if (!error&& ctxlen) {+ if (ctxlen< MAX_SECCTX_LEN) {+ strcpy(INET_DIAG_PUT(skb, INET_DIAG_SECCTX,+ ctxlen + 1), secctx);+ } else {+ strcpy(INET_DIAG_PUT(skb, INET_DIAG_SECCTX,+ 2), "-");
Is the "-" string a special value already interpreted by the userspace tools?
If not, you might consider using a string that would indicate an out-of-space
condition occurred; at first glance I thought the "-" string indicated no
context.
How much of a problem would it be if you just allocated an entire page (or 4k
in the case of huge pages) and used that? Is memory usage a concern here?
The memory usage is main concern, or else the 4k page is good idea.
Other side is that this function is few called, so the 4k maybe acceptable.
--
Best Reagrds,
Roy | RongQing Li
From: Paul Moore <paul@paul-moore.com> Date: 2011-09-01 12:28:10
On Thursday, September 01, 2011 05:33:07 PM Rongqing Li wrote:
On 09/01/2011 05:18 AM, Paul Moore wrote:
quoted
On Wednesday, August 31, 2011 04:36:17 PM rongqing.li@windriver.com wrote:
quoted
From: Roy.Li<redacted>
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
You'll have to forgive me, I'm not familiar with the netlink code used
by
netstat and friends, but is there anyway to report back the security
context of UDP sockets? Or does the code below handle that already?
In general, AF_INET and AF_INET6 sockets, regardless of any upper level
protocols, have security contexts associated with them and it would be
nice to see them in netstat.
Yes, this is real concern, If the dumping tcp security context can be
accepted by netdev, I am planning to implement it for ipv4 udp socket, unix
socket. then ipv6..
Great, I'm glad to hear you're planning on implementing this for more than
just TCP.
I understand your desire to have the basic idea accepted with only TCP
implemented - and that is fine with me - but I would like to see support for
all of the protocols merged at the same time. In other words, seeking the
basic ACKs for TCP from the davem, et al is okay but I'd like to defer merging
TCP support until you have everything implemented and ready to be merged.
--
paul moore
www.paul-moore.com
From: Rongqing Li <hidden> Date: 2011-09-05 00:32:33
On 09/01/2011 08:28 PM, Paul Moore wrote:
On Thursday, September 01, 2011 05:33:07 PM Rongqing Li wrote:
quoted
On 09/01/2011 05:18 AM, Paul Moore wrote:
quoted
On Wednesday, August 31, 2011 04:36:17 PM rongqing.li@windriver.com wrote:
quoted
From: Roy.Li<redacted>
Add a new netlink attribute INET_DIAG_SECCTX to dump the security
context of TCP sockets.
You'll have to forgive me, I'm not familiar with the netlink code used
by
netstat and friends, but is there anyway to report back the security
context of UDP sockets? Or does the code below handle that already?
In general, AF_INET and AF_INET6 sockets, regardless of any upper level
protocols, have security contexts associated with them and it would be
nice to see them in netstat.
Yes, this is real concern, If the dumping tcp security context can be
accepted by netdev, I am planning to implement it for ipv4 udp socket, unix
socket. then ipv6..
Great, I'm glad to hear you're planning on implementing this for more than
just TCP.
I understand your desire to have the basic idea accepted with only TCP
implemented - and that is fine with me - but I would like to see support for
all of the protocols merged at the same time. In other words, seeking the
basic ACKs for TCP from the davem, et al is okay but I'd like to defer merging
TCP support until you have everything implemented and ready to be merged.