netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: netdev@vger.kernel.org
Subject: question about klen in move_addr_to_user()
Date: Mon, 18 Mar 2013 13:10:07 +0300	[thread overview]
Message-ID: <20130318101007.GO9189@mwanda> (raw)

Smatch complains that about a potential buffer overflow in
move_add_to_user()

net/socket.c
   212  static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,
   213                               void __user *uaddr, int __user *ulen)
   214  {
   215          int err;
   216          int len;
   217  
   218          err = get_user(len, ulen);
   219          if (err)
   220                  return err;
   221          if (len > klen)
   222                  len = klen;
   223          if (len < 0 || len > sizeof(struct sockaddr_storage))
   224                  return -EINVAL;
   225          if (len) {
   226                  if (audit_sockaddr(klen, kaddr))
                                           ^^^^
Smatch complains that although "len" is capped here, "klen" hasn't
necessarily been.  If "klen" is more than 128 bytes it leads to
memory corruption.

   227                          return -ENOMEM;
   228                  if (copy_to_user(uaddr, kaddr, len))
   229                          return -EFAULT;
   230          }

The call tree is this:

__sys_recvmsg() gets the msg->msg_namelen from the user.

Normally the network protocols set msg->msg_namelen in their
->recvmsg() function but some don't like caif_seqpkt_recvmsg() and
recv_msg() for tipc.

regards,
dan carpenter

             reply	other threads:[~2013-03-18 10:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-18 10:10 Dan Carpenter [this message]
2013-03-19 13:55 ` question about klen in move_addr_to_user() David Miller
2013-10-02 18:58   ` [patch] net: heap overflow in __audit_sockaddr() Dan Carpenter
2013-10-02 21:11     ` Ben Hutchings
2013-10-02 21:26       ` Dan Carpenter
2013-10-02 21:27       ` [patch v2] " Dan Carpenter
2013-10-03 20:06         ` David Miller
2013-11-27 11:32         ` Eric Wong
2013-11-27 11:51           ` Hannes Frederic Sowa
2013-11-27 12:40             ` [patch] net: clamp ->msg_namelen instead of returning an error Dan Carpenter
2013-11-27 19:42               ` Eric Wong
2013-11-27 21:27               ` Eric Dumazet
2013-11-29 21:13                 ` David Miller
2013-11-27 20:24             ` [patch v2] net: heap overflow in __audit_sockaddr() Linus Torvalds
2013-11-27 21:18               ` Hannes Frederic Sowa
2013-11-27 13:56           ` David Laight

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=20130318101007.GO9189@mwanda \
    --to=dan.carpenter@oracle.com \
    --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).