* [PATCH] net: tls: fix a memory leak bug
@ 2019-04-24 20:18 Wenwen Wang
2019-04-25 1:08 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Wenwen Wang @ 2019-04-24 20:18 UTC (permalink / raw)
To: Wenwen Wang
Cc: Boris Pismenny, Aviad Yehezkel, Dave Watson, John Fastabend,
Daniel Borkmann, David S. Miller, open list:NETWORKING [TLS],
open list
In decrypt_internal(), a memory block 'mem' is allocated through kmalloc()
to hold aead_req, sgin[], sgout[], aad, and iv. This memory block should be
freed after it is used, before this function is returned. However, if the
return value of the function invocation of tls_do_decryption() is
-EINPROGRESS, this memory block is actually not freed, which is a memory
leak bug.
To fix this issue, free the allocated block before the error code
-EINPROGRESS is returned.
Signed-off-by: Wenwen Wang <wang6495@umn.edu>
---
net/tls/tls_sw.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index b50ced8..22445bb 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1445,8 +1445,10 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
/* Prepare and submit AEAD request */
err = tls_do_decryption(sk, skb, sgin, sgout, iv,
data_len, aead_req, async);
- if (err == -EINPROGRESS)
+ if (err == -EINPROGRESS) {
+ kfree(mem);
return err;
+ }
/* Release the pages in case iov was mapped to pages */
for (; pages > 0; pages--)
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: tls: fix a memory leak bug
2019-04-24 20:18 [PATCH] net: tls: fix a memory leak bug Wenwen Wang
@ 2019-04-25 1:08 ` Jakub Kicinski
2019-04-25 4:44 ` Vakul Garg
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2019-04-25 1:08 UTC (permalink / raw)
To: Wenwen Wang
Cc: Boris Pismenny, Aviad Yehezkel, Dave Watson, John Fastabend,
Daniel Borkmann, David S. Miller, open list:NETWORKING [TLS],
open list, Vakul Garg
On Wed, 24 Apr 2019 15:18:07 -0500, Wenwen Wang wrote:
> In decrypt_internal(), a memory block 'mem' is allocated through kmalloc()
> to hold aead_req, sgin[], sgout[], aad, and iv. This memory block should be
> freed after it is used, before this function is returned. However, if the
> return value of the function invocation of tls_do_decryption() is
> -EINPROGRESS, this memory block is actually not freed, which is a memory
> leak bug.
>
> To fix this issue, free the allocated block before the error code
> -EINPROGRESS is returned.
>
> Signed-off-by: Wenwen Wang <wang6495@umn.edu>
Did you find this by code inspection or is this provable at runtime
(kmemleak or such)?
> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index b50ced8..22445bb 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c
> @@ -1445,8 +1445,10 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
> /* Prepare and submit AEAD request */
> err = tls_do_decryption(sk, skb, sgin, sgout, iv,
> data_len, aead_req, async);
> - if (err == -EINPROGRESS)
> + if (err == -EINPROGRESS) {
> + kfree(mem);
> return err;
Mm... don't think so.
-EINPROGRESS is special, it means something is working on the request
asynchronously here.
I think this memory is freed in tls_decrypt_done():
kfree(aead_req);
Note that aead_req is the first member of the allocated buffer.
CCing Vakul
> + }
>
> /* Release the pages in case iov was mapped to pages */
> for (; pages > 0; pages--)
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] net: tls: fix a memory leak bug
2019-04-25 1:08 ` Jakub Kicinski
@ 2019-04-25 4:44 ` Vakul Garg
0 siblings, 0 replies; 3+ messages in thread
From: Vakul Garg @ 2019-04-25 4:44 UTC (permalink / raw)
To: Jakub Kicinski, Wenwen Wang
Cc: Boris Pismenny, Aviad Yehezkel, Dave Watson, John Fastabend,
Daniel Borkmann, David S. Miller, open list:NETWORKING [TLS],
open list
> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Thursday, April 25, 2019 6:39 AM
> To: Wenwen Wang <wang6495@umn.edu>
> Cc: Boris Pismenny <borisp@mellanox.com>; Aviad Yehezkel
> <aviadye@mellanox.com>; Dave Watson <davejwatson@fb.com>; John
> Fastabend <john.fastabend@gmail.com>; Daniel Borkmann
> <daniel@iogearbox.net>; David S. Miller <davem@davemloft.net>; open
> list:NETWORKING [TLS] <netdev@vger.kernel.org>; open list <linux-
> kernel@vger.kernel.org>; Vakul Garg <vakul.garg@nxp.com>
> Subject: Re: [PATCH] net: tls: fix a memory leak bug
>
> On Wed, 24 Apr 2019 15:18:07 -0500, Wenwen Wang wrote:
> > In decrypt_internal(), a memory block 'mem' is allocated through
> > kmalloc() to hold aead_req, sgin[], sgout[], aad, and iv. This memory
> > block should be freed after it is used, before this function is
> > returned. However, if the return value of the function invocation of
> > tls_do_decryption() is -EINPROGRESS, this memory block is actually not
> > freed, which is a memory leak bug.
> >
> > To fix this issue, free the allocated block before the error code
> > -EINPROGRESS is returned.
> >
> > Signed-off-by: Wenwen Wang <wang6495@umn.edu>
>
> Did you find this by code inspection or is this provable at runtime (kmemleak
> or such)?
>
> > diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index
> > b50ced8..22445bb 100644
> > --- a/net/tls/tls_sw.c
> > +++ b/net/tls/tls_sw.c
> > @@ -1445,8 +1445,10 @@ static int decrypt_internal(struct sock *sk,
> struct sk_buff *skb,
> > /* Prepare and submit AEAD request */
> > err = tls_do_decryption(sk, skb, sgin, sgout, iv,
> > data_len, aead_req, async);
> > - if (err == -EINPROGRESS)
> > + if (err == -EINPROGRESS) {
> > + kfree(mem);
> > return err;
>
> Mm... don't think so.
>
> -EINPROGRESS is special, it means something is working on the request
> asynchronously here.
>
> I think this memory is freed in tls_decrypt_done():
>
> kfree(aead_req);
>
> Note that aead_req is the first member of the allocated buffer.
>
> CCing Vakul
The patch is wrong.
Valid reasons have been given against the patch.
>
> > + }
> >
> > /* Release the pages in case iov was mapped to pages */
> > for (; pages > 0; pages--)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-25 4:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-24 20:18 [PATCH] net: tls: fix a memory leak bug Wenwen Wang
2019-04-25 1:08 ` Jakub Kicinski
2019-04-25 4:44 ` Vakul Garg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.