Fix kfree() corruption in sock_read_buffer_sendmsg()
Subsystems (2)
PATCH 1/1 Fix kfree() corruption in sock_read_buffer_sendmsg()
The memcpy_from_iovec() function that the unix sendmsg functions use modifies the struct msghdr. Since the current code uses the msg.iovec_base pointer in the msghdr for the kmalloc() and kfree(), we end up freeing the wrong pointer. This patch stores the original address in a separate pointer and corrects the kfree() call to use it.
--- net/unix/checkpoint.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
net/unix/checkpoint.c +5 -3
@@ -118,6 +118,7 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx, struct sock *sock) {struct msghdr msg;struct kvec kvec; +void *buf;int ret =0 ;int len;
@@ -134,8 +135,9 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx, struct sock *sock) } kvec.iov_len = len; - kvec.iov_base =kmalloc (len,GFP_KERNEL ); -if (!kvec.iov_base) + buf =kmalloc (len,GFP_KERNEL ); + kvec.iov_base = buf; +if (!buf)return -ENOMEM ; ret =ckpt_kread (ctx, kvec.iov_base, len);
@@ -147,7 +149,7 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx, struct sock *sock)if ((ret >0 ) && (ret != len)) ret = -ENOMEM ; out: -kfree (kvec.iov_base); +kfree (buf);return ret; }
Signature · 1 line
1.6.2.5
A message that is not in the archive (sent off-list or not yet received): 1250264153-21697-1-git-send-email-danms-r/[email protected]
Serge E. Hallyn
Tested-byQuoted 8 lines · Dan Smith
The
memcpy_from_iovec()function that the unix sendmsg functions use modifies the struct msghdr. Since the current code uses the msg.iovec_base pointer in the msghdr for thekmalloc()andkfree(), we end up freeing the wrong pointer. This patch stores the original address in a separate pointer and corrects thekfree()call to use it.Cc serue-r/[email protected]Signed-off-by Dan Smith <danms-r/[email protected]>
Quoted 39 lines
--- net/unix/checkpoint.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)net/unix/checkpoint.c +5
-3@@ -118,6 +118,7 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx, struct sock *sock) {struct msghdr msg;struct kvec kvec; +void *buf;int ret =0 ;int len;@@ -134,8 +135,9 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx, struct sock *sock) } kvec.iov_len = len; - kvec.iov_base =kmalloc (len,GFP_KERNEL ); -if (!kvec.iov_base) + buf =kmalloc (len,GFP_KERNEL ); + kvec.iov_base = buf; +if (!buf)return -ENOMEM ; ret =ckpt_kread (ctx, kvec.iov_base, len);@@ -147,7 +149,7 @@ static int sock_read_buffer_sendmsg(struct ckpt_ctx *ctx, struct sock *sock)if ((ret >0 ) && (ret != len)) ret = -ENOMEM ; out: -kfree (kvec.iov_base); +kfree (buf);return ret; }Signature · 1 line
1.6.2.5
A message that is not in the archive (sent off-list or not yet received): 20090814185145.GA5712-r/[email protected]
Quoted 11 lines · Serge E. Hallyn
Quoted 8 lines · Dan Smith
The
memcpy_from_iovec()function that the unix sendmsg functions use modifies the struct msghdr. Since the current code uses the msg.iovec_base pointer in the msghdr for thekmalloc()andkfree(), we end up freeing the wrong pointer. This patch stores the original address in a separate pointer and corrects thekfree()call to use it.Cc serue-r/[email protected]Signed-off-by Dan Smith <danms-r/[email protected]>Tested-by Serge Hallyn <serue-r/[email protected]>
Pulled.
Oren.