From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Andrey Ryabinin <a.ryabinin@samsung.com>,
Sasha Levin <sasha.levin@oracle.com>,
"David S. Miller" <davem@davemloft.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Dave Jones <davej@redhat.com>, Eric Dumazet <edumazet@google.com>
Subject: Re: net: socket: NULL ptr deref in sendmsg
Date: Sat, 26 Jul 2014 17:54:40 +0200 [thread overview]
Message-ID: <1406390080.22881.75.camel@localhost> (raw)
In-Reply-To: <CAPAsAGwc7B2rB+3wTHkL97B5eDchbcuhfkKef56ARCy2CxCGuQ@mail.gmail.com>
On Sa, 2014-07-26 at 19:48 +0400, Andrey Ryabinin wrote:
> 2014-07-26 2:15 GMT+04:00 Hannes Frederic Sowa <hannes@stressinduktion.org>:
> > Otherwise I would just set msg_namelen = 0, too, and just not handle
> > passed in NULL pointers to sockaddrs.
> >
>
> I like that, how about such chage:
>
> diff --git a/net/compat.c b/net/compat.c
> index 9a76eaf..bc8aeef 100644
> --- a/net/compat.c
> +++ b/net/compat.c
> @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg,
> struct iovec *kern_iov,
> {
> int tot_len;
>
> - if (kern_msg->msg_namelen) {
> + if (kern_msg->msg_name && kern_msg->msg_namelen) {
> if (mode == VERIFY_READ) {
> int err = move_addr_to_kernel(kern_msg->msg_name,
> kern_msg->msg_namelen,
> @@ -93,10 +93,11 @@ int verify_compat_iovec(struct msghdr *kern_msg,
> struct iovec *kern_iov,
> if (err < 0)
> return err;
> }
> - if (kern_msg->msg_name)
> - kern_msg->msg_name = kern_address;
> - } else
> + kern_msg->msg_name = kern_address;
> + } else {
> kern_msg->msg_name = NULL;
> + kern_msg->msg_namelen = 0;
> + }
>
> tot_len = iov_from_user_compat_to_kern(kern_iov,
> (struct compat_iovec __user
> *)kern_msg->msg_iov,
> diff --git a/net/core/iovec.c b/net/core/iovec.c
> index 827dd6b..e1ec45a 100644
> --- a/net/core/iovec.c
> +++ b/net/core/iovec.c
> @@ -39,7 +39,7 @@ int verify_iovec(struct msghdr *m, struct iovec
> *iov, struct sockaddr_storage *a
> {
> int size, ct, err;
>
> - if (m->msg_namelen) {
> + if (m->msg_name && m->msg_namelen) {
> if (mode == VERIFY_READ) {
> void __user *namep;
> namep = (void __user __force *) m->msg_name;
> @@ -48,10 +48,10 @@ int verify_iovec(struct msghdr *m, struct iovec
> *iov, struct sockaddr_storage *a
> if (err < 0)
> return err;
> }
> - if (m->msg_name)
> - m->msg_name = address;
> + m->msg_name = address;
> } else {
> m->msg_name = NULL;
> + m->msg_namelen = 0;
> }
>
> size = m->msg_iovlen * sizeof(struct iovec);
>
>
LGTM! Can you send a patch?
Thanks,
Hannes
next prev parent reply other threads:[~2014-07-26 15:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-13 21:50 net: socket: NULL ptr deref in sendmsg Sasha Levin
2014-07-14 22:08 ` David Miller
2014-07-24 16:05 ` Sasha Levin
2014-07-25 15:23 ` Andrey Ryabinin
2014-07-25 18:27 ` Eric Dumazet
2014-07-25 20:52 ` Sasha Levin
2014-07-25 22:15 ` Hannes Frederic Sowa
2014-07-26 15:40 ` Andrey Ryabinin
2014-07-25 22:15 ` Hannes Frederic Sowa
2014-07-26 15:48 ` Andrey Ryabinin
2014-07-26 15:54 ` Hannes Frederic Sowa [this message]
2014-07-26 17:26 ` [PATCH] net: sendmsg: fix NULL pointer dereference Andrey Ryabinin
2014-07-28 9:50 ` Hannes Frederic Sowa
2014-07-29 19:21 ` David Miller
2014-07-29 0:19 ` net: socket: NULL ptr deref in sendmsg David Miller
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=1406390080.22881.75.camel@localhost \
--to=hannes@stressinduktion.org \
--cc=a.ryabinin@samsung.com \
--cc=davej@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=sasha.levin@oracle.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).