Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Cong Wang
On Mon, Jan 15, 2018 at 10:37 PM, Jason Wang wrote: > > > On 2018年01月16日 14:33, Cong Wang wrote: >> But __tun_detach(true) is not a hot path, a memset() doesn't harm >> anything. > > > Yes, but it looks more more like a workaround or trick to me. > I'd blame skb_array API for this. ;) Ideally, sk

Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Jason Wang
On 2018年01月16日 14:33, Cong Wang wrote: On Mon, Jan 15, 2018 at 10:12 PM, Jason Wang wrote: On 2018年01月16日 14:07, Cong Wang wrote: On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang wrote: I mean we can leave __tun_detach() as is, and just add the cleanup to tun_detach_all(). This is because in

Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Cong Wang
On Mon, Jan 15, 2018 at 10:12 PM, Jason Wang wrote: > > > On 2018年01月16日 14:07, Cong Wang wrote: >> >> On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang wrote: >>> >>> I mean we can leave __tun_detach() as is, and just add the cleanup to >>> tun_detach_all(). This is because in both cases, we're sure

Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Jason Wang
On 2018年01月16日 14:07, Cong Wang wrote: On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang wrote: I mean we can leave __tun_detach() as is, and just add the cleanup to tun_detach_all(). This is because in both cases, we're sure skb array has been initialized before. Oh, I thought the same before s

Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Cong Wang
On Mon, Jan 15, 2018 at 10:00 PM, Jason Wang wrote: > I mean we can leave __tun_detach() as is, and just add the cleanup to > tun_detach_all(). This is because in both cases, we're sure skb array has > been initialized before. > Oh, I thought the same before sending v3, but I believe it is easier

Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Jason Wang
On 2018年01月16日 13:49, Cong Wang wrote: On Mon, Jan 15, 2018 at 9:46 PM, Jason Wang wrote: I think then you don't even need the memset trick since we are sure it has been implemented? It doesn't look like sk_alloc() zero's the memory of tfile. Typo, for "implemented" I mean "initialized".

Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Cong Wang
On Mon, Jan 15, 2018 at 9:46 PM, Jason Wang wrote: > > > I think then you don't even need the memset trick since we are sure it has > been implemented? It doesn't look like sk_alloc() zero's the memory of tfile.

Re: [Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Jason Wang
On 2018年01月16日 03:37, Cong Wang wrote: tfile->tun could be detached before we close the tun fd, via tun_detach_all(), so it should not be used to check for tfile->tx_array. As Jason suggested, we probably have to clean it up unconditionally both in __tun_deatch() and tun_detach_all(), but this

[Patch net v3] tun: fix a memory leak for tfile->tx_array

2018-01-15 Thread Cong Wang
tfile->tun could be detached before we close the tun fd, via tun_detach_all(), so it should not be used to check for tfile->tx_array. As Jason suggested, we probably have to clean it up unconditionally both in __tun_deatch() and tun_detach_all(), but this requires to check if it is initialized or