netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH] net: af_packet: Validate parameter size for PACKET_HDRLEN control message
Date: Wed, 27 Feb 2013 11:46:58 -0800	[thread overview]
Message-ID: <1361994418-1403-1-git-send-email-linux@roeck-us.net> (raw)

Building af_packet may fail with

In function ‘copy_from_user’,
    inlined from ‘packet_getsockopt’ at
    net/packet/af_packet.c:3215:21:
arch/x86/include/asm/uaccess_32.h:211:26: error: call to
    ‘copy_from_user_overflow’ declared with attribute error: copy_from_user()
    buffer size is not provably correct

if built with W=1 due to a missing parameter size validation.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 net/packet/af_packet.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c7bfeff..1976b23 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3210,6 +3210,8 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
 		val = po->tp_version;
 		break;
 	case PACKET_HDRLEN:
+		if (len < sizeof(int))
+			return -EINVAL;
 		if (len > sizeof(int))
 			len = sizeof(int);
 		if (copy_from_user(&val, optval, len))
-- 
1.7.9.7

             reply	other threads:[~2013-02-27 19:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-27 19:46 Guenter Roeck [this message]
2013-02-27 20:19 ` [PATCH] net: af_packet: Validate parameter size for PACKET_HDRLEN control message David Miller
2013-02-27 20:22 ` Daniel Borkmann
2013-02-27 20:26   ` David Miller
2013-02-27 20:33     ` Guenter Roeck
2013-02-27 21:18       ` Daniel Borkmann

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=1361994418-1403-1-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /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).