Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1336571 > unrolled thread
| Started by | Joe Korty <joe.korty@ccur.com> |
|---|---|
| First post | 2016-02-17 17:40 +0100 |
| Last post | 2016-02-17 19:30 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] Fix kfree bug in sendmsg and recvmsg Joe Korty <joe.korty@ccur.com> - 2016-02-17 17:40 +0100
Re: [PATCH] Fix kfree bug in sendmsg and recvmsg Al Viro <viro@ZenIV.linux.org.uk> - 2016-02-17 17:50 +0100
Re: [PATCH] Fix kfree bug in sendmsg and recvmsg Al Viro <viro@ZenIV.linux.org.uk> - 2016-02-17 18:00 +0100
Re: [PATCH] Fix kfree bug in sendmsg and recvmsg David Miller <davem@davemloft.net> - 2016-02-17 19:30 +0100
| From | Joe Korty <joe.korty@ccur.com> |
|---|---|
| Date | 2016-02-17 17:40 +0100 |
| Subject | [PATCH] Fix kfree bug in sendmsg and recvmsg |
| Message-ID | <r3diX-yw-21@gated-at.bofh.it> |
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. Signed-off-by: Joe Korty <joe.korty@ccur.com> Index: b/net/socket.c =================================================================== --- a/net/socket.c +++ b/net/socket.c @@ -1960,7 +1960,8 @@ out_freectl: if (ctl_buf != ctl) sock_kfree_s(sock->sk, ctl_buf, ctl_len); out_freeiov: - kfree(iov); + if (iov != iovstack) + kfree(iov); return err; } @@ -2125,7 +2126,8 @@ static int ___sys_recvmsg(struct socket err = len; out_freeiov: - kfree(iov); + if (iov != iovstack) + kfree(iov); return err; }
[toc] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2016-02-17 17:50 +0100 |
| Message-ID | <r3dsC-BT-9@gated-at.bofh.it> |
| In reply to | #1336571 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2016-02-17 18:00 +0100 |
| Message-ID | <r3dCi-Fn-1@gated-at.bofh.it> |
| In reply to | #1336574 |
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.
[toc] | [prev] | [next] | [standalone]
| From | David Miller <davem@davemloft.net> |
|---|---|
| Date | 2016-02-17 19:30 +0100 |
| Message-ID | <r3f1o-1O1-29@gated-at.bofh.it> |
| In reply to | #1336571 |
From: Joe Korty <joe.korty@ccur.com> Date: Wed, 17 Feb 2016 11:38:05 -0500 > 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. > > Signed-off-by: Joe Korty <joe.korty@ccur.com> Please submit networking patches to netdev@vger.kernel.org, thank you.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web