netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: yjwei@cn.fujitsu.com
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] NET: Fix function put_cmsg() which may cause usr application memory overflow
Date: Thu, 20 Dec 2007 14:39:56 -0800 (PST)	[thread overview]
Message-ID: <20071220.143956.103295054.davem@davemloft.net> (raw)
In-Reply-To: <4767665D.20300@cn.fujitsu.com>

From: Wei Yongjun <yjwei@cn.fujitsu.com>
Date: Tue, 18 Dec 2007 15:19:09 +0900

> When used function put_cmsg() to copy kernel information to user 
> application memory, if the memory length given by user application is 
> not enough, by the bad length calculate of msg.msg_controllen, 
> put_cmsg() function may cause the msg.msg_controllen to be a large 
> value, such as 0xFFFFFFF0, so the following put_cmsg() can also write 
> data to usr application memory even usr has no valid memory to store 
> this. This may cause usr application memory overflow.
 ...
> The same promble exists in put_cmsg_compat(). This patch can fix this 
> problem.
> 
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>

Thank you for fixing this bug, patch applied.

put_cmsg() is a confusing function, it takes a while to understand
what it is trying to accomplish.  And this explains why this bug
lived for so long.

Each CMSG entry has to be aligned, but put_cmsg() will allow to
put the full final message into the CMSG area if there is enough
room to fit the message without the added alignment.

So, with Wei's fix, we now have:

	int cmlen = CMSG_LEN(len);
 ...
	if (msg->msg_controllen < cmlen) {
		msg->msg_flags |= MSG_CTRUNC;
		cmlen = msg->msg_controllen;
	}
 ...
	if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
		goto out;
	if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
		goto out;
	cmlen = CMSG_SPACE(len);
	if (msg->msg_controllen < cmlen)
		cmlen = msg->msg_controllen;
	msg->msg_control += cmlen;
	msg->msg_controllen -= cmlen;
 ...

which I think finally implements the intended behavior
accurately.

      reply	other threads:[~2007-12-20 22:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-18  6:19 [PATCH] NET: Fix function put_cmsg() which may cause usr application memory overflow Wei Yongjun
2007-12-20 22:39 ` David Miller [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=20071220.143956.103295054.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=yjwei@cn.fujitsu.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).