netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Leach <matthew.leach@arm.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "netdev\@vger.kernel.org" <netdev@vger.kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Will Deacon <Will.Deacon@arm.com>
Subject: Re: sys_sendmsg Fails Silently With Negative msg_namelen
Date: Mon, 10 Mar 2014 10:48:52 +0000	[thread overview]
Message-ID: <87fvmqwcq3.fsf@e106496-lin.cambridge.arm.com> (raw)
In-Reply-To: <20140307212609.GQ4774@mwanda> (Dan Carpenter's message of "Fri, 7 Mar 2014 21:26:09 +0000")

Hi Dan,

Dan Carpenter <dan.carpenter@oracle.com> writes:

[...]

> I think Ruby was using larger buffer sizes than necessary so we could
> add something like:
>
> 	if (kmsg->msg_namelen < 0)
> 		return -EINVAL;
> 	if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
>   		kmsg->msg_namelen = sizeof(struct sockaddr_storage);

I don't see how your patch does anything different?  If we don't clamp
the value and leave it as -1 the check for a negative buffer size
eventually happens in move_addr_to_kernel anyway, just before we copy
the buffer from userspace.  This check fails and returns EINVAL.

>
>
> Why are people passing -1 as the buffer size anyway?  

This was actually found with LTP.  The sendmsg01 test passes -1 as the
msg_namelen parameter and expects the syscall to fail.

> Your email suggests that people expect it to work, and it will work
> fine if you have a buffer size which is larger than sizeof(struct
> sockaddr_storage).  I'm nervous about changing something which works
> fine in case I break userspace.  A second time.  :P

Agreed, but IMHO passing -1 as a buffer size should cause a syscall to
fail, rather than assuming we can copy from the buffer.

-- 
Matt

      reply	other threads:[~2014-03-10 10:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87vbvpx0fo.fsf@e106496-lin.cambridge.arm.com>
2014-03-07 21:26 ` sys_sendmsg Fails Silently With Negative msg_namelen Dan Carpenter
2014-03-10 10:48   ` Matthew Leach [this message]

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=87fvmqwcq3.fsf@e106496-lin.cambridge.arm.com \
    --to=matthew.leach@arm.com \
    --cc=Will.Deacon@arm.com \
    --cc=dan.carpenter@oracle.com \
    --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).