From: Stephen Smalley <sds@tycho.nsa.gov>
To: rongqing.li@windriver.com
Cc: netdev@vger.kernel.org, selinux@tycho.nsa.gov,
lsm <linux-security-module@vger.kernel.org>
Subject: Re: [PATCH 2/5] Export the raw sock's security context to proc.
Date: Fri, 05 Aug 2011 09:51:07 -0400 [thread overview]
Message-ID: <1312552267.19283.47.camel@moss-pluto> (raw)
In-Reply-To: <1312534686-4099-3-git-send-email-rongqing.li@windriver.com>
On Fri, 2011-08-05 at 16:58 +0800, rongqing.li@windriver.com wrote:
> From: Roy.Li <rongqing.li@windriver.com>
>
> The element sk_security of struct sock represents the socket
> security context ID, which is inheriting from the process when
> creates this socket on most of the time.
>
> 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. on this
> condition, the "netstat -Z" will return wrong value, since
> "netstat -Z" only returns the process security context as socket
> process security.
>
> Export the raw sock's security context to proc, so that "netstat -Z"
> could be fixed by reading procfs.
>
> Signed-off-by: Roy.Li <rongqing.li@windriver.com>
> ---
> net/ipv4/raw.c | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
> index 1457acb..645d373 100644
> --- a/net/ipv4/raw.c
> +++ b/net/ipv4/raw.c
> @@ -972,6 +972,7 @@ EXPORT_SYMBOL_GPL(raw_seq_stop);
>
> static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
> {
> + int sclen;
> struct inet_sock *inet = inet_sk(sp);
> __be32 dest = inet->inet_daddr,
> src = inet->inet_rcv_saddr;
> @@ -979,12 +980,15 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
> srcp = inet->inet_num;
>
> seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
> - " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %pK %d\n",
> + " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %pK %d",
> i, src, srcp, dest, destp, sp->sk_state,
> sk_wmem_alloc_get(sp),
> sk_rmem_alloc_get(sp),
> 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
> atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
> +
> + sock_write_secctx(sp, seq, &sclen);
You don't seem to use the return value or the sclen. If that's
intentional, then why does sclen exist and why isn't the function void?
> + seq_putc(seq, '\n');
> }
>
> static int raw_seq_show(struct seq_file *seq, void *v)
> @@ -992,7 +996,8 @@ static int raw_seq_show(struct seq_file *seq, void *v)
> if (v == SEQ_START_TOKEN)
> seq_printf(seq, " sl local_address rem_address st tx_queue "
> "rx_queue tr tm->when retrnsmt uid timeout "
> - "inode ref pointer drops\n");
> + "inode ref pointer drops %s",
> + (selinux_is_enabled() ? " scontext\n" : "\n"));
The rest of your code isn't SELinux-specific and should work for other
security modules, so there is no reason to make this SELinux-specific
either. The audit system may provide a useful example. I'd just always
include the field header (otherwise how can we add any further fields
unambiguously?), and make it something more general, like "seclabel".
> else
> raw_sock_seq_show(seq, v, raw_seq_private(seq)->bucket);
> return 0;
--
Stephen Smalley
National Security Agency
next prev parent reply other threads:[~2011-08-05 13:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-05 8:58 [PATCH 0/5] Export the sock's security context to proc rongqing.li
2011-08-05 8:58 ` [PATCH 1/5] Define the function to write sock's security context to seq_file rongqing.li
[not found] ` <1312534686-4099-2-git-send-email-rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2011-08-05 13:32 ` Stephen Smalley
2011-08-05 13:56 ` Stephen Smalley
2011-08-08 9:32 ` Rongqing Li
2011-08-08 13:25 ` Stephen Smalley
2011-08-05 8:58 ` [PATCH 2/5] Export the raw sock's security context to proc rongqing.li
2011-08-05 13:51 ` Stephen Smalley [this message]
2011-08-05 8:58 ` [PATCH 3/5] Export the udp " rongqing.li
2011-08-05 8:58 ` [PATCH 4/5] Export the unix " rongqing.li
2011-08-05 8:58 ` [PATCH 5/5] Export the tcp " rongqing.li
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=1312552267.19283.47.camel@moss-pluto \
--to=sds@tycho.nsa.gov \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rongqing.li@windriver.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox