lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 9 Aug 2011 15:28:26 +0800
From:	<rongqing.li@...driver.com>
To:	<netdev@...r.kernel.org>, <selinux@...ho.nsa.gov>,
	<linux-security-module@...r.kernel.org>, <sds@...ho.nsa.gov>
Subject: [PATCH 2/6] Define the function to write sock's security context to seq_file.

From: Roy.Li <rongqing.li@...driver.com>

sock_write_secctx will write the sock's security context to a seq_file
and return the number of characters successfully written.

This function will be called when export socket information to proc.

Signed-off-by: Roy.Li <rongqing.li@...driver.com>
---
 include/net/sock.h |    1 +
 net/core/sock.c    |   28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 8e4062f..8bedb0c 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);
 
 /* 
  *	Enable debug/info messages 
diff --git a/net/core/sock.c b/net/core/sock.c
index bc745d0..032ea72 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2254,6 +2254,34 @@ void sk_common_release(struct sock *sk)
 }
 EXPORT_SYMBOL(sk_common_release);
 
+int sock_write_secctx(struct sock *sk, struct seq_file *seq)
+{
+	char *ctx = NULL;
+	u32 ctxlen, secid;
+	int len;
+
+	if (sk == NULL)
+		goto error;
+
+	if (security_socket_getsockname(sk->sk_socket))
+		goto error;
+
+	security_sk_getsecid(sk, &secid);
+	if (!secid)
+		goto error;
+
+	if (security_secid_to_secctx(secid, &ctx, &ctxlen))
+		goto error;
+
+	seq_printf(seq, " %s%n", ctx, &len);
+	security_release_secctx(ctx, ctxlen);
+	return len;
+
+error:
+	seq_printf(seq, " %s%n", "-", &len);
+	return len;
+}
+
 static DEFINE_RWLOCK(proto_list_lock);
 static LIST_HEAD(proto_list);
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ