netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Wright <chrisw@osdl.org>
To: netdev@oss.sgi.com
Cc: davem@davemloft.net, jmorris@redhat.com, sds@epoch.ncsc.mil,
	serue@us.ibm.com
Subject: [RFC][PATCH 1/3] netlink check sender
Date: Sat, 12 Feb 2005 01:02:43 -0800	[thread overview]
Message-ID: <20050212010243.W24171@build.pdx.osdl.net> (raw)
In-Reply-To: <20050212010109.V24171@build.pdx.osdl.net>; from chrisw@osdl.org on Sat, Feb 12, 2005 at 01:01:09AM -0800

* Add check_sender callback to struct netlink_opt.
* Add netlink_kernel_create_check() to register that callback, and turn
  netlink_kernel_create() into a simple wrapper around that.
* Invoke callback when set to verify sender in sender's context.

===== net/netlink/af_netlink.c 1.69 vs edited =====
--- 1.69/net/netlink/af_netlink.c	2005-01-21 12:25:32 -08:00
+++ edited/net/netlink/af_netlink.c	2005-02-11 18:05:59 -08:00
@@ -71,6 +71,7 @@ struct netlink_opt
 	struct netlink_callback	*cb;
 	spinlock_t		cb_lock;
 	void			(*data_ready)(struct sock *sk, int bytes);
+	int			(*check_sender)(struct sk_buff *skb);
 };
 
 #define nlk_sk(__sk) ((struct netlink_opt *)(__sk)->sk_protinfo)
@@ -636,9 +637,17 @@ int netlink_attachskb(struct sock *sk, s
 int netlink_sendskb(struct sock *sk, struct sk_buff *skb, int protocol)
 {
 	struct netlink_opt *nlk;
-	int len = skb->len;
-
+	int err, len = skb->len;
+	
 	nlk = nlk_sk(sk);
+
+	printk("%s: %s(%d) send_check %p\n", __FUNCTION__, current->comm, current->pid, nlk->check_sender);
+	if (nlk->check_sender)
+		if ((err = nlk->check_sender(skb))) {
+			netlink_detachskb(sk, skb);
+			return err;
+		}
+
 #ifdef NL_EMULATE_DEV
 	if (nlk->handler) {
 		skb_orphan(skb);
@@ -1033,7 +1042,8 @@ static void netlink_data_ready(struct so
  */
 
 struct sock *
-netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len))
+netlink_kernel_create_check(int unit, void (*input)(struct sock *sk, int len),
+			    int (*check)(struct sk_buff *skb))
 {
 	struct socket *sock;
 	struct sock *sk;
@@ -1053,8 +1063,10 @@ netlink_kernel_create(int unit, void (*i
 	}
 	sk = sock->sk;
 	sk->sk_data_ready = netlink_data_ready;
-	if (input)
+	if (input) {
 		nlk_sk(sk)->data_ready = input;
+		nlk_sk(sk)->check_sender = check;
+	}
 
 	if (netlink_insert(sk, 0)) {
 		sock_release(sock);
@@ -1459,7 +1471,7 @@ MODULE_ALIAS_NETPROTO(PF_NETLINK);
 EXPORT_SYMBOL(netlink_ack);
 EXPORT_SYMBOL(netlink_broadcast);
 EXPORT_SYMBOL(netlink_dump_start);
-EXPORT_SYMBOL(netlink_kernel_create);
+EXPORT_SYMBOL(netlink_kernel_create_check);
 EXPORT_SYMBOL(netlink_register_notifier);
 EXPORT_SYMBOL(netlink_set_err);
 EXPORT_SYMBOL(netlink_set_nonroot);
===== include/linux/netlink.h 1.23 vs edited =====
--- 1.23/include/linux/netlink.h	2005-02-06 21:59:39 -08:00
+++ edited/include/linux/netlink.h	2005-02-11 14:56:23 -08:00
@@ -116,7 +116,11 @@ struct netlink_skb_parms
 #define NETLINK_CREDS(skb)	(&NETLINK_CB((skb)).creds)
 
 
-extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));
+extern struct sock *netlink_kernel_create_check(int unit, void (*input)(struct sock *sk, int len), int (*check)(struct sk_buff *skb));
+static inline struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len)) 
+{
+	return netlink_kernel_create_check(unit, input, NULL);
+}
 extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
 extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock);
 extern int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid,

  reply	other threads:[~2005-02-12  9:02 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-12  9:01 [RFC][PATCH 0/3] netlink check sender Chris Wright
2005-02-12  9:02 ` Chris Wright [this message]
2005-02-12  9:05   ` [RFC][PATCH 2/3] netlink check sender, audit Chris Wright
2005-02-12  9:06     ` [RFC][PATCH 3/3] netlink check sender, rtnetlink Chris Wright
2005-02-12 16:48     ` [RFC][PATCH 2/3] netlink check sender, audit Pablo Neira
2005-02-12 21:41       ` Pablo Neira
2005-02-14 13:08         ` Stephen Smalley
2005-02-15  0:13         ` Chris Wright
2005-02-15  2:29           ` Pablo Neira
2005-02-15  2:36             ` Pablo Neira
2005-02-15  3:47             ` Chris Wright
2005-02-15 22:19               ` Pablo Neira
2005-02-15 22:22                 ` Chris Wright
2005-02-15 22:27                   ` Pablo Neira
2005-02-16  0:11                     ` Chris Wright
2005-02-16  3:42                       ` James Morris
2005-02-15  0:11       ` Chris Wright
2005-02-14 12:59   ` [RFC][PATCH 1/3] netlink check sender Stephen Smalley
2005-02-14 13:05     ` Stephen Smalley
2005-02-15  0:22       ` Chris Wright
2005-02-15  0:17     ` Chris Wright

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=20050212010243.W24171@build.pdx.osdl.net \
    --to=chrisw@osdl.org \
    --cc=davem@davemloft.net \
    --cc=jmorris@redhat.com \
    --cc=netdev@oss.sgi.com \
    --cc=sds@epoch.ncsc.mil \
    --cc=serue@us.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).