* [PATCH 1/5] Define the function to write sock's security context to seq_file.
2011-08-05 8:58 [PATCH 0/5] Export the sock's security context to proc rongqing.li
@ 2011-08-05 8:58 ` rongqing.li
[not found] ` <1312534686-4099-2-git-send-email-rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2011-08-05 13:56 ` Stephen Smalley
2011-08-05 8:58 ` [PATCH 2/5] Export the raw sock's security context to proc rongqing.li
` (3 subsequent siblings)
4 siblings, 2 replies; 11+ messages in thread
From: rongqing.li @ 2011-08-05 8:58 UTC (permalink / raw)
To: netdev, selinux
From: Roy.Li <rongqing.li@windriver.com>
This function will write the sock's security context to a seq_file
and return the error code, and the number of characters successfully
written is written in int pointers parameter.
This function will be called when export socket information to proc.
Signed-off-by: Roy.Li <rongqing.li@windriver.com>
---
include/net/sock.h | 1 +
net/core/sock.c | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 8e4062f..0366ab1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1828,6 +1828,7 @@ static inline struct sock *skb_steal_sock(struct sk_buff *skb)
extern void sock_enable_timestamp(struct sock *sk, int flag);
extern int sock_get_timestamp(struct sock *, struct timeval __user *);
extern int sock_get_timestampns(struct sock *, struct timespec __user *);
+extern int sock_write_secctx(struct sock *sk, struct seq_file *seq, int *len);
/*
* Enable debug/info messages
diff --git a/net/core/sock.c b/net/core/sock.c
index bc745d0..1126a49 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2254,6 +2254,32 @@ void sk_common_release(struct sock *sk)
}
EXPORT_SYMBOL(sk_common_release);
+int sock_write_secctx(struct sock *sk, struct seq_file *seq, int *len)
+{
+ struct flowi fl;
+ char *ctx = NULL;
+ u32 ctxlen;
+ int res = 0;
+
+ *len = 0;
+
+ if (sk == NULL)
+ return -EINVAL;
+ res = security_socket_getsockname(sk->sk_socket);
+ if (res)
+ return res;
+
+ security_sk_classify_flow(sk, &fl);
+
+ res = security_secid_to_secctx(fl.flowi_secid, &ctx, &ctxlen);
+ if (res)
+ return res;
+
+ seq_printf(seq, " %s%n", ctx, len);
+ security_release_secctx(ctx, ctxlen);
+ return res;
+}
+
static DEFINE_RWLOCK(proto_list_lock);
static LIST_HEAD(proto_list);
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread[parent not found: <1312534686-4099-2-git-send-email-rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>]
* Re: [PATCH 1/5] Define the function to write sock's security context to seq_file.
[not found] ` <1312534686-4099-2-git-send-email-rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
@ 2011-08-05 13:32 ` Stephen Smalley
0 siblings, 0 replies; 11+ messages in thread
From: Stephen Smalley @ 2011-08-05 13:32 UTC (permalink / raw)
To: rongqing.li-CWA4WttNNZF54TAoqtyWWQ
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, selinux-+05T5uksL2qpZYMLLGbcSA,
lsm
On Fri, 2011-08-05 at 16:58 +0800, rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org wrote:
> From: Roy.Li <rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
>
> This function will write the sock's security context to a seq_file
> and return the error code, and the number of characters successfully
> written is written in int pointers parameter.
>
> This function will be called when export socket information to proc.
>
> Signed-off-by: Roy.Li <rongqing.li-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
> ---
> include/net/sock.h | 1 +
> net/core/sock.c | 26 ++++++++++++++++++++++++++
> 2 files changed, 27 insertions(+), 0 deletions(-)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index bc745d0..1126a49 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -2254,6 +2254,32 @@ void sk_common_release(struct sock *sk)
> }
> EXPORT_SYMBOL(sk_common_release);
>
> +int sock_write_secctx(struct sock *sk, struct seq_file *seq, int *len)
> +{
> + struct flowi fl;
> + char *ctx = NULL;
> + u32 ctxlen;
> + int res = 0;
> +
> + *len = 0;
> +
> + if (sk == NULL)
> + return -EINVAL;
> + res = security_socket_getsockname(sk->sk_socket);
> + if (res)
> + return res;
> +
> + security_sk_classify_flow(sk, &fl);
Rather than using a fake flowi, just define and use
security_sk_getsecid(). There is already a security_ops->sk_getsecid()
hook, so you just need the wrapper function.
> +
> + res = security_secid_to_secctx(fl.flowi_secid, &ctx, &ctxlen);
> + if (res)
> + return res;
> +
> + seq_printf(seq, " %s%n", ctx, len);
> + security_release_secctx(ctx, ctxlen);
> + return res;
> +}
> +
> static DEFINE_RWLOCK(proto_list_lock);
> static LIST_HEAD(proto_list);
>
--
Stephen Smalley
National Security Agency
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/5] Define the function to write sock's security context to seq_file.
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:56 ` Stephen Smalley
2011-08-08 9:32 ` Rongqing Li
1 sibling, 1 reply; 11+ messages in thread
From: Stephen Smalley @ 2011-08-05 13:56 UTC (permalink / raw)
To: rongqing.li; +Cc: netdev, selinux, lsm
On Fri, 2011-08-05 at 16:58 +0800, rongqing.li@windriver.com wrote:
> From: Roy.Li <rongqing.li@windriver.com>
>
> This function will write the sock's security context to a seq_file
> and return the error code, and the number of characters successfully
> written is written in int pointers parameter.
>
> This function will be called when export socket information to proc.
>
> Signed-off-by: Roy.Li <rongqing.li@windriver.com>
> ---
> include/net/sock.h | 1 +
> net/core/sock.c | 26 ++++++++++++++++++++++++++
> 2 files changed, 27 insertions(+), 0 deletions(-)
> diff --git a/net/core/sock.c b/net/core/sock.c
> index bc745d0..1126a49 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -2254,6 +2254,32 @@ void sk_common_release(struct sock *sk)
> }
> EXPORT_SYMBOL(sk_common_release);
>
> +int sock_write_secctx(struct sock *sk, struct seq_file *seq, int *len)
> +{
> + struct flowi fl;
> + char *ctx = NULL;
> + u32 ctxlen;
> + int res = 0;
> +
> + *len = 0;
> +
> + if (sk == NULL)
> + return -EINVAL;
Is this ever possible?
> + res = security_socket_getsockname(sk->sk_socket);
> + if (res)
> + return res;
I'm not sure it is a good idea to output nothing if permission is denied
to the socket, as opposed to some well-defined string indicating that
condition. Particularly if someone later adds another field to
the /proc files after the context; we don't want the contents of that
field to be interpreted as the context if permission was denied.
> +
> + security_sk_classify_flow(sk, &fl);
> +
> + res = security_secid_to_secctx(fl.flowi_secid, &ctx, &ctxlen);
> + if (res)
> + return res;
Likewise, if we couldn't map the secid to a secctx for some reason, we
likely ought to output some well-defined string indicating that
condition.
> +
> + seq_printf(seq, " %s%n", ctx, len);
> + security_release_secctx(ctx, ctxlen);
> + return res;
> +}
> +
> static DEFINE_RWLOCK(proto_list_lock);
> static LIST_HEAD(proto_list);
>
--
Stephen Smalley
National Security Agency
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 1/5] Define the function to write sock's security context to seq_file.
2011-08-05 13:56 ` Stephen Smalley
@ 2011-08-08 9:32 ` Rongqing Li
2011-08-08 13:25 ` Stephen Smalley
0 siblings, 1 reply; 11+ messages in thread
From: Rongqing Li @ 2011-08-08 9:32 UTC (permalink / raw)
To: Stephen Smalley; +Cc: netdev, selinux, lsm
On 08/05/2011 09:56 PM, Stephen Smalley wrote:
> On Fri, 2011-08-05 at 16:58 +0800, rongqing.li@windriver.com wrote:
>> From: Roy.Li<rongqing.li@windriver.com>
>>
>> This function will write the sock's security context to a seq_file
>> and return the error code, and the number of characters successfully
>> written is written in int pointers parameter.
>>
>> This function will be called when export socket information to proc.
>>
>> Signed-off-by: Roy.Li<rongqing.li@windriver.com>
>> ---
>> include/net/sock.h | 1 +
>> net/core/sock.c | 26 ++++++++++++++++++++++++++
>> 2 files changed, 27 insertions(+), 0 deletions(-)
>
>> diff --git a/net/core/sock.c b/net/core/sock.c
>> index bc745d0..1126a49 100644
>> --- a/net/core/sock.c
>> +++ b/net/core/sock.c
>> @@ -2254,6 +2254,32 @@ void sk_common_release(struct sock *sk)
>> }
>> EXPORT_SYMBOL(sk_common_release);
>>
>> +int sock_write_secctx(struct sock *sk, struct seq_file *seq, int *len)
>> +{
>> + struct flowi fl;
>> + char *ctx = NULL;
>> + u32 ctxlen;
>> + int res = 0;
>> +
>> + *len = 0;
>> +
>> + if (sk == NULL)
>> + return -EINVAL;
>
> Is this ever possible?
>
Hi Stephen:
When output the tcp information to proc by tcp4_seq_show and
tcp state is TCP_SEQ_STATE_TIME_WAIT, the input argument v is
struct inet_timewait_sock, it seem we can not get the struct sock
from struct inet_timewait_sock, so I assume the sk is NULL in that
condition.
static int tcp4_seq_show(struct seq_file *seq, void *v)
{
case TCP_SEQ_STATE_TIME_WAIT:
get_timewait4_sock(v, seq, st->num, &len);
break;
}
}
>> + res = security_socket_getsockname(sk->sk_socket);
>> + if (res)
>> + return res;
>
> I'm not sure it is a good idea to output nothing if permission is denied
> to the socket, as opposed to some well-defined string indicating that
> condition. Particularly if someone later adds another field to
> the /proc files after the context; we don't want the contents of that
> field to be interpreted as the context if permission was denied.
>
From your review, I redesign the output information as below.
when disable SELinux, print "(none)" in proc
when enable SELinux, no error on getting security context, print the
real security context
when enable SELinux, there is error on getting security context, print
"??"
Do you think it is OK?
Thanks very much
-Roy
>> +
>> + security_sk_classify_flow(sk,&fl);
>> +
>> + res = security_secid_to_secctx(fl.flowi_secid,&ctx,&ctxlen);
>> + if (res)
>> + return res;
>
> Likewise, if we couldn't map the secid to a secctx for some reason, we
> likely ought to output some well-defined string indicating that
> condition.
>
>> +
>> + seq_printf(seq, " %s%n", ctx, len);
>> + security_release_secctx(ctx, ctxlen);
>> + return res;
>> +}
>> +
>> static DEFINE_RWLOCK(proto_list_lock);
>> static LIST_HEAD(proto_list);
>>
>
--
Best Reagrds,
Roy | RongQing Li
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 1/5] Define the function to write sock's security context to seq_file.
2011-08-08 9:32 ` Rongqing Li
@ 2011-08-08 13:25 ` Stephen Smalley
0 siblings, 0 replies; 11+ messages in thread
From: Stephen Smalley @ 2011-08-08 13:25 UTC (permalink / raw)
To: Rongqing Li; +Cc: netdev, selinux, lsm
On Mon, 2011-08-08 at 17:32 +0800, Rongqing Li wrote:
> On 08/05/2011 09:56 PM, Stephen Smalley wrote:
> > I'm not sure it is a good idea to output nothing if permission is denied
> > to the socket, as opposed to some well-defined string indicating that
> > condition. Particularly if someone later adds another field to
> > the /proc files after the context; we don't want the contents of that
> > field to be interpreted as the context if permission was denied.
> >
>
> From your review, I redesign the output information as below.
>
> when disable SELinux, print "(none)" in proc
> when enable SELinux, no error on getting security context, print the
> real security context
> when enable SELinux, there is error on getting security context, print
> "??"
>
> Do you think it is OK?
It appears that netstat presently displays a "-" if it cannot obtain the
security context or pid/program name information, so perhaps you should
follow that convention whenever you cannot obtain a security context
regardless of the particular reason. Note that your logic shouldn't be
based on whether or not SELinux is enabled/disabled per se, but rather
based on whether the security module provides security contexts, which
can be determined by checking whether the secid is set to a non-zero
value by security_sk_getsecid(). The audit system (kernel/audit*.c)
uses similar logic to decide whether or not to log task security
contexts.
--
Stephen Smalley
National Security Agency
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/5] Export the raw sock's security context to proc.
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
@ 2011-08-05 8:58 ` rongqing.li
2011-08-05 13:51 ` Stephen Smalley
2011-08-05 8:58 ` [PATCH 3/5] Export the udp " rongqing.li
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: rongqing.li @ 2011-08-05 8:58 UTC (permalink / raw)
To: netdev, selinux
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);
+ 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"));
else
raw_sock_seq_show(seq, v, raw_seq_private(seq)->bucket);
return 0;
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 2/5] Export the raw sock's security context to proc.
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
0 siblings, 0 replies; 11+ messages in thread
From: Stephen Smalley @ 2011-08-05 13:51 UTC (permalink / raw)
To: rongqing.li; +Cc: netdev, selinux, lsm
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/5] Export the udp sock's security context to proc.
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
2011-08-05 8:58 ` [PATCH 2/5] Export the raw sock's security context to proc rongqing.li
@ 2011-08-05 8:58 ` 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
4 siblings, 0 replies; 11+ messages in thread
From: rongqing.li @ 2011-08-05 8:58 UTC (permalink / raw)
To: netdev, selinux
From: Roy.Li <rongqing.li@windriver.com>
Export the udp sock's security context to proc, since it maybe
different from the sock's owner process security context.
Signed-off-by: Roy.Li <rongqing.li@windriver.com>
---
net/ipv4/udp.c | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 1b5a193..e64b858 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2089,6 +2089,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
int bucket, int *len)
{
struct inet_sock *inet = inet_sk(sp);
+ int sclen;
__be32 dest = inet->inet_daddr;
__be32 src = inet->inet_rcv_saddr;
__u16 destp = ntohs(inet->inet_dport);
@@ -2102,21 +2103,29 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
atomic_read(&sp->sk_refcnt), sp,
atomic_read(&sp->sk_drops), len);
+
+ sock_write_secctx(sp, f, &sclen);
+ *len += sclen;
}
int udp4_seq_show(struct seq_file *seq, void *v)
{
- if (v == SEQ_START_TOKEN)
- seq_printf(seq, "%-127s\n",
+ int len;
+
+ 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");
+ "inode ref pointer drops%n",
+ &len);
+ seq_printf(seq, "%-*s\n", 150 - len,
+ (selinux_is_enabled() ? " scontext" : ""));
+ }
else {
struct udp_iter_state *state = seq->private;
- int len;
udp4_format_sock(v, seq, state->bucket, &len);
- seq_printf(seq, "%*s\n", 127 - len, "");
+ seq_printf(seq, "%*s\n", 150 - len, "");
}
return 0;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/5] Export the unix sock's security context to proc.
2011-08-05 8:58 [PATCH 0/5] Export the sock's security context to proc rongqing.li
` (2 preceding siblings ...)
2011-08-05 8:58 ` [PATCH 3/5] Export the udp " rongqing.li
@ 2011-08-05 8:58 ` rongqing.li
2011-08-05 8:58 ` [PATCH 5/5] Export the tcp " rongqing.li
4 siblings, 0 replies; 11+ messages in thread
From: rongqing.li @ 2011-08-05 8:58 UTC (permalink / raw)
To: netdev, selinux
From: Roy.Li <rongqing.li@windriver.com>
Export the unix sock's security context to proc, since it maybe
different from the sock's owner process security context.
Signed-off-by: Roy.Li <rongqing.li@windriver.com>
---
net/unix/af_unix.c | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ec68e1c..338fa0a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2239,12 +2239,15 @@ static void unix_seq_stop(struct seq_file *seq, void *v)
spin_unlock(&unix_table_lock);
}
+#define OFFSET_PATH_START 40
static int unix_seq_show(struct seq_file *seq, void *v)
{
+ int seqlen, offset = OFFSET_PATH_START;
if (v == SEQ_START_TOKEN)
- seq_puts(seq, "Num RefCount Protocol Flags Type St "
- "Inode Path\n");
+ seq_printf(seq, "Num RefCount Protocol Flags Type St "
+ "Inode Path %s",
+ (selinux_is_enabled() ? " scontext\n" : "\n"));
else {
struct sock *s = v;
struct unix_sock *u = unix_sk(s);
@@ -2275,7 +2278,15 @@ static int unix_seq_show(struct seq_file *seq, void *v)
}
for ( ; i < len; i++)
seq_putc(seq, u->addr->name->sun_path[i]);
+ if (offset > len)
+ offset -= (len + 1);
+ else
+ offset = 0;
}
+
+ seq_printf(seq, "%*c", offset, '\b');
+ sock_write_secctx(s, seq, &seqlen);
+
unix_state_unlock(s);
seq_putc(seq, '\n');
}
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 5/5] Export the tcp sock's security context to proc.
2011-08-05 8:58 [PATCH 0/5] Export the sock's security context to proc rongqing.li
` (3 preceding siblings ...)
2011-08-05 8:58 ` [PATCH 4/5] Export the unix " rongqing.li
@ 2011-08-05 8:58 ` rongqing.li
4 siblings, 0 replies; 11+ messages in thread
From: rongqing.li @ 2011-08-05 8:58 UTC (permalink / raw)
To: netdev, selinux
From: Roy.Li <rongqing.li@windriver.com>
Export the tcp sock's security context to proc, since it maybe
different from the sock's owner process security context.
Signed-off-by: Roy.Li <rongqing.li@windriver.com>
---
net/ipv4/tcp_ipv4.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 955b8e6..98a85d6 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2478,13 +2478,16 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
static int tcp4_seq_show(struct seq_file *seq, void *v)
{
struct tcp_iter_state *st;
- int len;
+ int len, sclen;
+ struct sock *s = NULL;
if (v == SEQ_START_TOKEN) {
- seq_printf(seq, "%-*s\n", TMPSZ - 1,
+ seq_printf(seq,
" sl local_address rem_address st tx_queue "
"rx_queue tr tm->when retrnsmt uid timeout "
- "inode");
+ "inode %n", &len);
+ seq_printf(seq, "%-*s\n", TMPSZ - len - 1,
+ (selinux_is_enabled() ? " scontext" : ""));
goto out;
}
st = seq->private;
@@ -2493,15 +2496,19 @@ static int tcp4_seq_show(struct seq_file *seq, void *v)
case TCP_SEQ_STATE_LISTENING:
case TCP_SEQ_STATE_ESTABLISHED:
get_tcp4_sock(v, seq, st->num, &len);
+ s = v;
break;
case TCP_SEQ_STATE_OPENREQ:
get_openreq4(st->syn_wait_sk, v, seq, st->num, st->uid, &len);
+ s = st->syn_wait_sk;
break;
case TCP_SEQ_STATE_TIME_WAIT:
get_timewait4_sock(v, seq, st->num, &len);
break;
}
- seq_printf(seq, "%*s\n", TMPSZ - 1 - len, "");
+
+ sock_write_secctx(s, seq, &sclen);
+ seq_printf(seq, "%*s\n", TMPSZ + sclen - 1 - len, "");
out:
return 0;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread