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 3/3] netlink check sender, rtnetlink
Date: Sat, 12 Feb 2005 01:06:32 -0800	[thread overview]
Message-ID: <20050212010632.Y24171@build.pdx.osdl.net> (raw)
In-Reply-To: <20050212010504.X24171@build.pdx.osdl.net>; from chrisw@osdl.org on Sat, Feb 12, 2005 at 01:05:04AM -0800

Add rtnetlink_check_sender() function to validate rtnetlink messages in
sender context.  Invalid messages (due to content or sender privileges)
will be rejected before queued to socket.

===== net/core/rtnetlink.c 1.33 vs edited =====
--- 1.33/net/core/rtnetlink.c	2005-01-10 13:42:22 -08:00
+++ edited/net/core/rtnetlink.c	2005-02-12 00:13:46 -08:00
@@ -462,8 +462,32 @@ static int rtnetlink_done(struct netlink
 static struct rtattr **rta_buf;
 static int rtattr_max;
 
-/* Process one rtnetlink message. */
+static int rtnetlink_check_sender(struct sk_buff *skb)
+{
+	struct nlmsghdr *nlh;
+	int kind;
+	int type;
+
+	if (skb->len < NLMSG_LENGTH(0))
+		return -EINVAL;
+
+	nlh = (struct nlmsghdr *)skb->data;
+	type = nlh->nlmsg_type;
+
+	/* Unknown message: reply with EINVAL */
+	if (type > RTM_MAX)
+		return -EINVAL;
+
+	type -= RTM_BASE;
+	kind = type&3;
 
+	if (kind != 2 && !capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	return 0;
+}
+
+/* Process one rtnetlink message. */
 static __inline__ int
 rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
 {
@@ -485,10 +509,6 @@ rtnetlink_rcv_msg(struct sk_buff *skb, s
 	if (type < RTM_BASE)
 		return 0;
 
-	/* Unknown message: reply with EINVAL */
-	if (type > RTM_MAX)
-		goto err_inval;
-
 	type -= RTM_BASE;
 
 	/* All the messages must have at least 1 byte length */
@@ -509,11 +529,6 @@ rtnetlink_rcv_msg(struct sk_buff *skb, s
 	sz_idx = type>>2;
 	kind = type&3;
 
-	if (kind != 2 && security_netlink_recv(skb)) {
-		*errp = -EPERM;
-		return -1;
-	}
-
 	if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
 		u32 rlen;
 
@@ -690,7 +705,8 @@ void __init rtnetlink_init(void)
 	if (!rta_buf)
 		panic("rtnetlink_init: cannot allocate rta_buf\n");
 
-	rtnl = netlink_kernel_create(NETLINK_ROUTE, rtnetlink_rcv);
+	rtnl = netlink_kernel_create_check(NETLINK_ROUTE, rtnetlink_rcv,
+					   rtnetlink_check_sender);
 	if (rtnl == NULL)
 		panic("rtnetlink_init: cannot initialize rtnetlink\n");
 	netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);

  reply	other threads:[~2005-02-12  9:06 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 ` [RFC][PATCH 1/3] " Chris Wright
2005-02-12  9:05   ` [RFC][PATCH 2/3] netlink check sender, audit Chris Wright
2005-02-12  9:06     ` Chris Wright [this message]
2005-02-12 16:48     ` 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=20050212010632.Y24171@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).