Netdev List
 help / color / mirror / Atom feed
From: Mathias Krause <minipli@googlemail.com>
To: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Mathias Krause <minipli@googlemail.com>, netdev@vger.kernel.org
Subject: [PATCH 2/4] connector: use nlmsg_len() to check message length
Date: Mon, 30 Sep 2013 22:03:07 +0200	[thread overview]
Message-ID: <1380571389-15343-3-git-send-email-minipli@googlemail.com> (raw)
In-Reply-To: <1380571389-15343-1-git-send-email-minipli@googlemail.com>

The current code tests the length of the whole netlink message to be
at least as long to fit a cn_msg. This is wrong as nlmsg_len includes
the length of the netlink message header. Use nlmsg_len() instead to
fix this "off-by-NLMSG_HDRLEN" size check.

Cc: stable@vger.kernel.org  # v2.6.14+
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 drivers/connector/connector.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 6ecfa75..0daa11e 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -157,17 +157,18 @@ static int cn_call_callback(struct sk_buff *skb)
 static void cn_rx_skb(struct sk_buff *__skb)
 {
 	struct nlmsghdr *nlh;
-	int err;
 	struct sk_buff *skb;
+	int len, err;
 
 	skb = skb_get(__skb);
 
 	if (skb->len >= NLMSG_HDRLEN) {
 		nlh = nlmsg_hdr(skb);
+		len = nlmsg_len(nlh);
 
-		if (nlh->nlmsg_len < sizeof(struct cn_msg) ||
+		if (len < (int)sizeof(struct cn_msg) ||
 		    skb->len < nlh->nlmsg_len ||
-		    nlh->nlmsg_len > CONNECTOR_MAX_MSG_SIZE) {
+		    len > CONNECTOR_MAX_MSG_SIZE) {
 			kfree_skb(skb);
 			return;
 		}
-- 
1.7.10.4

  parent reply	other threads:[~2013-09-30 20:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-30 20:03 [PATCH 0/4] connector fixes Mathias Krause
2013-09-30 20:03 ` [PATCH 1/4] proc connector: fix info leaks Mathias Krause
2013-09-30 20:03 ` Mathias Krause [this message]
2013-09-30 20:03 ` [PATCH 3/4] connector: use 'size' everywhere in cn_netlink_send() Mathias Krause
2013-09-30 20:03 ` [PATCH 4/4] connector - documentation: simplify netlink message length assignment Mathias Krause
2013-10-02 20:04 ` [PATCH 0/4] connector fixes David Miller
2013-10-06 20:46   ` Рустафа Джамурахметов

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=1380571389-15343-3-git-send-email-minipli@googlemail.com \
    --to=minipli@googlemail.com \
    --cc=netdev@vger.kernel.org \
    --cc=zbr@ioremap.net \
    /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