linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Joe Korty <joe.korty@ccur.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Fix kfree bug in sendmsg and recvmsg
Date: Wed, 17 Feb 2016 16:52:56 +0000	[thread overview]
Message-ID: <20160217165256.GM17997@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20160217164407.GL17997@ZenIV.linux.org.uk>

On Wed, Feb 17, 2016 at 04:44:07PM +0000, Al Viro wrote:
> On Wed, Feb 17, 2016 at 11:38:05AM -0500, Joe Korty wrote:
> > Fix kfree bug in recvmsg and sendmsg.
> > 
> > We cannot kfree(iov) when iov points to an array on the
> > stack, as that has the potential of corrupting memory.
> > 
> > So re-introduce the if-stmt that used to protect kfree
> > from this condition, code that was removed as part of
> > a larger set of changes made by git commit da184284.
> 
> NAK.  You are misreading import_iovec():
>         *iov = p == *iov ? NULL : p;
> in the end will have iov replaced with NULL if we ended up using what
> it originally pointed to.

PS: that's absolutely deliberate - cleanup after import_iovec() (and its
wrappers) is *always* of the same sort; that way we avoid the checks
completely.  The rules are much simpler that way: after the call of
import_iovec() cleanup is always kfree(iov), no matter what and that's
the only thing iov should be used after that call.

Your "restored" check won't harm anything, precisely because it'll never
be satisfied.  Note that this is the normal codepath - we go through
out_freeiov on success as well.  If iov remained pointing to on-stack
array in case of short vector, we would've been ears-deep in oopsen.
The reason why we are not is that in this case iov ends up being NULL.

  reply	other threads:[~2016-02-17 16:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 16:38 [PATCH] Fix kfree bug in sendmsg and recvmsg Joe Korty
2016-02-17 16:44 ` Al Viro
2016-02-17 16:52   ` Al Viro [this message]
2016-02-17 18:29 ` 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=20160217165256.GM17997@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=davem@davemloft.net \
    --cc=joe.korty@ccur.com \
    --cc=linux-kernel@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).